//Change color of menu item
function change_color(d) {
	 document.getElementById(d).style.background = "#5A8EC6";
}

//Menu Jan
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id){	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose(){
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime(){
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

//Validations Newsletter 
function isValidEmail(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		var AtPos = str.indexOf("@")
	    var StopPos = str.lastIndexOf(".")
		
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail");
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail");
		    return false;
		 }
		 if (AtPos == -1 || StopPos == -1) {
			return false
		 }
		 if (StopPos < AtPos) {
			return false
		 }
		 if (StopPos - AtPos == 1) {
			return false
		 } 
		 if(StopPos == lstr - 1){ //ana.oh@gmail.
			return false
		 }
 		 return true;
}
function ValidateSubscribeForm(form){			
	if ((form.email.value==null)||(form.email.value=="")){
		alert("Please Enter your Email")
		form.email.focus()
		return false
	}

	if( isValidEmail(form.email.value) == false) {
		alert('The email address you entered is not valid');
		form.email.focus(); 
		return false; 
	}
	return true; 
} 

//Validate contact form
function validate_contact(){
	if(document.getElementById('name').value==""){
		alert('Please complete your name');document.form2.name.focus();
	}else if(isValidEmail(document.getElementById('email').value)==false){
		alert("Please enter/check your Email"); document.form2.email.focus();
	}else if(document.getElementById('message').value==""){
		alert('Please complete your enquiry');document.form2.message.focus();
	}else {
		document.form2.submit();
	}
}