function checksilbox(silid) {
	if(document.getElementById('silbox'+silid).checked == true) document.getElementById('siltds'+silid).style.display = '';
	else document.getElementById('siltds'+silid).style.display = 'none';
}

function checkchainbox(chainid) {
	if(document.getElementById('chainbox'+chainid).checked == true) document.getElementById('chaintds'+chainid).style.display = '';
	else document.getElementById('chaintds'+chainid).style.display = 'none';
}

/*function checkvalue() {
	var siln = parseInt(document.addaccessory.SilIdNos.value);
	var sils = document.addaccessory.SilIds.value;
	var chnn = parseInt(document.addaccessory.ChainNos.value);
	var chns = document.addaccessory.ChainIds.value;
	sils = sils.split("|");
	chns = chns.split("|");
	for(i=0; i<siln; i++) {
		if(document.getElementById('silbox'+sils[i]).checked == true) {
			if(document.getElementById('silnos'+sils[i]) == '')  {
				alert('Enter No. of Silencers required');
				document.getElementById('silnos'+sils[i]).focus();
				return false;
			}
		}
	}
	for(i=0; i<chnn; i++) {
	}
	
}*/

function pre_slide() {
	var NS = (navigator.appName=="Netscape")?true:false;
	 iWidth = (NS)?window.innerWidth:document.body.clientWidth;
	 new_width = (iWidth - 300)/2;
	 NewWindow=window.open("design.html", "design","menubar=0, width=300, height=500, left = "+new_width+", top = 120");
	 NewWindow.focus();
}

function checktag(rows) {
	var radio_choice = false;
	for (counter = 0; counter < rows; counter++) {
		if(document.tagselects.newtags[counter].checked) radio_choice = true;
	}
	if(radio_choice == true) return true; 
	else { alert('Please select a tag here'); return false; }
}

function cktag2(){
	if(document.getElementById('tags2').checked == true) document.getElementById('tag2').style.display = 'none';
	else document.getElementById('tag2').style.display = '';
}

function quoteform() {
	if(!validName(document.contactform.fname.value)) {
		document.contactform.fname.focus();
		alert('Please enter a valid Name');
		return false;
	}
	if(!validEmail(document.contactform.email.value)) {
		document.contactform.email.focus();
		alert('Please enter a valid Email');
		return false;
	}
	if(document.contactform.phone.value != '')
		if(!validPhone(document.contactform.phone.value)) {
			document.contactform.phone.focus();
			alert('Please enter a valid Phone Number');
			return false;
		}
	if(document.contactform.quote.value == '') {
		document.contactform.quote.focus();
		alert('Please enter your Quote');
		return false;
	}
}

function validate() {
	if(!validName(document.customerinfo.c_fname.value)) {
		document.customerinfo.c_fname.focus();
		alert('Please enter a valid First Name');
		return false;
	}

	if(!validName(document.customerinfo.c_lname.value)) {
		document.customerinfo.c_lname.focus();
		alert('Please enter a valid Last Name');
		return false;
	}

	if(!validEmail(document.customerinfo.c_email.value)) {
		document.customerinfo.c_email.focus();
		alert('Please enter a valid Email');
		return false;
	}

	/*if(!validPassword(document.customerinfo.c_pass.value)) {
		document.customerinfo.c_pass.focus();
		alert('Invalid Password.\n\nPassword should contain atleast 6 characters.\n\nItaccepts AlphaNumeric characters');
		return false;
	}

	if((document.customerinfo.c_pass.value != '') && (document.customerinfo.c_pass2.value != '') && (document.customerinfo.c_pass.value != document.customerinfo.c_pass2.value)) {
		document.customerinfo.c_pass2.focus();
		alert('Your Password did not match.\n\nPlease check.');
		return false;
	}

	if(!validPassword(document.customerinfo.c_pass2.value)) {
		document.customerinfo.c_pass2.focus();
		alert('Invalid Password.\n\nPassword should contain atleast 6 characters.\n\nItaccepts AlphaNumeric characters');
		return false;
	}*/

	if(document.customerinfo.c_b_addr1.value == '') {
		document.customerinfo.c_b_addr1.focus();
		alert('Please enter your Address.');
		return false;
	}

	if(document.customerinfo.c_b_city.value == '') {
		document.customerinfo.c_b_city.focus();
		alert('Please enter your City.');
		return false;
	}

	if(document.customerinfo.c_b_country.value != 'US') {
		if(document.customerinfo.c_b_state1.value == '') {
			document.customerinfo.c_b_state1.focus();
			alert('Please enter a State');
			return false;
		}
	} else {
		if(!validZip(document.customerinfo.c_b_zip.value)) {
			document.customerinfo.c_b_zip.focus();
			alert('Please enter a valid Zip Code');
			return false;
		}
	}

	if(document.customerinfo.c_same[1].checked) {  
		if(document.customerinfo.c_s_addr1.value == '') {
			document.customerinfo.c_s_addr1.focus();
			alert('Please enter your Address.');
			return false;
		}

		if(document.customerinfo.c_s_city.value == '') {
			document.customerinfo.c_s_city.focus();
			alert('Please enter your City.');
			return false;
		}

		if(document.customerinfo.c_s_country.value != 'US') {
			if(document.customerinfo.c_s_state1.value == '') {
				document.customerinfo.c_s_state1.focus();
				alert('Please enter a State');
				return false;
			}
		} else {
			if(!validZip(document.customerinfo.c_s_zip.value)) {
				document.customerinfo.c_s_zip.focus();
				alert('Please enter a valid Zip Code.');
				return false;
			}
		}
	}
}
function validPhone( strValue ) {
	var objRegExp  = /^((\(\d{3}\))|(\d{3}))\s?(\.|\-|\s)?\d{3}(\.|\-|\s)\d{4}$/;
	return objRegExp.test(strValue);
}
function validName( strValue ) {
	strValue = trim(strValue, '');
	strMatchPattern = /^[a-zA-Z\'\s]+$/;
	var objRegExp = new RegExp( strMatchPattern);
	return objRegExp.test(strValue);
}

function validEmail( strValue) {
var objRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i 
  return objRegExp.test(strValue);
}

function validPassword( strValue) {
var objRegExp = /^[A-Za-z0-9]\w{4,}[A-Za-z0-9]$/i
  return objRegExp.test(strValue);
}

function validZip( strValue) {
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
  return objRegExp.test(strValue);
}

/***** TRIMMING *****/
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
/***** TRIMMING *****/

/******* ADMIN VALIDATION *******/
function paypalid() {
	if(!validEmail(document.paypalform.paypalmail.value)) {
		document.paypalform.paypalmail.focus();
		alert('Invalid Email');
		return false;
	}
}

function adminemail() {
	if(!validEmail(document.adminform.newemail.value)) {
		document.adminform.newemail.focus();
		alert('Invalid Email');
		return false;
	}
}

function adminpass() {
	if(!validPassword(document.adminform.oldpass.value)) {
		document.adminform.oldpass.focus();
		alert('Invalid old Password');
		return false;
	}
	if(!validPassword(document.adminform.newpass.value)) {
		document.adminform.newpass.focus();
		alert('Invalid new Password');
		return false;
	}
	if(document.adminform.newpass.value != document.adminform.newpass2.value) {
		document.adminform.newpass.focus();
		alert('Passwords did not match');
		return false;
	}
}
function ckfile(fld) {
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(fld.value)) {
		alert("Invalid image file type.");
		fld.value='';
		fld.focus();
		return false;
	}
	return true;
}

function tagcheck() {
	if(document.adminform.tagname.value == '') {
		document.adminform.tagname.focus();
		alert('Enter Tag Name');
		return false;
	}
	if(document.adminform.tagprice.value == '') {
		document.adminform.tagprice.focus();
		alert('Enter Tag Price');
		return false;
	}
	if(document.adminform.tagimage.value == '') {
		document.adminform.tagimage.focus();
		alert('Browse Tag Image');
		return false;
	}

}
/******* ADMIN VALIDATION *******/


function upQuest(val, val2) {
	location="orders_view.php?show="+val2+"&pgn="+val;
}