/** MOODAL **/
function doAlert(msg){
	alert(msg);
}

function asubmit(what){
	var oSubmit;
	oSubmit = document.getElementById('mod_submit');	
	if(what==1){
	oSubmit.value = 'Please Wait...';
	oSubmit.disabled = true;	
	}else{
	oSubmit.value = 'Send!';
	oSubmit.disabled = false;			
	}
}

function Trim(str) 
{  if(str.charAt(0) == " ")
  {  str = Trim(str.substring(1));
  }
  if (str.charAt(str.length-1) == " ")
  {  str = Trim(str.substring(0,str.length-1));
  }
  return str;
}
function IsInt(sText,sType){ 
   if(sType=='num'){
	   var ValidChar = '0123456789';
   }else if(sType=='int'){
	   var ValidChar = '123456789';
   }else if(sType=='dec'){
	   var ValidChar = '0123456789.';
   }else{
	   var ValidChar = sType;
   };

   var IsNumber=true;
   if(!sText.length){
	   IsNumber=false;
   };
   
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChar.indexOf(Char) == -1){
         IsNumber = false;
         };
      };
   return IsNumber;
}
function getFormElement(eName,eType){
	var _return;
	var _oSel = document.getElementById(eName);
	if(eType=='select'){
		_return = _oSel.options[_oSel.selectedIndex].value;
	}else{
		_return = _oSel.value;
	}
	return _return;	
}
function modValid(){
	asubmit(1);
	var isValid = true
	var mod_purpose 	= getFormElement('mod_purpose','select');
	var mod_numbervilla = getFormElement('mod_numbervilla','text');
	var mod_adult 		= getFormElement('mod_adult','text');
	var mod_child 		= getFormElement('mod_child','text');
	var mod_checkin  	= getFormElement('mod_checkin','text');
	var mod_checkout 	= getFormElement('mod_checkout','text');
	var mod_pickup 		= getFormElement('mod_pickup','checkbox');
	var mod_transfer 	= getFormElement('mod_transfer','checkbox');
	
	var mod_name   		= getFormElement('mod_name','text');
	var mod_email  		= getFormElement('mod_email','text');
	var mod_phone  		= getFormElement('mod_phone','text');
	var mod_comment 	= Trim(getFormElement('mod_comment','text'));
	var mod_spam 		= Trim(getFormElement('mod_spam','text'));
	
	if (parseInt(mod_purpose)<1){
		isValid = false;
		alert('Please choose what kind of submission you would like to do');
		asubmit();
		return false;		
	}
	if (parseInt(mod_purpose)==1){
		// validate booking element
		if ((!(IsInt(mod_numbervilla,'num')))||(mod_numbervilla<1)){
			isValid = false;
			alert('Number of villas required');
			asubmit();
			return false;												 	
		}
		if ((!(IsInt(mod_adult,'int')))||(mod_adult<1)){
			isValid = false;
			alert('Number of adult required');
			asubmit();
			return false;												 	
		}		
		if (!isDate(mod_checkin,' in Checkin Date Field')){
			isValid = false;
			asubmit();
			return false;
		}//mod_checkin
		
		if (!isDate(mod_checkout,' in Checkout Date Field')){
			isValid = false;
			asubmit();
			return false;
		}//mod_checkout		
	}else{
		// validate comment
		if(mod_comment.length<5){
			isValid = false;
			alert('Please specify what kind of info that you need from us\n in the comment box (min 5 chars)');
			asubmit();
			return false;			
		}
	}
	
	if (mod_name.length<2||mod_name.length>100){
		isValid = false;
		alert('Your name min 2 characters and max 100 characters in length');
		asubmit();
		return false;
	}//mod_name
	
	var objRegExp  = /^[a-zA-Z0-9.][a-zA-Z0-9-_\s]+@[a-zA-Z0-9-\s].+\.[a-zA-Z]{2,5}$/;
	
	if (!objRegExp.test(mod_email)){
		isValid = false;
		alert('invalid email address!');
		asubmit();
		return false;
	}//mod_email	
	
	if (mod_phone.length<5||mod_phone.length>15){
		isValid = false;
		alert('Your phone required (5 to 15 characters in length)');
		asubmit();
		return false;
	}//mod_phone	
	
	if (mod_spam.length != 6){
		isValid = false;
		alert('Type the correct code to verify you are not spam');
		asubmit();
		return false;
	}//mod_spam	
	
	//alert(isValid);
	if(isValid){
		return true;
	}else{
		return false;
	}
}