// 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 poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
function popproduct(url)
{
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height=600,width=750,left=150,top=70');
	if (window.focus) {newwindow.focus()}
}

function popservices(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}
function showsubcat(catid){
	window.location.href = "index.php?catname="+catid;
}
function changetype()
{
var catname=document.frm_job.catid.value;
	if (catname=="All")
		{
			window.location.href="searchjobs.php";
		}
	else
		{
			window.location.href="searchjobs.php?type="+document.frm_job.catid.value;
		}
}
function changejobdetails()
{
var catname=document.frm_job.catid.value;
	if (catname=="All")
		{
			window.location.href="searchjobs.php";
		}
	else
		{
			window.location.href="searchjobs.php?type="+document.frm_job.catid.value;
		}
}

//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);
}

//script validation for date 
function date_valid(dateissue,dateissue2){
	var stdate=dateissue.split("/");
	var enddate=dateissue2.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}




//Move the Settings
function move(index,to) {
		var list = document.form.list;
		var total = list.options.length-1;
		if (index == -1) return false;
		if (to == +1 && index == total) return false;
		if (to == -1 && index == 0) return false;
		var items = new Array;
		var values = new Array;
		for (i = total; i >= 0; i--) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
		}
		for (i = total; i >= 0; i--) {
		if (index == i) {
		list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
		list.options[i] = new Option(items[i + to], values[i]);
		i--;
		}
		else {
		list.options[i] = new Option(items[i], values[i]);
		   }
		}
		list.focus();
}



function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length < 1 || month < 1 || month > 12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length < 1 || day < 1 || day > 31 || (month==2 && day > daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year < minYear || year > maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
} 
	function pay_search()
	{
	var payname=document.payform.paystatus.value;
	var dof="member";
		if (payname=="All")
			{
				window.location.href="index.php?do=member&task=view_member";
			}
		else
			{
				window.location.href="index.php?paystatus="+document.payform.paystatus.value+"&do=member&task=view_member";
			}
	}
	
function sendnewsletter_validation(){
		if(document.snewsletter.newstitle.value == "")
		{
		   alert("Please enter the Newsletter Title");
		   document.snewsletter.newstitle.focus();
		   return false;
		}
		if(document.snewsletter.member.value == "")
		{
		   alert("Please choose the category");
		   document.snewsletter.member.focus();
		   return false;
		}
		/*if(document.snewsletter.editor11.value == "")
		{
		   alert("Please enter the description");
		   document.snewsletter.editor11.focus();
		   return false;
		}*/
}
	
	
function editor_validation(){
		if(document.msgeditor.fromname.value == "")
		{
		   alert("Please enter the From Name");
		   document.msgeditor.fromname.focus();
		   return false;
		}
		if(document.msgeditor.fromemail.value == "")
		{
		   alert("Please enter the From Email");
		   document.msgeditor.fromemail.focus();
		   return false;
		}
		if (!validateEmail(document.msgeditor.fromemail.value,1,1)) 
		{
			document.msgeditor.fromemail.focus();
			return false;
		}
		/*if(document.msgeditor.editor1.value == "")
		{
		   alert("Please enter the Welcome Message");
		   document.msgeditor.editor1.focus();
		   return false;
		}*/
		if(document.msgeditor.thanksmsg.value == "")
		{
		   alert("Please enter the Thanks Message");
		   document.msgeditor.thanksmsg.focus();
		   return false;
		}
}
function newsletter_validation(){
		if(document.newsletter.fromname.value == "")
		{
		   alert("Please enter the From Name");
		   document.newsletter.fromname.focus();
		   return false;
		}
		if(document.newsletter.frommail.value == "")
		{
		   alert("Please enter the From Email");
		   document.newsletter.frommail.focus();
		   return false;
		}
		if (!validateEmail(document.newsletter.frommail.value,1,1)) 
		{
			document.newsletter.frommail.focus();
			return false;
		}
}
	
function category_validate(){
		if(document.frm_procategory.txt_catname.value == "")
		{
		   alert("Please enter the Category name");
		   document.frm_procategory.txt_catname.focus();
		   return false;
		}
}
//Validation for subcategory
function subcategory_validate(){
		if(document.form_subcategory.catid.value == "")
		{
		   alert("Please Choose the Category name");
		   document.form_subcategory.catid.focus();
		   return false;
		}
		if(document.form_subcategory.txt_subcatname.value == "")
		{
		   alert("Please Enter the SubCategory name");
		   document.form_subcategory.txt_subcatname.focus();
		   return false;
		}
}

//Validation for product

function product_validate(){
		if(document.frm_product.txt_catname.value == "")
		{
		   alert("Please Choose the Category name");
		   document.frm_product.txt_catname.focus();
		   return false;
		}
	if(document.frm_product.txt_subcatname.value == "")
		{
		   alert("Please Choose the SubCategory name");
		   document.frm_product.txt_subcatname.focus();
		   return false;
		}
	if(document.frm_product.txt_proname.value == "")
		{
		   alert("Please Enter the Product name");
		   document.frm_product.txt_proname.focus();
		   return false;
		}
	if(document.frm_product.txt_procode.value == "")
		{
		   alert("Please Enter the Product code");
		   document.frm_product.txt_procode.focus();
		   return false;
		}
	if(document.frm_product.txt_rprice.value == "")
		{
		   alert("Please Enter the Regular price");
		   document.frm_product.txt_rprice.focus();
		   return false;
		}
	if(document.frm_product.txt_saleprice.value == "")
		{
		   alert("Please Enter the Sale price");
		   document.frm_product.txt_saleprice.focus();
		   return false;
		}
	/*if(document.frm_product.txt_shippingcost.value == "")
		{
		   alert("Please Enter the Shipping cost");
		   document.frm_product.txt_shippingcost.focus();
		   return false;
		}
	if(document.frm_product.txt_weight.value == "")
		{
		   alert("Please Enter the Product weight");
		   document.frm_product.txt_weight.focus();
		   return false;
		}
	if(document.frm_product.txt_stock.value == "")
		{
		   alert("Please Enter the Product Stock");
		   document.frm_product.txt_stock.focus();
		   return false;
		}*/
	/*if(document.frm_product.txt_tax.value == "")
		{
		   alert("Please Enter the Tax");
		   document.frm_product.txt_tax.focus();
		   return false;
		}*/

}
function register_validate(){
		if(document.frm_register.txtUser.value == "")
		{
		   alert("Please Enter the User name");
		   document.frm_register.txtUser.focus();
		   return false;
		}
		if(document.frm_register.txtPassword.value == "")
		{
		   alert("Please Enter the Password");
		   document.frm_register.txtPassword.focus();
		   return false;
		}
		if(document.frm_register.txtConfirmPassword.value == "")
		{
		   alert("Please Enter the Confirm Password");
		   document.frm_register.txtConfirmPassword.focus();
		   return false;
		}
		if(document.frm_register.txtFirst.value == "")
		{
		   alert("Please Enter the First name");
		   document.frm_register.txtFirst.focus();
		   return false;
		}
		if(document.frm_register.txtLast.value == "")
		{
		   alert("Please Enter the Last name");
		   document.frm_register.txtLast.focus();
		   return false;
		}
		if (!validateEmail(document.frm_register.txtEmail.value,1,1)) 
		{
			document.frm_register.txtEmail.focus();
			return false;
		}
		if(document.frm_register.txtPostAdd1.value == "")
		{
		   alert("Please Enter the AddressLine");
		   document.frm_register.txtPostAdd1.focus();
		   return false;
		}
		if(document.frm_register.txtPostCity.value == "")
		{
		   alert("Please Enter the City");
		   document.frm_register.txtPostCity.focus();
		   return false;
		}
		if(document.frm_register.txtPostState.value == "")
		{
		   alert("Please choose the state");
		   document.frm_register.txtPostState.focus();
		   return false;
		}
		if(document.frm_register.txtPostZip.value == "")
		{
		   alert("Please Enter the Zipcode");
		   document.frm_register.txtPostZip.focus();
		   return false;
		}
		if(document.frm_register.txtPostCountry.value == "")
		{
		   alert("Please choose the Country");
		   document.frm_register.txtPostCountry.focus();
		   return false;
		}
	if(document.frm_register.txtBusinessph.value == "")
		{
		   alert("Please Enter the Phone");
		   document.frm_register.txtBusinessph.focus();
		   return false;
		}
		phone = document.frm_register.txtBusinessph;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
}

function login_validate(){
if(document.Login.txtUsername.value == "")
	{
	   alert("Please Enter the Username");
	   document.Login.txtUsername.focus();
	   return false;
	}
if(document.Login.txtPassword.value == "")
	{
	   alert("Please Enter the Password");
	   document.Login.txtPassword.focus();
	   return false;
	}
}

//News  Validation
function news_validate(){
	if (document.frm_news.Question.value == "") 
		{
				alert ("Please Enter the title.");
				document.frm_news.Question.focus();
				return false;
		}
	if (document.frm_news.shortdesc.value == "") 
		{
				alert ("Please Enter the Short Description.");
				document.frm_news.shortdesc.focus();
				return false;
		}
}

function date_valid(dateissue,dateissue2){
	var stdate=dateissue.split("/");
	var enddate=dateissue2.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
} 

//Script to display the subcategory with the category
var lists = new Array();
var deliverytype = new Array();

function emptyList( box ) 
{
	while ( box.options.length ) box.options[0] = null;
}

function fillList( box, arr ) 
{
	for ( i = 0; i < arr[0].length; i++ ) 
	{
		option = new Option( arr[0][i], arr[0][i+1] );
		box.options[box.length] = option;
		i=i+1;
	}
	box.selectedIndex=0;
}
function changeList(box) 
{
	list = lists[box.options[box.selectedIndex].value];
	DeliveryTp = deliverytype[box.options[box.selectedIndex].value];
	
	if(box.options[box.selectedIndex].value != "select" && box.options[box.selectedIndex].value != "Choose")
	{
		emptyList(box.form.Subcategory);
		fillList(box.form.Subcategory, list);
	}
}

function openwindow(){
	document.viewcart.action="deletecart.php";
	document.viewcart.submit();
}
function openw(){
	window.location.href = "index.php";
}
function openwi(){
	window.location.href = "checkout.php";
}
function opencart(){
document.viewcart.action="modifycart.php";
document.viewcart.submit();
}

function showdeli(){
		if (!(document.checkout.chkDelivery.checked)){
		delistyle=document.getElementById("delivery");
		    if(delistyle){
			delistyle.style.display="block";
			delistyle.style.visibility="visible";
			}				
		}
		else
		{
			delistyle=document.getElementById("delivery");
			if(delistyle){
			delistyle.style.display="none";
			delistyle.style.visibility="hidden";
			}
		}
	}


function forgetpassword_validate(){
	if(!validateEmail(document.frm_pass.email.value,1,1)) 
	{
		document.frm_pass.email.focus();
		return false;
	}
}

function checkout_validate(){
	if(document.frm_checkout.name.value == ""){
		alert("Please Enter the Name");
		document.frm_checkout.name.focus();
		return false;
	}
	if(!validateEmail(document.frm_checkout.email.value,1,1)) 
	{
		document.frm_checkout.email.focus();
		return false;
	}
	if(document.frm_checkout.addr1.value == ""){
		alert("Please Enter the Address1");
		document.frm_checkout.addr1.focus();
		return false;
	}
	if(document.frm_checkout.city.value == ""){
		alert("Please Enter the City");
		document.frm_checkout.city.focus();
		return false;
	}
	if(document.frm_checkout.county.value == ""){
		alert("Please Enter the County");
		document.frm_checkout.county.focus();
		return false;
	}
	if(document.frm_checkout.country.value == ""){
		alert("Please Select the Coutry");
		document.frm_checkout.country.focus();
		return false;
	}
	if(document.frm_checkout.zipcode.value == ""){
		alert("Please Enter the zipcode");
		document.frm_checkout.zipcode.focus();
		return false;
	}
	if(document.frm_checkout.phone.value == "")
	{
	   alert("Please Enter the Phone");
	   document.frm_checkout.phone.focus();
	   return false;
	}
	phone = document.frm_checkout.phone;
	if (checkInternationalPhone(phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		phone.value=""
		phone.focus()
		return false
		}
	if(!(document.frm_checkout.chkDelivery.checked))
	{
		if(document.frm_checkout.deliaddr1.value == ""){
			alert("Please Enter the Delivery Address1");
			document.frm_checkout.deliaddr1.focus();
			return false;
		}
		if(document.frm_checkout.delicity.value == ""){
			alert("Please Enter the Delivery City");
			document.frm_checkout.delicity.focus();
			return false;
		}
		if(document.frm_checkout.delicounty.value == ""){
			alert("Please Enter the Delivery County");
			document.frm_checkout.delicounty.focus();
			return false;
		}
		if(document.frm_checkout.delicountry.value == ""){
			alert("Please Select the Delivery Coutry");
			document.frm_checkout.delicountry.focus();
			return false;
		}
		if(document.frm_checkout.delizipcode.value == ""){
			alert("Please Enter the Delivery zipcode");
			document.frm_checkout.delizipcode.focus();
			return false;
		}
		if(document.frm_checkout.deliphone.value == "")
		{
		   alert("Please Enter the Delivery Phone");
		   document.frm_checkout.deliphone.focus();
		   return false;
		}
		phone = document.frm_checkout.deliphone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
	}
	if(document.frm_checkout.Cardname.value == "")
	{
	   alert("Please Select the Credit Card Name");
	   document.frm_checkout.Cardname.focus();
	   return false;
	}
	if(document.frm_checkout.CardexpM.value == "")
	{
	   alert("Please Select the Credit Card Expire Month");
	   document.frm_checkout.CardexpM.focus();
	   return false;
	}
	if(document.frm_checkout.CardexpY.value == "")
	{
	   alert("Please Select the Credit Card Expire Year");
	   document.frm_checkout.CardexpY.focus();
	   return false;
	}
	if(document.frm_checkout.Nameoncard.value == "")
	{
	   alert("Please Enter the Name on Card");
	   document.frm_checkout.Nameoncard.focus();
	   return false;
	}
	if(document.frm_checkout.cardnumber.value == "")
	{
	   alert("Please Enter the Credit Card Number");
	   document.frm_checkout.cardnumber.focus();
	   return false;
	}
	if(isNaN(document.frm_checkout.cardnumber.value)){
		alert("Please Enter the Valid Credit Card Number");
		document.frm_checkout.cardnumber.focus();
		return false;
	}
	if(document.frm_checkout.cvv2.value == "")
	{
	   alert("Please Enter the CVV2 Number");
	   document.frm_checkout.cvv2.focus();
	   return false;
	}
	if(isNaN(document.frm_checkout.cvv2.value)){
		alert("Please Enter the Valid CVV2 Number");
		document.frm_checkout.cvv2.focus();
		return false;
	}
}

function prodsearch_validate(){
	if(document.frm_prosearch.keyword.value == ""){
		alert("Please Enter the Search Keyword");
		document.frm_prosearch.keyword.focus();
		return false;
	}
}