// JavaScript Document
startList = function() {
	//code only for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}
window.onload=startList;

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}



//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

//Function phone validation Script
// 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 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){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function SubclearName()
{
	if(document.frm_subscribe.subsc_name.value == "your name here")
	{
		document.frm_subscribe.subsc_name.value = "";
	}
}

function SubclearEmail()
{
	if(document.frm_subscribe.email_id.value == "enter your email address")
	{
		document.frm_subscribe.email_id.value = "";
	}
}

function pop_order(url)
{
	var width = 500;
	var height = 400; 
	var left = screen.width/2 - (width/2);
	var top = 100;
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height='+height+',width='+width+',left='+left+',top='+top+'');
	if (window.focus) {newwindow.focus()}
}

function subscribe_validate()
{
	if(document.frm_subscribe.subsc_name.value == "")
	{
		alert("Please Enter the Name");
		document.frm_subscribe.subsc_name.focus();
		return false;
	}
	if (!validateEmail(document.frm_subscribe.email_id.value,1,1)) 
	{
		document.frm_subscribe.email_id.focus();
		return false;
	}
	document.frm_subscribe.action="newsletter.php?task=sub";
	document.frm_subscribe.submit();
}

function checkSubs(e){
var characterCode
	 if(e && e.which){
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
 	 subscribe_validate();
 	 return false
	 }
return true
}

function mail_unsubscribe()
{
	if (!validateEmail(document.frm_subscribe.email_id.value,1,1)) 
	{
		document.frm_subscribe.email_id.focus();
		return false;
	}
	document.frm_subscribe.action="newsletter.php?task=unsub";
	document.frm_subscribe.submit();
}

function checkEnter(e){
var characterCode
	 if(e && e.which){
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
 	 mail_unsubscribe();
 	 return false
	 }
return true
}

function clearEmail()
{
	if(document.frm_subscribe.email_id.value == "Enter your Email Address to Unsubscribe")
	{
		document.frm_subscribe.email_id.value = "";
	}
}


function contact_submit()
{
	if(document.frm_contact.name.value == "")
	{
		alert("Please Enter the Name");
		document.frm_contact.name.focus();
		return false;
	}
	phone = document.frm_contact.phone;
	if (checkInternationalPhone(phone.value)==false)
	{
		alert("Please Enter a Valid Phone Number")
		phone.value=""
		phone.focus()
		return false
	}
	if (!validateEmail(document.frm_contact.cont_email.value,1,1)) 
	{
		document.frm_contact.cont_email.focus();
		return false;
	}
	if(document.frm_contact.message.value == "")
	{
		alert("Please Enter the Message");
		document.frm_contact.message.focus();
		return false;
	}
	document.frm_contact.action="contact.php";
	document.frm_contact.submit();
}

function contact_reset()
{
	document.frm_contact.name.value = "";
	document.frm_contact.phone.value = "";
	document.frm_contact.cont_email.value = "";
	document.frm_contact.message.value = "";
}

function clearContEmail()
{
	if(document.frm_contact.cont_email.value == "email address")
	{
		document.frm_contact.cont_email.value = "";
	}
}

function clearContName()
{
	if(document.frm_contact.name.value == "your name here")
	{
		document.frm_contact.name.value = "";
	}
}

function clearContPhone()
{
	if(document.frm_contact.phone.value == "telephone")
	{
		document.frm_contact.phone.value = "";
	}
}

function clearContMsg()
{
	if(document.frm_contact.message.value == "message")
	{
		document.frm_contact.message.value = "";
	}
}

function checkContact(e){
var characterCode
	 if(e && e.which){
	 e = e
	 characterCode = e.which
	 }
	 else{
	 e = event
	 characterCode = e.keyCode
	 }	 
	 if(characterCode == 13){
 	 contact_submit();
 	 return false
	 }
return true
}
