// JavaScript Document

imageWindow = null;
function imagePop(width,height,title,imgsrc)
{
	
windowURL = "winpop.php?width="+width+"&height="+height+"&title="+title+"&imgsrc="+imgsrc;	
	
	if(imageWindow != null)
	{
	imageWindow.close();	
	imageWindow = window.open(windowURL,'_blank','width=50,height=50,scrollbars=no,status=no,titlebar=no');
	}	
	else
	imageWindow = window.open(windowURL,'_blank','width=50,height=50,scrollbars=no,status=no,titlebar=no');
}


theWindow = null;
function openWindow(windowURL)
{
	if(theWindow != null)
	{
	theWindow.close();	
	theWindow = window.open(windowURL,'_blank','width=150,height=177,scrollbars=no,status=no');
	}	
	else
	theWindow = window.open(windowURL,'_blank','width=150,height=177,scrollbars=no,status=no');
}

theWindow2 = null;
function openWindow2(windowURL)
{
	if(theWindow2 != null)
	{
	theWindow2.close();	
	theWindow2 = window.open(windowURL,'_blank','width=550,height=177,scrollbars=no,status=no');
	}	
	else
	theWindow2 = window.open(windowURL,'_blank','width=550,height=177,scrollbars=no,status=no');
}



function NoHTML(sText)
{
   var InvalidChars = "><";
   var HTMLcheck =true;
   var Char;

 
   for (i = 0; i < sText.length && HTMLcheck == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (InvalidChars.indexOf(Char) != -1) //if items are found 
         {
         HTMLcheck = false;
         }
      }
   return HTMLcheck;
}

function getURL()
{
test = location.href;

test= test.split("/");
str = "";
for(i=0;i<(test.length-1);i++)
{
	if(i == 0)
	str = test[i]+"/";
	else
	str = str + test[i] + "/";
}
return str;
}

function $(id) {
  return document.getElementById(id);
}


//==== Login form check function =====>
function logForm (form){

  if (form.login.value == ""){

    alert( "Please enter a vaild login." );
    logform.login.focus();
    return false;
  }
  
  if (form.pasword.value == ""){

    alert( "Please enter a vaild password." );
    logform.pasword.focus();
    return false;
  }
}

//==== Form check function =====>
function checkform (form){

  if (form.name.value == ""){

    alert( "Please enter your name." );
    form.name.focus();
    return false;
  }
  
  if (form.phone.value == ""){

    alert( "Please enter your phone number." );
    form.phone.focus();
    return false;
  }
  
  if (form.number_of_adults.value == ""){

    alert( "Please enter number of adults." );
    form.number_of_adults.focus();
    return false;
  }

  else{

     pattern = /^\d+$/;
 
     if (form.number_of_adults.value != "" ){

        if ( pattern.test(form.number_of_adults.value)==false ){

          alert ("You must enter a numeric value. Ex: 5");
          form.number_of_adults.focus();
		  return false;
        }
    }	  
  }

  if (form.number_of_children.value == ""){

    alert( "Please enter number of children." );
    form.number_of_children.focus();
    return false;
  }
  
  else{

     pattern = /^\d+$/;
 
     if (form.number_of_children.value != "" ){

        if ( pattern.test(form.number_of_children.value)==false ){

          alert ("You must enter a numeric value. Ex: 5");
          form.number_of_children.focus();
		  return false;
        }
     }	  
  }
  
  if (form.comments.value == ""){

    alert( "Please enter comments." );
    form.comments.focus();
    return false;
  }
  else
  {
	temp = NoHTML(form.comments.value);

	if(!temp)
	{
    alert( "< or > are invalid characters for comments." );
    form.comments.focus();
    return false;		
	}
	
  }
  
  
  populateKey(); 
   
  return true;
}

function populateKey()
{
$('key').value = getURL();	
}


//==== Email Check function =====>

function IsEmail(sText){

var whereisAT = sText.indexOf('@');

 if(whereisAT == -1){

    return false;
 }
   
 var whereisDOT = sText.indexOf('.');  

 if(whereisDOT == -1){

    return false;
 }
     
    return true;
}

