function checksix(x, y)
{
		
	var strng = document.getElementById(x).value;
	if ((strng.length >= y))
	{ document.getElementById(x).value=strng.substring(0,y);
	alert("Max "+y+" characters allowed");
	}
	
	var lft=(y-(strng.length));
	lft=lft.toString()
	//document.getElementById(x+'max').innerHTML = lft.concat(" characters left ");

}

function checkfile(x)
{ 
  
  var re_text = /\.jpg|\.jpeg|\.png/i;
   
    /* Checking file type */
	if(x.value!='')
	{
    	if (x.value.search(re_text) == -1)
	    {
        // alert("Please Attached Microsoft Word Document only.");
         alert('Please attach jpg/jpeg/png Document only.');
		 x.value='';
		 x.focus();
	    }
	}
	
	

}
function dosubmit()
{
	//alert(document.getElementById('terms').value)	;
	if(document.getElementById('terms').checked)
		{
//			document.form1.s.
		document.getElementById('submit').disabled=false;
		}
	else
		{
		
		document.getElementById('submit').disabled=true;
		}
		
}
	

function checkWholeForm(theForm) {
	
    var why = "";
	
   // why += checkUsername(theForm.username.value, 'username');
    //why += checkPassword(theForm.password.value, theForm.confirmpassword.value);
	 why += isEmpty(theForm.hotel_name.value, 'hotel_name');
	 why += checkDropdown(theForm.category.value, 'category');
	 // why += isEmpty(theForm.company.value, 'company');
	//
	  
	 
	  why += checkDropdown(theForm.country.value, 'country');
	why += checkDropdown(theForm.States.value, 'States');
	why += checkDropdown(theForm.Cities.value, 'Cities');
	why += checkDropdown(theForm.Localities.value, 'Localities');
//		why += checkDropdown(theForm.Cities.selectedIndex.value, 'City');
		why += isEmpty(theForm.address.value, 'address');
		why += isEmpty(theForm.zip.value, 'zip');
		if( (theForm.phone1.value=='')   || !(isNum(theForm.phone1.value)))
			{	why += 	'Invalid Phone 1\n';
				document.getElementById('phone1').style.background="#ffbeaa";	
			}
		if( (theForm.phone2.value=='')   || !(isNum(theForm.phone2.value)))
			{	why += 	'Invalid Phone 2\n';
				document.getElementById('phone2').style.background="#ffbeaa";	
			}
		if( (theForm.fax.value=='') || !(isNum(theForm.fax.value)))
			{	why += 	'Invalid Fax Number\n';
				document.getElementById('fax').style.background="#ffbeaa";	
			}
	// why += checkPhone(theForm.mobile.value, 'mobile');
	 //why += checkPhone(theForm.day_phone.value, 'day_phone');
 	 //why += checkPhone(theForm.night_phone.value, 'night_phone');
	 
    why += checkEmail(theForm.emailid.value, 'emailid');
	why += isEmpty(theForm.cp.value, 'cp');
	why += isEmpty(theForm.designation.value, 'designation');
	if( (theForm.contact_no.value=='')   || !(isNum(theForm.contact_no.value)))
			{	why += 	'Invalid Contact No\n';
				document.getElementById('contact_no').style.background="#ffbeaa";	
			}
	if( (theForm.mobile.value=='')   || !(isNum(theForm.mobile.value)))
			{	why += 	'Invalid Mobile No\n';
				document.getElementById('mobile').style.background="#ffbeaa";	
			}
	why += checkEmail(theForm.email.value, 'email');	
	/*if( (theForm.airport_distance.value=='')   || !(isNum(theForm.airport_distance.value)))
			{	why += 	'Pls check Airport Distance\n';
				document.getElementById('airport_distance').style.background="#ffbeaa";	
			}
			
	if( (theForm.railway_distance.value=='')   || !(isNum(theForm.railway_distance.value)))
			{	why += 	'Pls Check Railway Station Distance\n';
				document.getElementById('railway_distance').style.background="#ffbeaa";	
			}
		
	if( (theForm.bus_distance.value=='')   || !(isNum(theForm.bus_distance.value)))
			{	why += 	'Pls check Bus Stand Distance\n';
				document.getElementById('bus_distance').style.background="#ffbeaa";	
			}	*/
			
	var checkin= parseInt(theForm.check_inHour.value+theForm.check_inMinute.value);
	var checkout= parseInt(theForm.check_outHour.value+theForm.check_outMinute.value);
	if(checkin<checkout)
			{	why += 	'Check-Out Time should be before Check-In Time\n';
				document.getElementById('check_inHour').style.background="#ffbeaa";	
			}
	/* why += isEmpty(theForm.hotel_overview.value, 'hotel_overview');
	why += isEmpty(theForm.location_advantage.value, 'location_advantage');
	why += isEmpty(theForm.hotel_policy.value, 'hotel_policy');
	*/		
	 var re_text = /\.jpg|\.jpeg|\.png|\.gif/i;
   
    if (document.getElementById('mainimg').value.search(re_text) == -1)
    {
      // why += 'Please attach jpg/jpeg/gif/png in Phtotograph\n';
       //document.getElementById('mainimg').style.background="#ffbeaa";	
		 
    }		
	//contact_no
	   
	//why += checkDropdown(theForm.agent_type.value, 'agent_type');
     
//    why += isDifferent(theForm.different.value);
    
   
    if (why != "") {
       alert(why.toUpperCase() );
       return false;
    }
	else
	{
		//alert("Well done! Data is Valid");
	}
return true;
}





/**********************  VALIDATION FUNCTIONS BELOW ********************
/**********************                              *******************/


// email

function checkEmail (strng, nm) {
	document.getElementById(nm).style.background="#ffffff";
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
    document.getElementById(nm).style.background="#ffbeaa";
}
else
{

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
}
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng, nm) {
		document.getElementById(nm).style.background="#ffffff";
var error = "";
if (strng == "") {
   error = "You didn't enter a ";
   error += nm;
   error += "\n";
    document.getElementById(nm).style.background="#ffbeaa";
}
else
{
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
		error = nm;
       error += " contains illegal characters.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
  
    }
    //if (!(stripped.length == 10)) {
	//error = "The phone number is the wrong length. Make sure you included an area code.\n";
    //} 
}
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng, strng2) {
		document.getElementById('password').style.background="#ffffff";
		document.getElementById('confirmpassword').style.background="#ffffff";
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
    document.getElementById('password').style.background="#ffbeaa";
	  document.getElementById('confirmpassword').style.background="#ffbeaa";
}
else 
{

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 8) || (strng.length >20)) {
       error = "The password is the wrong length.(Should be 8 to 20 characters)\n";
	    document.getElementById('password').style.background="#ffbeaa";
	  document.getElementById('confirmpassword').style.background="#ffbeaa";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
	   document.getElementById('password').style.background="#ffbeaa";
   	  document.getElementById('confirmpassword').style.background="#ffbeaa";
    } 
   // else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
    //   error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    //}  
}
 if(strng != strng2)
{  error = "Password / Confirm Password feilds does't match.\n";
	 document.getElementById('password').style.background="#ffbeaa";
 	  document.getElementById('confirmpassword').style.background="#ffbeaa";
}
 
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng, nm) {
   document.getElementById(nm).style.background="#ffffff";
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
   document.getElementById(nm).style.background="#ffbeaa";
}
else
{

    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 6) || (strng.length > 20)) {
       error = "The username is the wrong length (Should be 6 to 20 characters).\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
	 document.getElementById(nm).style.background="#ffbeaa";
    } 
}
return error;
}       


// non-empty textbox

function isEmpty(strng, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
  if (strng.length == 0) {
     error = " ";
	 if(nm=='cp')
	 { error += 'Contact Person';
	 }
	 else
	 {
	 error += nm;
	 }
	 error += "  has not been filled in.\n";
	  document.getElementById(nm).style.background="#ffbeaa";
  }
return error;	  
}


// exactly one radio button is chosen

function checkRadio(checkvalue, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
   if (!(checkvalue)) {
       error = "Please choose category.\n";
	    document.getElementById(nm).style.background="#ffbeaa";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice, nm) {
	   document.getElementById(nm).style.background="#ffffff";
var error = "";
//alert(" It is "+choice);
    if (choice == '')
	{
    error = "You didn't choose an option from the drop-down ";
	error += nm;
	error += "\n";
	 document.getElementById(nm).style.background="#ffbeaa";
    } 
	else if(choice == 0)
	{	//alert("Hi I am 0");
		if(nm=='Country')
		{
			//alert("Country");	
		}
		if(nm=='States')
		{
			//alert("States");
			if(document.getElementById('otherstate').value=='')
			error = "You didn't fill in 'Other State' \n ";
			 
			   
		}
		if(nm=='Cities')
		{
			//alert("Cities");	
			if(document.getElementById('othercity').value=='')
			error = "You didn't fill in 'other City' \n ";
		}
		
		if(nm=='Localities')
		{
			if(document.getElementById('otherlocality').value=='')
			{error = "You didn't fill in 'other locality' \n ";
			document.getElementById('otherlocality').style.background="#ffbeaa";
			}
		}
	}
		
		
	
return error;
}    

var numb = '0123456789 ';
var lwr = 'abcdefghijklmnopqrstuvwxyz ';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';

function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}
function isDecimal(parm) {return isValid(parm,numb+'.');}

           