// JavaScript Document
function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function showimage(){
		if (document.form_otherset.imgresize[0].checked){
		ap1=document.getElementById("showattrib");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
				}				
		}
		else
		{
			ap1=document.getElementById("showattrib");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
				}
		}
	}
	function popupmenus(url)
{
	width=screen.width;
	center=width/2;
	leftpos=20;
	newwindow=window.open(url,'LinkGenerator','height=350,width=500,left='+leftpos+',top=0,resizable=yes,scrollbars=yes');
	if (window.focus) 
	{
	newwindow.focus()
	}
}
function menu_validate()
{
	if(document.form_menu.menuname.value == "")
	{
	   alert("Please Enter Menu Name");
	   document.form_menu.menuname.focus();
	   return false;
	}
	if(document.form_menu.txtpagename.value == "")
	{
	   alert("Please Enter Page Name");
	   document.form_menu.txtpagename.focus();
	   return false;
	}
	if(document.form_menu.needsubmenu.value == "")
	{
	   alert("Please Select Submenu Name");
	   document.form_menu.needsubmenu.focus();
	   return false;
	}
		if(document.form_menu.displayorder.value == "")
	{
	   alert("Please Enter display order");
	   document.form_menu.displayorder.focus();
	   return false;
	}
	if(isNaN(document.form_menu.displayorder.value))
	{
	   alert("Display Order must be a numeric value");
	   document.form_menu.displayorder.focus();
	   return false;
	}
}
function submenu_validate()
{
	if(document.frm_subcategory.txt_submenuname.value == "")
	{
	   alert("Please Enter Sub Menu Name");
	   document.frm_subcategory.txt_submenuname.focus();
	   return false;
	}
	if(document.frm_subcategory.txtpagename.value == "")
	{
	   alert("Please Enter Page Name");
	   document.frm_subcategory.txtpagename.focus();
	   return false;
	}
}

	function showshopsubcat(x,y){
	window.location.href = "index.php?do=occupancy&task=addoccupancy&catname="+x+"&c_id="+y;
}
var lists=new Array();
function changeList(box) 
{
	//alert(box.options[box.selectedIndex].value);
	//alert(lists[box.options[box.selectedIndex].value]);
	list = lists[box.options[box.selectedIndex].value];
	//alert(list);
	if(box.options[box.selectedIndex].value != "select" && box.options[box.selectedIndex].value != "Choose" && box.options[box.selectedIndex].value != "")
	{
		
		emptyList(box.form.int_roomid);
		fillList(box.form.int_roomid, list );
	}
}
function emptyList(box) 
{
	while (box.options.length) box.options[0] = null;
}

function fillList( box, arr ) 
{
	//alert(arr);
	for ( i = 0; i < arr[0].length; i++ ) 
	{
		opton = new Option( arr[0][i], arr[0][i+1] );
		box.options[box.length] = opton;
		i=i+1;
	}
	box.selectedIndex=0;
}



	function shodetails(){
	if(document.frmoccupancy.pickup[1].checked) 
	{
		shipname=document.getElementById("secondapplicant");
		if(shipname){
		shipname.style.display="block";
		shipname.style.visibility="visible";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="none";
		shipname11.style.visibility="hidden";
		}
			
	}
	else if (document.frmoccupancy.pickup[0].checked) 
	{
	   shipname1=document.getElementById("secondapplicant");
		if(shipname1){
		shipname1.style.display="none";
		shipname1.style.visibility="hidden";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="block";
		shipname11.style.visibility="visible";
		}
		
	}
		else
	{
	   shipname1=document.getElementById("secondapplicant");
		if(shipname1){
		shipname1.style.display="none";
		shipname1.style.visibility="hidden";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="none";
		shipname11.style.visibility="hidden";
		}
		
	}
}


	function setting_validate()
{
	if(document.form_payment.paymode.checked == "")
	{
		alert("Please Enter the Mode of Payment");
		document.form_payment.paymode.focus();
		return false;
	}
	if(document.form_payment.paypaladdr.value == "")
	{
		alert("Please Enter the Paypal Business Address");
		document.form_payment.paypaladdr.focus();
		return false;
	}
	if(document.form_payment.paypaltoken.value == "")
	{
		alert("Please Enter the Paypal Token Number");
		document.form_payment.paypaltoken.focus();
		return false;
	}
	return true;
}

function confirmMsg(msg){
if(!confirm(msg)){
	return false;

} else {
	return true;

}
}

//Change Reg type
function showpaydetail(){
		if (document.frm_member.regtype.value == "SELLER"){
		ap1=document.getElementById("showattrib");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
				}				
		}
		else
		{
			ap1=document.getElementById("showattrib");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
				}
		}
	}

function change_searchtype()
{
var catname=document.frm_search.catid.value;

	if (catname=="All")
	{
		window.location.href="index.php?do=memberpersale&task=viewmemberpersale";
	}
	else
	{
		window.location.href="index.php?do=memberpersale&task=viewmemberpersale&pettype="+document.frm_search.catid.value;
	}
}

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}


function myprofile_validate()
{
	     var txtcompany = document.form_myprofile.company.value;
		 if (txtcompany == "" )
		 { 
			 alert ("Please enter Company Name");
			 document.form_myprofile.company.focus();
			 return false;
		 }
             var contactperson = document.form_myprofile.txt_contactperson.value;
		 if (contactperson == "" )
		 { 
			 alert ("Please enter Name");
			 document.form_myprofile.txt_contactperson.focus();
			 return false;
		 }
              var email = document.form_myprofile.txt_email.value;
               if (!validateEmail(document.form_myprofile.txt_email.value,1,1)) 
		 {
			 document.form_myprofile.txt_email.focus();
			 return false;
		 }
		 
               var phone = document.form_myprofile.txt_phone.value;
		 if (phone == "" )
		 { 
			 alert ("Please enter Telephone Number");
			 document.form_myprofile.txt_phone.focus();
			 return false;
		 }
                var username = document.form_myprofile.txt_username.value;
		 if (username == "" )
		 { 
			 alert ("Please enter Username");
			 document.form_myprofile.txt_username.focus();
			 return false;
		 }
                  var password = document.form_myprofile.txt_password.value;
		 if (password == "" )
		 { 
			 alert ("Please enter Password");
			 document.form_myprofile.txt_password.focus();
			 return false;
		 }
}


function admin_validation(){
var txtUsername=document.Login.txtUsername.value;
	 if(txtUsername == "")
			 {
			 alert("Username is empty");
			 document.Login.txtUsername.focus();
			 return false;
			 }
var txtPassword=document.Login.txtPassword.value;
	 if(txtPassword == "")
			 {
			 alert("Password is empty");
			 document.Login.txtPassword.focus();
			 return false;
			 }
}



function  cms_validate()
{
	     /*var heading = document.frm_cms.heading.value;
		 if (heading == "" )
		 { 
			 alert ("Please enter heading");
			 document.frm_cms.heading.focus();
			 return false;
		 }*/
              var pagetitle = document.frm_cms.pagetitle.value;
		 if (pagetitle == "" )
		 { 
			 alert ("Please enter page title");
			 document.frm_cms.pagetitle.focus();
			 return false;
		 }
            var metakey = document.frm_cms.metakey.value;
		 if (metakey == "" )
		 { 
			 alert ("Please enter Meta keyword");
			 document.frm_cms.metakey.focus();
			 return false;
		 }
           var metadesc = document.frm_cms.metadesc.value;
		 if (metadesc == "" )
		 { 
			 alert ("Please enter Meta Description");
			 document.frm_cms.metadesc.focus();
			 return false;
		 }
}



         
  function generalsetting_validate()
{

 if (document.form_general.txt_website.value == "") 
		{
			alert ("Please enter the website URL.");
			document.form_general.txt_website.focus();
			return false;
		}
  

        var txt_numrows = document.form_general.txt_numrows.value;
	if (txt_numrows == "")
	 { 
		 alert ("Please enter the number of rows displayed per page in Admin Panel.");
		 document.form_general.txt_numrows.focus();
		 return false;
	 }	
	 if(isNaN(txt_numrows) || txt_numrows == 0 || txt_numrows.indexOf('.') >= 0 || txt_numrows.indexOf('-') >= 0 ){
		alert("Rows must be a numeric value.");
		document.form_general.txt_numrows.focus();
		return false;

}
           var txt_frontrows = document.form_general.txt_frontrows.value;
	if (txt_frontrows == "")
	 { 
		 alert ("Please enter the number of rows displayed per page in Front Panel.");
		 document.form_general.txt_frontrows.focus();
		 return false;
	 }	
	 if(isNaN(txt_frontrows) || txt_frontrows == 0 || txt_frontrows.indexOf('.') >= 0 || txt_frontrows.indexOf('-') >= 0 ){
		alert("Rows must be a numeric value.");
		document.form_general.txt_frontrows.focus();
		return false;

}

       var txt_admintitle = document.form_general.txt_admintitle.value;
		 if (txt_admintitle == "" )
		 { 
			 alert ("Please enter Admin Title");
			 document.form_general.txt_admintitle.focus();
			 return false;
		 }
        
}


function  seo_validate()
{
	   
              var pagetitle = document.frm_seo.pagetitle.value;
		 if (pagetitle == "" )
		 { 
			 alert ("Please enter page title");
			 document.frm_seo.pagetitle.focus();
			 return false;
		 }
            var metakey = document.frm_seo.metakey.value;
		 if (metakey == "" )
		 { 
			 alert ("Please enter Meta keyword");
			 document.frm_seo.metakey.focus();
			 return false;
		 }
           var metadesc = document.frm_seo.metadesc.value;
		 if (metadesc == "" )
		 { 
			 alert ("Please enter Meta Description");
			 document.frm_seo.metadesc.focus();
			 return false;
		 }
}

function emailcon_validate()
{
	var txt_subject = document.frm_email.txt_subject.value;
		 if (txt_subject == "" )
		 { 
			 alert ("Please enter Subject");
			 document.frm_email.txt_subject.focus();
			 return false;
		 }
}


//Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function bookingvalidate()
{
	
	         var intCatid = document.frmoccupancy.intCatid.value;
		 if (intCatid == "" )
		 { 
			 alert ("Please select Room Name");
			 document.frmoccupancy.intCatid.focus();
			 return false;
		 }
	
		     var txtname = document.frmoccupancy.txtname.value;
		 if (txtname == "" )
		 { 
			 alert ("Please enter First Name");
			 document.frmoccupancy.txtname.focus();
			 return false;
		 }
             var lastname = document.frmoccupancy.lastname.value;
		 if (lastname == "" )
		 { 
			 alert ("Please enter the Last Name");
			 document.frmoccupancy.lastname.focus();
			 return false;
		 }
		      var contactemail = document.frmoccupancy.contactemail.value;
               if (!validateEmail(document.frmoccupancy.contactemail.value,1,1)) 
		 {
			 document.frmoccupancy.contactemail.focus();
			 return false;
		 }
		 
		      var nopeople = document.frmoccupancy.nopeople.value;
		 if (nopeople == "" )
		 { 
			 alert ("Please enter No of Adults in the party");
			 document.frmoccupancy.nopeople.focus();
			 return false;
		 }
             var nochild = document.frmoccupancy.nochild.value;
		 if (nochild == "" )
		 { 
			 alert ("Please enter No of Children in the party");
			 document.frmoccupancy.nochild.focus();
			 return false;
		 }
         
             var start_date = document.frmoccupancy.start_date.value;
		 if (start_date == "" )
		 { 
			 alert ("Please select Arrival Date");
			 document.frmoccupancy.start_date.focus();
			 return false;
		 }
         
	 
}
