var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var decimalSeparator=","

function formatNumber(expr, decplaces) {
	return Math.floor(expr * Math.pow(10,decplaces))/Math.pow(10,decplaces);
} 

function setFocus(obj){
	if (obj){
		if (obj.disabled==false){
			obj.focus();
			if (obj.createTextRange()) {
				f = obj.createTextRange();
				f.moveStart('character', obj.value.length);
				f.collapse();
				f.select();
			}
		}
	}
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Il formato della data deve essere : gg/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Inserire un mese valido")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Inserire un giorno valido")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("L'anno deve essere di 4 cifre e compreso tra "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Inserire una data valida")
		return false
	}
return true
}


function CheckLocation() {
		txt = self.parent.location.pathname;
		txt = txt.toUpperCase();
	
}

function CheckLocationPrivate() {
	//if (self.parent.location.pathname !=  "/DINAMICA/logdinamica.asp") {
		//self.location = 'login.asp';
	//}
}


function isEmail(email)
{
  var result = true;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = false;
  }
  return result;
}


function isNumeric(str)
{
// true è numerica
  var len= str.length;
  if (len==0)
    return false;
  //else
  var p=0;
  var ok= false;
  var ch= "";
  while (p<len)
  {
    ch= str.charAt(p);
    if ('0'<=ch && ch<='9')
      return true;
      p++;
   }
   return ok;
}

function ValidateCurriculum()	{
	  if(document.mainform.EMP_FIRST_NM.value == "")			  	{alert("Inserire il Nome nella sezione Dati Anagrafici");	return;}
	  if(isNumeric(document.mainform.EMP_FIRST_NM.value)) 	  			{alert("Il Nome non è corretto");	return;}
	  if(document.mainform.EMP_LAST_NM.value == "")			 		{alert("Inserire il Cognome nella sezione Dati Anagrafici");	return;}
	  if(isNumeric(document.mainform.EMP_LAST_NM.value))				{alert("Il Cognome non è corretto");	return;}
	  if(document.mainform.EMP_SEX_ID.value == "<>   ")				{alert("Inserire il Sesso nella sezione Dati Anagrafici");	return;}
	  if(document.mainform.EMP_BIRTHDAY_DT.value == "")				{alert("Inserire la Data di Nascita nella sezione Dati Anagrafici");	return;}
	  if(isDate(document.mainform.EMP_BIRTHDAY_DT.value)==false)			{alert("La Data di Nascita non è corretta");	return;}
	  if(document.mainform.EMP_BIRTHDAY_GEO_LOC_DESC.value == "")			{alert("Inserire il luogo di Nascita nella sezione Dati Anagrafici");	return;}
	  if(isNumeric(document.mainform.EMP_BIRTHDAY_GEO_LOC_DESC.value))		{alert("Il luogo di Nascita non è corretto");	return;}
	  if(document.mainform.EMP_CIV_STATUS_ID.value == "<nd> ")		{alert("Inserire lo Stato Civile nella sezione Dati Anagrafici");	return;}
	  if(document.mainform.EMP_MILITARY_STATUS_ID.value == "<nd> ")	{alert("Inserire il Servizio Militare nella sezione Dati Anagrafici");	return;}
	  if(document.mainform.EMP_ADDR.value == "")				 	{alert("Inserire l'Indirizzo nella sezione Domicilio");	return;}
	  if(document.mainform.EMP_GEO_LOC_DESC.value == "")		 	{alert("Inserire il Comune nella sezione Domicilio");	return;}
	  if(isNumeric(document.mainform.EMP_GEO_LOC_DESC.value))	 	{alert("Il Comune non è corretto");	return;}
	  if(document.mainform.EMP_GEO_STPROV_ID.value == "<> ")		{alert("Inserire la Provincia nella sezione Domicilio");	return;}
	  if(document.mainform.EMP_ZIP_NBR.value == "")			 		{alert("Inserire il Cap nella sezione Domicilio ");	return;}
	  if(isInteger(document.mainform.EMP_ZIP_NBR.value)==false)	 		{alert("Il Cap non è corretto");	return;}
	  if(document.mainform.EMP_ZIP_NBR.value.length < 5)	 			{alert("Il Cap non è corretto");	return;}
          if(document.mainform.GEO_COUNTRY_ID.value == "<>")		 	{alert("Inserire lo Stato nella sezione Domicilio");	return;}	  
	  if(document.mainform.EMP_SMTP_EMAIL.value == "")		 		{alert("Inserire l'Indirizzo di Posta nella sezione Riferimenti Internet");	return;}
	  if(isEmail(document.mainform.EMP_SMTP_EMAIL.value))			{alert("L'Indirizzo di Posta non è corretto");	return;}
	  if(document.mainform.SH_SCHOOL_TITLE_ID.value == "<>   ")		{alert("Inserire il Titolo di Studio nella sezione Studi ");	return;}
	  if(mainform.EMP_WHY_WORK_WITH_US_DESC.value.length > 8000)	 {alert("Attenzione! Il messaggio scritto nella sezione Interessato a lavorare in Dinamica e' troppo lungo");  return ;}
	  if(mainform.EMP_NOTE.value.length > 16)			   		     {alert("Attenzione! Il messaggio scritto nella sezione Note e' troppo lungo");  return ;}     
				
	  document.mainform.submit();
	return;
}


function CheckOpener() {
	//if (self.opener == null) {
		//self.location = 'bianca.html';
	//}
}

function field_onkeypress() {

if (window.event.keyCode == 13)
   {
   ValidateForm();
   }
}


function FindCenter(oggetto) {
	var llength=0;
	var segno=top.frames(3).segno;
	llength = (oggetto.width - segno.width)/2;
	segno.style.left=0;
	segno.style.marginLeft=oggetto.offsetLeft + llength ;
}


function highlightit(cur2){
	if (cur2.filters.alpha.opacity<100){
		cur2.filters.alpha.opacity += 5;
		}else if (window.highlighting){
		clearInterval(highlighting);
	}
}


function high(which2){
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",50)
}


function low(which2){
	clearInterval(highlighting)
	which2.filters.alpha.opacity=40
}


function imageChange(ImageLeft) {
	segno.style.left=0;
	segno.style.marginLeft=ImageLeft ;
}


function imageOut() {
	segno.style.marginLeft='70px' ;
}


function privacy()
	{
	 fenetre=window.open("privacy.html","Privacy","resizable=no,scrollbars=yes,location=no,top=100,left=150,width=500,height=400");
	}


function Cambia(NOME)		{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qs").value;
	
	qsret=replaceadd(qsret, "ob", "ob=" + NOME);
	
	return "el_ord_pending.asp?" + qsret;
}


function Cambiaut(NOME)		{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qsut").value;
	
	qsret=replaceadd(qsret, "ob", "ob=" + NOME);
	
	return "el_util.asp?" + qsret;
}

function CambiaFiltroStorico(filtro){
			
	document.body.style.cursor="wait";
	qsret= document.forms(0).item("qs").value;
	qsret=replaceadd(qsret, "filtro", "filtro=" + filtro);
	qsret=replaceadd(qsret, "page", "page=1");
	return "submitvariazioni.asp?"+ qsret;
	
}

function CambiaFiltro(filtro){
			
	document.body.style.cursor="wait";
	qsret= document.forms(0).item("qsmov").value;
	qsret=replaceadd(qsret, "filtro", "filtro=" + filtro);
	return "el_mov.asp?" + qsret;
	
}

function CambiaQs(page){
	document.body.style.cursor="wait";
	qsret=document.getElementById('qs').value
	qsret=replaceadd(qsret, "page", "page=" + page);
	return qsret
}
function CambiaQsFinder(field){
	document.getElementById('divContainer').style.display='none'
	document.body.style.cursor="wait";
	qsret=document.getElementById('qs').value
	qsret=replaceadd(qsret, "order", "order=" + field);
	return qsret
}
function CambiaQSOrderType(type){
	document.getElementById('divContainer').style.display='none'
	document.body.style.cursor="wait";
	qsret=document.getElementById('qs').value
	qsret=replaceadd(qsret, "orderType", "orderType=" + type);
	return qsret
}
function CambiaQsFinderText(txt){
	document.body.style.cursor="wait";
	qsret=document.getElementById('qs').value
	qsret=replaceadd(qsret, "finder", "finder=" + txt);
	return qsret
}
function CambiaQ(page)		{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qsut").value;
	
	qsret=replaceadd(qsret, "page", "page=" + page);
	
	return "el_util.asp?" + qsret;
}


function Cambiautm(NOME)	{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qsmov").value;
	qsret=document.getElementById("qsmov").value;
	
	qsret=replaceadd(qsret, "ob", "ob=" + NOME);
	
	return "el_mov.asp?" + qsret;
}

function Cambiautp(NOME)	{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qspool").value;
	
	qsret=replaceadd(qsret, "ob", "ob=" + NOME);
	
	return "el_pool.asp?" + qsret;
}

function CambiaQstr(page)		{
	document.body.style.cursor="wait";
	
	qsret= document.forms(0).item("qsmov").value;
	
	qsret=replaceadd(qsret, "page", "page=" + page);
	
	return "el_mov.asp?" + qsret;
}


function Popup(q_cod,obj) {
	
	if (obj =="bvw0_EMP") {
	 Dettagli=window.open("dettagli_emp.asp?q_cod=" + q_cod,"Dettagli","height=500,width=650,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Dettagli.focus()
	}

	if (obj =="bvw0_CAR") {
	 Dettagli=window.open("datiutilizzo.asp?q_cod=" + q_cod,"Dettagli","height=500,width=600,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Dettagli.focus()
	}
		   
	if (obj =="Poolbvw0_MCAR"){
	 Dettagli=window.open("dettagli_pool.asp?q_cod=" + q_cod,"Dettagli","height=500,width=600,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Dettagli.focus()
	}
	
	if (obj =="bvw0_ORDERS") {
	 Dettagli=window.open("dettagli_pending.asp?q_cod=" + q_cod,"Dettagli","height=500,width=600,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Dettagli.focus()
	}
	
	if (obj =="bvw0_MCAR") {
	 Dettagli=window.open("dettagli_mov.asp?q_cod=" + q_cod,"Dettagli","height=500,width=600,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Dettagli.focus()
	}
}


function popupkm(obj){
	KM=window.open("popupkm.asp?soc=" + obj,"KM","height=300,width=421,menubar=0,resizable=0,scrollbars=0, status=0,titlebar=0,toolbar=0,left=100,top=75")
	KM.focus()
}


function PopupElenco(pagina) {
	
	 Elenco=window.open(pagina,"Elenco","height=500,width=650,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 Elenco.focus()
}

function PopupElencoD(pagina) {
	
	 ElencoD=window.open(pagina,"ElencoD", "height=200,width=350,menubar=0,resizable=0,scrollbars=0, status=0,titlebar=0,toolbar=0,left=100,top=75")
	 ElencoD.focus()
}

function PopupElencoM(pagina) {
	
	 ElencoM=window.open(pagina,"ElencoM","height=450,width=650,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 ElencoM.focus()
}
function PopupElencoExcel(pagina) {
	
	 ElencoExcel=window.open(pagina,"ElencoExcel","height=450,width=650,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")
	 ElencoExcel.focus()
}

function NewWindow(pagina) {
	
	 window.open(pagina,"","height=500,width=610,menubar=0,resizable=no,scrollbars=1, status=0,titlebar=0,toolbar=0,left=200,top=50")

}


chrOk = "0123456789/."
function CheckL(obj) {
	o = obj.value;
	a = o.charAt(o.length-1);
	if (chrOk.indexOf(a)==-1 | a=="." ){
	obj.value=o.substr(0,o.length-1);
	} 
}
	
	
function SVeicoli_onchange() {
	targa.value = SVeicoli.value;
}
	
	
function CheckValue(obj1,obj2) {
	x = obj1.value;
	y = obj2.value;
	if (x==""){
		alert("E' necessario compilare prima il campo precedente.")
		obj2.value="";
	} 
}


function CheckVoto(obj1,obj2) {
	x = obj1.value;
	y = obj2.value;
	if (x==""){
	obj2.value="";
	} 
}
	
function ValidateFormSurvey() {
		var risposte;
		risposte=0;
		if(document.mainform.S01_BEG_WITHDRAW_CAR_MI.value != "")			{risposte=1;} 
		if(document.mainform.S02_END_RETURN_CAR_MI.value != "")				{risposte=risposte +1;} 
		if(document.mainform.S03_PRELEASE_CHANGE_MI.value != "")			{risposte=risposte +1;} 
		if(document.mainform.S04_CAR_PRG_ASSISTANCE_MI.value != "")			{risposte=risposte +1;} 
		if(document.mainform.S05_CAR_NOPRG_ASSISTANCE_MI.value != "")		{risposte=risposte +1;} 
		if(document.mainform.S06_BEG_END_COURTESY_CAR_MI.value != "")		{risposte=risposte +1;} 
		if(document.mainform.S07_ADMIN_ISSUE_MI.value != "")				{risposte=risposte +1;} 
		if(document.mainform.S08_REFUND_EFFORT_MI.value != "")				{risposte=risposte +1;} 
		if(document.mainform.S09_ANSWER_SUPPLIER_EFFORT_MI.value != "")		{risposte=risposte +1;} 
		if(document.mainform.S10_INFO_SEARCH_SUPPLIER_MI.value != "")		{risposte=risposte +1;} 
		if(document.mainform.S11_INFO_SEARCH_INTERNAL_MI.value != "")		{risposte=risposte +1;} 
		if(document.mainform.SUPP_STRUCT_DESC.value != "")					{risposte=risposte +1;} 
		if(document.mainform.SUPP_STRUCT_VOTE_ID.value != 0)				{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT1_ID.value != 0)					{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT1_VOTE_ID.value != 0)			{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT2_ID.value != 0)					{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT2_VOTE_ID.value != 0)			{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT3_ID.value != 0)					{risposte=risposte +1;} 
		if(document.mainform.DB_USR_CONTACT3_VOTE_ID.value != 0)			{risposte=risposte +1;}
		if(document.mainform.EMP_SURVEY_NOTE.value != "")					{risposte=risposte +1;}
		
		if(risposte==0){
				alert("Il modulo non verrà inviato poichè nessun campo è stato compilato.")
			}else{
				document.mainform.submit();
		}
		
		return;
}


function ValidateFormContact()	{
	if(document.mainform.CONTACT_FIRST_NM.value == "")		{alert("Inserire il Nome");	return;}
	if(document.mainform.CONTACT_LAST_NM.value == "")		{alert("Inserire il Cognome");	return;}
	if(document.mainform.CONTACT_CO_DESC.value == "")		{alert("Inserire la Ragione");	return;}
	if(document.mainform.CONTACT_CO_ADDR.value == "")		{alert("Inserire l'Indirizzo");	return;}
	if(document.mainform.CONTACT_CO_LOC_DESC.value == "")	{alert("Inserire la Localita'");	return;}
	if(document.mainform.GEO_COUNTRY_ID.value == "<>")		{alert("Inserire lo Stato");	return;}
	if(document.mainform.CONTACT_CO_PHONE_NBR.value == "")	{alert("Inserire il Telefono");	return;}
	if(document.mainform.CONTACT_SMTP_EMAIL.value == "")	{alert("Inserire l'Indirizzo di Posta");	return;}
	if(document.mainform.CONTACT_CO_NOTE.value == "")		{alert("Inserire le Note");	return;}

		if(mainform.CONTACT_CO_NOTE.value.length > 100)	 		{alert("Attenzione! Il messaggio scritto nella sezione Note e' troppo lungo");  return ;}
	document.mainform.submit();
	return;
}

function f_onmousedown(pulsante) {
pulsante.src = "immagini/" + pulsante.name + "c.gif"
}


function ValidateFormDL()	{
	if(document.mainform.CONTACT_FIRST_NM.value == "")		{alert("Inserire il Nome");	return;}
	if(document.mainform.CONTACT_LAST_NM.value == "")		{alert("Inserire il Cognome");	return;}
  	if(document.mainform.CONTACT_OTH_FUNC_DESC.value == "")	{alert("Inserire la Posizione'");	return;}
	if(document.mainform.CONTACT_CO_DESC.value == "")	{alert("Inserire l'Indirizzo di Posta");	return;}
	if(document.mainform.CONTACT_SMTP_EMAIL.value == "")	{alert("Inserire l'Indirizzo di Posta");	return;}
		  
	document.mainform.submit();
	return;
}


function ValidateFormReg()	{
	if(document.formreg.CONTACT_SMTP_EMAIL.value == "")		{alert("Inserire l'indirizzo email");	return;}
			
	document.formreg.submit();
	return;
}
		
		
function f_onmouseup(pulsante) {
pulsante.src = "immagini/" + pulsante.name + ".gif"
}

function storico() {
	fenetre=window.open("storico_survey.asp","Storico","resizable=no,scrollbars=yes,location=no,top=100,left=150,width=500,height=400");
}


function replaceadd(fs, ss, rv) {
	ra=(rv=="")?"":"&" + rv;
	if (fs=='') return rv; 
	i=parseInt(fs.indexOf("?"));  //is querystring?
	if (i==-1){
		i=parseInt(fs.indexOf("&"+ss+"=")); //is not first element?
		if(i==-1){
			i=parseInt(fs.indexOf(ss+"="));
			if(i==0){  //prima posizione?
				j=parseInt(fs.indexOf("&"));
				return ((j==-1)?rv:rv + fs.substr(j));
			}else{
				return fs + ra;
			}
		}else{ //elemento &ss= trovato in pos i
			j=parseInt(fs.indexOf("&", i+1));
			return ((j==-1)?fs.substring(0,i) + ra:fs.substring(0,i) + ra + fs.substr(j));
		}
	} else {  // è una querystring. Elementi possono essere anche ?xx=
		i=parseInt(fs.indexOf("&"+ss+"="));
		if (i==-1) i=parseInt(fs.indexOf("?"+ss+"="));
		if (i==-1){ //non c'e proprio, mi chiedo se dopo ? c'è qualcosa
			i=parseInt(fs.indexOf("?"));
			return ((i==(parseInt(fs.length)-1))?fs+rv:fs + ra); 
		}else{
			j=parseInt(fs.indexOf("&", i+1));
			return ((j==-1)?fs.substring(0,i+1) + rv:fs.substring(0,i+1) + rv + fs.substr(j));
		}
	}
}

function storeCaret(textEl){ 
	if (textEl.createTextRange){ 
		textEl.caretPos = document.selection.createRange().duplicate();
	} 
}
function getCursorPosNN(ctrl) {
	var saveText = ctrl.value;  // save for restoring later
	try{
		ctrl.focus();
	} catch(e){}
	var range = document.getSelection().createRange();
	var weirdStr = String.fromCharCode(1);   // a weird string to
	range.text = weirdStr;
	var pos = ctrl.value.indexOf(weirdStr);  // get the position
	ctrl.value = saveText; 
	try{                  // restore the
		range = ctrl.createTextRange();
		range.move('character', pos);            // restore the cursor
		range.select();
	} catch(e){}
	return pos;
}
function getCursorPos(ctrl) {
	var saveText = ctrl.value;  // save for restoring later
	try{
		ctrl.focus();
	} catch(e){}
	if(navigator.appName != "Microsoft Internet Explorer"){
		return 0
		alert(document.getSelection())
		var range = document.getSelection().createRange();
		var weirdStr = String.fromCharCode(1);   // a weird string to
		range.text = weirdStr;
		var pos = ctrl.value.indexOf(weirdStr);  // get the position
		ctrl.value = saveText; 
		try{                  // restore the
			range = ctrl.createTextRange();
			range.move('character', pos);            // restore the cursor
			range.select();
		} catch(e){}
		return pos;
	} else {
		var range = document.selection.createRange();
		var weirdStr = String.fromCharCode(1);   // a weird string to
		range.text = weirdStr;
		var pos = ctrl.value.indexOf(weirdStr);  // get the position
		ctrl.value = saveText; 
		try{                  // restore the
			range = ctrl.createTextRange();
			range.move('character', pos);            // restore the cursor
			range.select();
		} catch(e){}
		return pos;
	}
}
function editNumber(textField, code){
	if(code==8) return true
	if (code==16) return true
	if (code==35) return true
	if ((code>=37) && (code<=40)) return true
	if ((code>=37) && (code<=40)) return false
	if ((code==13)||(code==8)) return true
	if (code==9) {
		if(textField.createTextRange()){
			var f = textField.createTextRange();
			f.moveStart('character', currPos);
			f.select()
		}
		return true
	}
	var currPos=getCursorPos(textField)
	if(navigator.appName == "Microsoft Internet Explorer"){
		if(document.selection.createRange()!=null){
			if(document.selection.createRange()!=undefined){
				if(document.selection.createRange().text.length>0){
					if(document.selection.createRange().parentElement().id==textField.id){
						document.selection.createRange().text=''
					}
				}
			}
		}
	}
	k=code
	if((code>=96)&&(code<=105)) k=k-48
	result=""
	for(i=0;i<textField.value.length;i++){
		if((textField.value.charCodeAt(i)<48)||(textField.value.charCodeAt(i)>57)){
			if(textField.value.charCodeAt(i)==47){
				result=result+textField.value.charAt(i)
			}
		} else {
			result=result + textField.value.charAt(i)
		}
	}
	var kkk=0
	for(var hh=0;hh<result.length-1;hh++){
		if(result.substring(hh,hh+1)=="/"){
			kkk+=1
		}
	}
	if(result.indexOf("/")>=0){
		result=replace(result, "/", "")
		currPos-=kkk
	}
	textField.value=result
	if(textField.createTextRange()){
		var f = textField.createTextRange();
		f.moveStart('character', currPos);
		f.collapse()
		try{
			f.select()
		} catch(e){}
	}
	
	return true	
}
function waitNumber(textField){
	var tmp=setTimeout("editNumber(document.getElementById('"+textField.id+"'), 48)", 100)
}
function replace(string, text, by){
	// Replaces text with by in string
	var strLength = string.length
	var txtLength = text.length
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);

	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if ((i+txtLength) < strLength) {
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	}
	return newstr;
}
function printMe(divID) {
  w=window.open('','newwin', 'left=8000, top=8000')
  w.document.write("<link rel='STYLESHEET' type='text/css' href='../utilities/style.css'>"+document.getElementById(divID).innerHTML)
  w.print()
  w.document.close()
  w.close()
}

function editDate(textField, code){
	if (code==16) return true
	if (code==35) return true
	if ((code>=37) && (code<=40)) return true
	if ((code>=37) && (code<=40)) return false
	if ((code==13)||(code==13)) return false
	
	var currPos=getCursorPos(textField)
	if (code==9) {
		textField.isOk=true
		if(textField.value!=''){
			if(isDate(textField.value)==false){
				textField.value=''
				if((document.getElementById(replace(textField.id, '_box', '_spText'))!=null)&&(document.getElementById(replace(textField.id, '_box', '_SPText'))!=undefined)){
					document.getElementById(replace(textField.id, '_box', '_spText')).value=''
				}
				textField.isOk=false
			}
		}
		if(textField.createTextRange()){
			var f = textField.createTextRange();
			f.moveStart('character', currPos);
			f.select()
		}
		return true
	}
	if(document.selection.createRange()!=null){
		if(document.selection.createRange()!=undefined){
			if(document.selection.createRange().text.length>0){
				if(document.selection.createRange().parentElement().id==textField.id){
					document.selection.createRange().text=''
				}
			}
		}
	}
	var k=code
	if((code>=96)&&(code<=105)) k=k-48
	var result=""
	var i
	for(i=0;i<textField.value.length;i++){
		if((textField.value.charCodeAt(i)<48)||(textField.value.charCodeAt(i)>57)){
			if(textField.value.charCodeAt(i)==47){
				result=result+textField.value.charAt(i)
			}
		} else {
			result=result + textField.value.charAt(i)
		}
	}
	textField.value=result
	if(k==13){
		return false
	}
	var myVal
	myVal=textField.value.length
	switch (myVal)
	{
		case (1):
			if (k>51){
				textField.value+="/"
				currPos=textField.value.length
			}
			break
		case (2):
			if(textField.value.substr(1)!="/"){
				textField.value += "/"
				currPos=textField.value.length
			}
			break
		case(3):
			if(k>49){
				textField.value=textField.value + "/200"
				currPos=textField.value.length
			}
			break
		case(4):
			if(k>49){
				textField.value=textField.value + "/200"
				currPos=textField.value.length
				break
			}
			if(textField.value.split("/")[1].length==2){
				textField.value=textField.value + "/200"
				currPos=textField.value.length
			}
			break
		case(5):
			if(textField.value.substr(4)=="/"){
				textField.value=textField.value + "200"
				currPos=textField.value.length
			} else {
				textField.value=textField.value + "/200"
				currPos=textField.value.length
			}
		case(6):
			break
		case(7):
			break
		case(8):
			break
		case(9):
			break
		case(10):
			break	
	}
	i=textField.value.indexOf("//")
	if(i>=0){
		var myF=textField.value.split("//")
		textField.value=""
		for(var k=0;k<myF.length-1;k++){
			textField.value+=myF[k]+"/"
		}
	}
	if(textField.createTextRange()){
		var f = textField.createTextRange();
		f.moveStart('character', currPos);
		f.collapse()
		try{
			f.select()
		} catch(e){}
	}
    
	return true
}

function editFloat(textField, code){
	if (code==8) return true
	if (code==16) return true
	if (code==35) return true
	if ((code>=37) && (code<=40)) return true
	if ((code>=37) && (code<=40)) return false
	if ((code==13)||(code==8)) return false
	if (code==9) {
		if(textField.createTextRange()){
			var f = textField.createTextRange();
			f.moveStart('character', currPos);
			f.select()
		}
		return true
	}
	var currPos=getCursorPos(textField)
	if(navigator.appName == "Microsoft Internet Explorer"){
		if(document.selection.createRange()!=null){
			if(document.selection.createRange()!=undefined){
				if(document.selection.createRange().text.length>0){
					if(document.selection.createRange().parentElement().id==textField.id){
						document.selection.createRange().text=''
					}
				}
			}
		}
	}
	var dec=parseInt(textField.attributes['SRV_ExecDecimal'].value,10)
	var k=code
	if((code>=96)&&(code<=105)) k=k-48
	result=""
	inDec=false
	myDec=0
	textField.value=replace(textField.value,'.', decimalSeparator)
	textField.value=replace(textField.value,',', decimalSeparator)
	for(i=0;i<textField.value.length;i++){
		if((textField.value.charCodeAt(i)<48)||(textField.value.charCodeAt(i)>57)){
			if(textField.value.charCodeAt(i)==44){
				if (result.indexOf(",")<0){
					if(dec>0){
						result=result+textField.value.charAt(i)
						inDec=true
					}
				}
			}
		} else {
			if ((inDec==false)||(myDec<dec)){
				result=result + textField.value.charAt(i)
				if (inDec) {
					myDec=myDec+1
				}
			}
		}
	}
	textField.value=result
	if(textField.createTextRange()){
		var f = textField.createTextRange();
		f.moveStart('character', currPos);
		f.collapse()
		try{
			f.select()
		} catch(e){}
	}
	return true
}
function editTime(textField, code){
	var myVal
	k=code
	if(k>=96) {
		k=k-48
	}
	if (k==9){
		return false
	}
	if (k>=65){
		textField.value=replace(textField.value, String.fromCharCode(k).toUpperCase() , "")
		textField.value=replace(textField.value, String.fromCharCode(k).toLowerCase() , "")
		return false
	}
	myVal=textField.value.length
	
	if(textField.value.indexOf(":")>=0){
		if(textField.value.split(":")[0].length==0){
			textField.value="00"+textField.value
		}
		if(textField.value.split(":")[0].length==1){
			textField.value="0"+textField.value
		}
	}
	
	switch (myVal)
	{
		case (1):
			if(k>50){
				//textField.value="0"+textField.value + ":"
			}
			break
		case (2):
			if(textField.value.indexOf(":")<0){
				textField.value=textField.value + ":"
			}
			break
		case (3):
			break
		case (4):
			var myVal=textField.value.substring(3)
			if(parseInt(myVal,10)>5){
				textField.value=textField.value.split(":")[0]+":0"+myVal
			}
			break
		case (5):
			break
		default:
	}
			
}
function isTime(mystr) {
  
  var temp=mystr
  retval=false
  var hours, minutes, seconds
  temp=alltrim(temp)
  if (temp.length==4) { 
	   temp="0"+temp
  }
  if (temp.length==5) { 
	   temp+=":00"
  }
     
  if (temp!=""){
	   
	   if (temp.length != 8 || temp.substring(2,3)!=":" || temp.substring(5,6)!=":") {
	   
	   }
	   else {
		  
		  hours=temp.substring(0,2)
		  if (nochars(hours) && parseInt(hours,10) >= 0 && parseInt(hours,10) < 24) {
			hours=parseInt(hours,10)
			minutes=temp.substring(3,5)
			if (nochars(minutes)) {
			      minutes=parseInt(minutes,10)
			      if (minutes >=0 && minutes <=59) {
				    seconds=temp.substring(6,8)
				    
				    if (nochars(seconds) && parseInt(seconds,10) >= 0 && parseInt(seconds,10)<=59) {
					  retval=true
				    }
			      }
			}
		 }
	   }
  }
 return retval
}
function alltrim(mys){
   var trimmedstring=""
   var startpos=0
   var endpos=mys.length - 1	
   while (startpos<=mys.length && mys.substring(startpos, startpos+1)==" ") {
 	   startpos++
   }
   if (endpos == -1) {
     endpos=0
   }
   while (endpos >= 0 && mys.substring(endpos,endpos+1)==" ") {
	   endpos--
   }
   
   return mys.substring(startpos,endpos+1)
}
function nochars(strval) {
      var retval=true
	   for (var i=0; i<strval.length;i++) {
		 if (strval.substring(i,i+1) < "0" || strval.substring(i,i+1) > "9") {
		       retval=false
		       break
		 }
	   }
	   return retval
}
