// 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)  
         {
           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);
}


//==== Feedback form check function =====>
function checkform2 (form){

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

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

    alert( "Please enter your last name." );
    form.lname.focus();
    return false;
  }

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

    alert( "Please enter your e-mail." );
    form.email.focus();
    return false;
  }
  else{
	
	temp = IsEmail(form.email.value);

	if(!temp)
	{
      alert( "Invalid email." );
      form.email.focus();
      return false;		
    }
	  
  }

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

    alert( "Please enter your phone number." );
    form.phone.focus();
    return false;
  }

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

    alert( "Please enter your 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;

}


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

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

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

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

    alert( "Please enter your e-mail." );
    form.email.focus();
    return false;
  }
  
  if (form.email.value != ""){

    temp = IsEmail(form.email.value);

	if(!temp)
	{
      alert( "Invalid email." );
      form.email.focus();
      return false;		
    }
  }
  
  if (form.phone.value == ""){

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

    alert( "Please enter a valid comment." );
    form.comments.focus();
    return false;
  }
  
  if (form.comments.value != ""){

    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;
}


