var DHTML = (document.getElementById || document.all || document.layers);


//----------------------------------------------------------------------------------------------------------------
//	DOM OBJECT CODE
//----------------------------------------------------------------------------------------------------------------

// this is a class. Call it with new
// var my_var = new getObj('html_id');
function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
        this.obj = document.layers[name];
        this.style = document.layers[name];
  }
}

//----------------------------------------------------------------------------------------------------------------

function initMainNav(){
	// if its a crappy browser, do not continue
	if ( (!DHTML)  || (!document.cloneNode)  ){
		return;
	}
	
	// get the <ul> that contains the main nav
	var main_nav = new getObj('mainNav');
	// get the main nav child node
	var main_nav_child_nodes = main_nav.obj.childNodes;
	// loop the child nodes of the main nav
	for(var x=0; x<main_nav_child_nodes.length; x++){
		// see if the child is a <li>
		if(main_nav_child_nodes[x].nodeName == 'LI'){
			// set hover behaviour. XP IE does not recognize the CSS way for li:hover
//			main_nav_child_nodes[x].onmouseover = jsLiHoverOver;
//			main_nav_child_nodes[x].onmouseout = jsHoverOut;
			
			// get the <li>s child nodes
			var li_child_nodes = main_nav_child_nodes[x].childNodes;
			
			// loop the li child nodes
			for(var y=0; y<li_child_nodes.length; y++){
			
				// if the <li> contains a <ul> child
				if(li_child_nodes[y].nodeName == 'UL'){
					// this <li> contains a <ul> that is a flyout menu
					// set the mouseover and mouseout
					main_nav_child_nodes[x].onmouseover = showFlyoutMenuOver;
					main_nav_child_nodes[x].onmouseout = showFlyoutMenuOut;
					// store the <ul> node
					main_nav_child_nodes[x].submenu = li_child_nodes[y];
					//main_nav_child_nodes[x].active = false;
					
				}// end if(li_child_nodes[y].nodeName == 'A')
			}// end for(var y=0; y<li_child_nodes.length; y++)
		}//end if(main_nav_child_nodes[x].nodeName == 'LI')
	}//end for(var x=0; x<main_nav_child_nodes.length; x++)
}


//----------------------------------------------------------------------------------------------------------------

function jsLiHoverOver(){
	//this.style.backgroundColor = '#5B8EC1';
	//this.style.borderColor =  '#375A7E #375A7E #5B8EC1 #375A7E';
}

//----------------------------------------------------------------------------------------------------------------

function jsHoverOut(){
	//this.style.backgroundColor = '#94A4AE';
	//this.style.borderColor =  '#375A7E';
}

//----------------------------------------------------------------------------------------------------------------

function showFlyoutMenuOver(){
	//this.style.backgroundColor = '#7C8991';
	//this.style.borderColor =  '#375A7E #375A7E #5B8EC1 #375A7E';
	this.submenu.style.left = '125px';
	this.submenu.style.top = '0px';
}

//----------------------------------------------------------------------------------------------------------------

function showFlyoutMenuOut(){
	//this.style.backgroundColor = '#94A4AE';
	//this.style.borderColor =  '#375A7E';
	this.submenu.style.left = '-3000px';
}

//----------------------------------------------------------------------------------------------------------------

function adminEditContent(form, id){
	form.var_id.value = id;
	form.submit();
}

//==========================================================
//	BEGIN FUNCTION FOR CONTACT.PHP
//==========================================================

function checkformContact(form) {

	var nameval = form.name.value;
	var emailval = form.email.value;
	var phoneval = form.phone.value;
//	var companyval = form.company.value;
	var messageval = form.message.value;
	
	if (!nameval || !emailval || !phoneval || !messageval) {
		alert("Please fill in all fields.");
		return false;
	}
	
	if (emailval.indexOf('@')<1 || emailval.indexOf('.')<1) {
		alert("Please enter a valid email address.");
		return false;
	}
}

//==========================================================
//	BEGIN FUNCTION FOR NEWSLETTER - MAILING LIST 
//==========================================================
		
function checkEmailStr(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var error_message = 'Your email address in invalid.';
	
	if (str.indexOf(at)==-1){
	   alert(error_message);
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert(error_message);
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert(error_message);
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert(error_message);
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert(error_message);
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert(error_message);
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert(error_message);
		return false;
	 }

	 return true;			
}

function validateEmail(form, email_input_name){

	var emailID=form[email_input_name];
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address");
		emailID.focus();
		return false;
	}

	if (checkEmailStr(emailID.value)==false){
		emailID.focus();
		return false;
	}
	return true;
 }
 

//----------------------------------------------------------------------------------------------------------------
//	VIDEO CODE
//----------------------------------------------------------------------------------------------------------------

function getVideo(video_file_name, video_width, video_height) {
	var url_str = "play_video_popup.php?file=" + video_file_name + "&width=" + video_width + "&height=" + video_height;
	var window_width = video_width + 100;
	var window_height = video_height + 150;
	var window_size_param = "WIDTH=" + window_width + ",HEIGHT=" + window_height;
	window.open(url_str, "video_window", window_size_param);
}



