// JavaScript Document
function updateCSS(f, node){
	document.getElementsByTagName('link')[node].setAttribute('href', f);
}
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}
function popUp(URL, w, h) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=" + w  + ",height=" + h + "');");
}
function valMailList() {
    var failed = false;
    var message = "You must enter the following before the form can be processed \n\n";
    if (document.form1.foEmail.value == "") {
        if (!failed){ firstfocus = document.form1.foEmail;}
        failed = true;
        message += "Valid Email Address \n";
    }
   // stick some form field validation in here
    if (failed){
        alert(message);
        firstfocus.focus();
        return false;
    }    
    return true;
}  

function popUp(URL, w, h) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width='" + w  + "',height='" + h + "'');");
}


function Validate() {
    var failed = false;
    var message = "You must enter the following before the form can be processed \n\n";
    if (document.getElementById('name').value == "") {
        if (!failed){ firstfocus = document.getElementById('name');}
        failed = true;
        message += "Name \n";
    }
	if (document.getElementById('email').value == "") {
        if (!failed){ firstfocus = document.getElementById('email');}
        failed = true;
        message += "Email \n";
    }
	if (echeck(document.getElementById('email').value)==false){
		firstfocus = document.getElementById('email');
		message += "Valid Email Address \n";
		failed = true;
	}
    if (document.getElementById('details').value == "") {
        if (!failed){ firstfocus = document.getElementById('details');}
        failed = true;
        message += "Details of your Enquiry \n";
    }
   // stick some form field validation in here
    if (failed){
        alert(message);
        firstfocus.focus();
        return false;
    }    
    return true;
} 


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 valid email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter valid email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Please enter valid email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Please enter valid email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Please enter valid email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Please enter valid email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Please enter valid email")
		    return false
		 }

 		 return true					
	}

/*
function valEmail() {
	if (document.advSearch.eUpdate.checked == true){
    var failed = false;
    var message = "You must enter the following before the form can be processed \n\n";
    if (document.advSearch.uFname.value == "") {
        if (!failed){ firstfocus = document.advSearch.uFname;}
        failed = true;
        message += "Firstname\n";
    }
    if (document.advSearch.uSname.value == "") {
        if (!failed){ firstfocus = document.advSearch.uSname;}
        failed = true;
        message += "Surname \n";
    }
	if (document.advSearch.uEmail.value == "") {
        if (!failed){ firstfocus = document.advSearch.uEmail;}
        failed = true;
        message += "Valid Email Address \n";
    }
	if (echeck(document.forum.uEmail.value)==false){
		document.forum.uEmail.value =""
		document.forum.uEmail.focus()
		return false
	}
	if (document.advSearch.ppolicy.checked == false){
		if (!falied){ firstfocus = document.advSearch.ppolicy;}
		failed = true;
		message += "You must agree with the privacy policy \n";
	}
   // stick some form field validation in here
    if (failed){
        alert(message);
        firstfocus.focus();
        return false;
    } return true;
}
    } */

function setOpacity (namein, step) 
{
	fadinthis = document.getElementById(namein);
	if (document.all) {fadinthis.style.filter = 'alpha(opacity = ' + step + ')';}
	if (step < 100){
			step = step+step;
			setTimeout('setOpacity("' + namein + '",' + step + ')', 50);
	}
}

function fadeInOut(idsin, idsout) 
{
	var splitOuts = idsout.split("-");
	for(i = 0; i < splitOuts.length; i++){
		if(document.getElementById(splitOuts[i])){ 
			document.getElementById(splitOuts[i]).style.filter = 'alpha(opacity = ' + 0 + ')';
			document.getElementById(splitOuts[i]).style.display = "none";
		}
	}
	var splitIns = idsin.split("-");
	for(i = 0; i < splitIns.length; i++){
		if(document.getElementById(splitIns[i])){
			document.getElementById(splitIns[i]).style.display = "block";
			setOpacity (splitIns[i], 5);
		}
	}
}
