
//////////////////////////////// EMAIL VALIDATION ////////////////////////////////////
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("Email address in not valid")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email address in not valid")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Email address in not valid")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Email address in not valid")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Email address in not valid")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Email address in not valid")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Email address in not valid")
		    return false
		 }

 		 return true					
	}
	
//////////////////////////////////////////// END OF EMAIL VALIDATION //////////////////////




//////////////////////////////////////////// PHONE NUMBER VALIDATION //////////////////////

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//////////////////////////////////////////// END OF PHONE NUMBER VALIDATION ///////////////

function checkForm()
{
	var cname, cemail, cmessage;
	with(window.document.msgform)
	{
		cname    = disc_name;
		cemail   = disc_email;
		cmessage 	= disc_require;
		
	}
	
	var messagelength = cmessage.length;
	
	if(trim(cname.value) == '')
	{
		alert('Please enter your name');
		cname.focus();
		return false;
	}
	else if(trim(cemail.value) == '')
	{
		alert('Please enter your email address');
		cemail.focus();
		return false;
	}
	else if (echeck(cemail.value)==false){
		cemail.focus();
		return false;
	}
	
	else if(trim(cmessage.value) == '')
	{
		alert("Please let us know your requirements");
		cmessage.focus();
		return false;
	}
	
	else
	{
		cname.value    = trim(cname.value);
		cemail.value   = trim(cemail.value);
		cmessage.value = trim(cmessage.value);
		return true;
	}
}

///////////////////////////////////////////////////////////////////////////////////

function checkForm2()
{
	var cname2, cemail2, cmessage2;
	with(window.document.msgform2)
	{
		cname2    = disc_name2;
		cemail2   = disc_email2;
		cmessage2 	= disc_require2;
		
	}
	
	var messagelength = cmessage2.length;
	
	if(trim(cname2.value) == '')
	{
		alert('Please enter your name');
		cname2.focus();
		return false;
	}
	else if(trim(cemail2.value) == '')
	{
		alert('Please enter your email address');
		cemail2.focus();
		return false;
	}
	else if (echeck(cemail2.value)==false){
		cemail2.focus();
		return false;
	}
	
	else if(trim(cmessage2.value) == '')
	{
		alert("Please let us know your requirements");
		cmessage2.focus();
		return false;
	}
	
	else
	{
		cname2.value    = trim(cname2.value);
		cemail2.value   = trim(cemail2.value);
		cmessage2.value = trim(cmessage2.value);
		return true;
	}
}

/////////////////////////////////////////////////////////////////////////////////////

function checkForm3()
{
	var cname3, cemail3, ctelephone3, cmessage3;
	with(window.document.msgform3)
	{
		cname3    = name;
		cemail3   = email;
		ctelephone3 = phone;
		cmessage3 	= message;
		
	}
	
	var messagelength = cmessage3.length;
	
	if(trim(cname3.value) == '')
	{
		alert('Please enter your name');
		cname3.focus();
		return false;
	}
	else if(trim(cname3.value) == 'Name')
	{
		alert('Please enter your name');
		cname3.focus();
		return false;
	}
	else if(trim(cemail3.value) == '')
	{
		alert('Please enter your email address');
		cemail3.focus();
		return false;
	}
	else if(trim(cemail3.value) == 'Email')
	{
		alert('Please enter your email address');
		cemail3.focus();
		return false;
	}
	else if (echeck(cemail3.value)==false){
		cemail3.focus();
		return false;
	}
	else if(trim(ctelephone3.value) == '')
	{
		alert('Please enter your phone number');
		ctelephone3.focus();
		return false;
	}
	else if(trim(ctelephone3.value) == 'Phone')
	{
		alert('Please enter your phone number');
		ctelephone3.focus();
		return false;
	}
	else if (checkInternationalPhone(ctelephone3.value)==false){
		alert("Phone number is not valid")
		ctelephone3.focus();
		return false;
	}
	else if(trim(cmessage3.value) == '')
	{
		alert("Please enter a message");
		cmessage3.focus();
		return false;
	}
	else if(trim(cmessage3.value) == 'Message')
	{
		alert("Please enter a message");
		cmessage3.focus();
		return false;
	}
	
	else
	{
		cname3.value    = trim(cname3.value);
		cemail3.value   = trim(cemail3.value);
		ctelephone3.value = trim(ctelephone3.value);
		cmessage3.value = trim(cmessage3.value);
		return true;
	}
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

////////////////////////////////////////// POPUP ////////////////////////////////////////

function ShowPopup(hoveritem)
{
hp = document.getElementById("hoverpopup");

// Set position of hover-over popup
hp.style.top = hoveritem.offsetTop + 18;
hp.style.left = hoveritem.offsetLeft + 20;

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup()
{
hp = document.getElementById("hoverpopup");
hp.style.visibility = "Hidden";
}
