//   FUNCTIONS needed by the form pages



//   ---------------- CALENDAR FUNCTIONS -------------------------//

function checkDate(o, f){
	if(document.selection){document.selection.empty()}
	
	var sDate = PopCalendar.formatDate(o.value, f, "dd-mm-yyyy")

	if ((sDate == "") || (sDate < "01-01-1900")){
		o.value = ""
	}
}

function keyPressed(e){
	if (PopCalendar.ie){
		if (event.keyCode==9){
			return true
		}else if (event.keyCode==46){
			return true
		}
	}else{
		return true
	}
	return false
}

//   ---------------- END CALENDAR FUNCTIONS -------------------------//

//   ---------------- VALIDATION FUNCTIONS -------------------------//

function checkInt(field,fieldCaption){
 
 resInt = true;
		
 if(field) {
	 intvalue = field.value;
	 if(intvalue != ''){
		 if (isNaN(intvalue)) {
		    field.value='';		    
		    resInt = false;
		 } else if(intvalue.split('.').length>1){
		    field.value='';
		    resInt = false;
		 } 
	 }
 }
 
 return resInt;
}

function checkReal(field,fieldCaption){

 resReal = true;
 
 if(field) {	
	 floatvalue = field.value;
	 if(floatvalue != ''){
		 if (isNaN(floatvalue)) {
		    field.value='';
		    resReal = false;	    
		 } 
	 }
 }
 
 return resReal;
}

function checkEmptyText(field,fieldCaption){
	
 resEmpty = true;
 	
 if(field) {	
	 stringvalue = field.value;

	 if ((!stringvalue) || (stringvalue == "")) {
	    field.value='';
	    resEmpty = false;
	 } 	 
 }
 
 return resEmpty;
}

function checkEmptyCheckBoxList(fieldName,fieldCaption,listSize){	 
	 resEmptyCB = false;
	 i = 0;
	 
	 while(i<listSize && !resEmptyCB) {
		 field = document.forms[0][fieldName+i];
		 if(field) {	
	 		if(field.checked){
	 			resEmptyCB = true;
 			}
 		}
 		
	 	i++;	 
	 }	
 	
 	return resEmptyCB;
}

function checkEmail(field,fieldCaption){
 resEMail = true;	
 //expresion regular para emails
 var er_email = /^(.+\@.+\..+)$/
 
 
 if(field) { 
	 stringvalue = field.value;
	 if(stringvalue != ''){
		 if (!er_email.test(stringvalue)) {
		    field.value='';	    
			resEMail = false;
		 } 
	 }
 }
 
 return resEMail;
}

//   ---------------- END VALIDATION FUNCTIONS -------------------------//

//   ---------------- FORM FUNCTIONS -------------------------//

function submitFormWeb(e){		  	
  	var formulario = document.forms[e];	
	sendForm = checkFormFields();
	
	if(sendForm) {		
		formulario.submit();
	}
}

function clearFormWeb(e){	  	
  	var formulario = document.forms[e];		
    formulario.reset();	
}

//   ---------------- END FORM FUNCTIONS -------------------------//
