﻿// JavaScript Document

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("ul");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function viewportHeight(){
	var viewportheight;
 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight 
	if (typeof window.innerWidth != 'undefined'){
	      viewportheight = window.innerHeight
	}
 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	    && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
	       viewportheight = document.documentElement.clientHeight
	}
 
	// older versions of IE
	else{
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	//	alert('Your viewport width is '+viewportwidth+'x'+viewportheight);
	return viewportheight;
}

function viewport(){
	var content = document.getElementById("content").style.height;
	content = document.getElementById("content").style.height = viewportHeight()-159;
}

function Set_Cookie( name, value, expires, path, domain, secure ){
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
/* 
if the expires variable is set, make the correct expires time, the current script below will set it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24
*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		    alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.contactForm.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter a valid email address.")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
	return true
 }