////// AJAX ///////
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			xmlhttp.overrideMimeType('text/html');
		}
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

//function myFirstFunction(){
//	xmlhttp.open("GET","/common/ajaxForCenter.php");
//	//Send the proper header information along with the request
//	/*xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//	xmlhttp.setRequestHeader("Content-length", str.length);
//	xmlhttp.setRequestHeader("Connection", "close");*/
//	xmlhttp.onreadystatechange=function() {
//		if(xmlhttp.readyState==4) {
//			if(xmlhttp.status ==200){
//				response = xmlhttp.responseText;
//				var values = response;
//				document.getElementById('centerAjax').innerHTML='';
//				document.getElementById('centerAjax').innerHTML=values;
//			}
//		}
//	}
//	xmlhttp.send(null);
//	setTimeout('myFunction()',10000);
//}

function myFunction(){
	xmlhttp.open("GET","/common/ajaxForLeft.php");
	//Send the proper header information along with the request
	/*xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", str.length);
	xmlhttp.setRequestHeader("Connection", "close");*/
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status ==200){
				response = xmlhttp.responseText;
				var values = response;
				document.getElementById('leftAjax').innerHTML='';
				document.getElementById('leftAjax').innerHTML=values;
			}
		}
	}
	xmlhttp.send(null);
	setTimeout('mySecondFunction()',10000);
}

function mySecondFunction(){
	xmlhttp.open("GET","/common/ajaxForRight.php");
	//Send the proper header information along with the request
	/*xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", str.length);
	xmlhttp.setRequestHeader("Connection", "close");*/
	xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status ==200){
				response = xmlhttp.responseText;
				var values = response;
				document.getElementById('rightAjax').innerHTML='';
				document.getElementById('rightAjax').innerHTML=values;
			}
		}
	}
	xmlhttp.send(null);
	//	var pageName = "http://fnrco.ndp.net"+window.location.pathname;
	//	//alert(pageName)
	//	if(pageName == "http://fnrco.ndp.net/index.php" || pageName == "http://fnrco.ndp.net/"){
	//		setTimeout('myFirstFunction()',10000);
	//	}else{
	setTimeout('myFunction()',10000);
	//	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.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 checkSpecialPrice(spqty,newqty,id){
	var id = id;
	var spqty=parseInt(spqty);
	var newqty1=document.getElementById(newqty).value;
	var countert = getCookie('clickCounter');
	if((newqty1<spqty) && (countert != id)){
		setCookie('clickCounter',id,1);
		alert('In order to recieve the special price, you would need to order the minimum quantity');
		return true;
	}
	return true;
}

var menu_arrow = new Image(); menu_arrow.src = "/images/menu_arrow.gif";

function validateAddShipping(){
	var root=document.add_shipping;
	if(root.company.value==''||root.first_name.value==''||root.last_name.value==''||root.address.value==''||root.city.value==''||root.countries.value==''||root.postal_code.value==''||root.email.value==''||root.phone.value==''){
		alert('Please fill all the form before submitting.');
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=root.email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}

	if(root.countries.value=='38'){
		if(root.canstates.value==''){
			alert('Please specify a state.');
			return false;
		}
	}

	if(root.countries.value=='219'){
		if(root.usstates.value==''){
			alert('Please specify a state.');
			return false;
		}
	}

	return true;
}


function validateAdvacedSearch(){
	var root=document.adv_search;
	if(root.keyword.value==''&&root.rfrange.value==''&&root.rtrange.value==''&&root.pfrange.value==''&&root.ptrange.value==''){
		blinkBlink('keyword1');
		alert('Please specify your search.');
		return false;
	}
	if(root.rfrange.value==''&&root.rtrange.value!=''||root.rfrange.value!=''&&root.rtrange.value==''){
		blinkBlink('rfrange');
		blinkBlink('rtrange');
		alert('Please specify both fields for the reference.');
		return false;
	}
	if(root.pfrange.value==''&&root.ptrange.value!=''||root.pfrange.value!=''&&root.ptrange.value==''){
		blinkBlink('pfrange');
		blinkBlink('ptrange');
		alert('Please specify both fields for the price.');
		return false;
	}
	if(isNaN(root.pfrange.value)||isNaN(root.ptrange.value)){
		blinkBlink('pfrange');
		blinkBlink('ptrange');
		alert('Please enter numeric values for the price.');
		return false;
	}
	return true;
}

function validateAddressForEdit(){
	var root=document.delivery_address;

	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var address = root.address.value;
	var city = root.city.value;
	var country = root.country.value;
	var state = root.state_region.value;
	var postal_code = root.postal_code.value;
	var company = root.company.value;
	var phone = root.phone.value;
	var email = root.email.value;

	if (company == ''){
		blinkBlink('company');
		alert('Please fill the company field');
		root.company.focus();
		return false;
	}

	if (firstName == ''){
		blinkBlink('first_name');
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}

	if (lastName == ''){
		blinkBlink('last_name');
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}

	if (address == ''){
		blinkBlink('address');
		alert('Please specify your address');
		root.address.focus();
		return false;
	}

	if (city == ''){
		blinkBlink('city');
		alert('Please specify your city');
		root.city.focus();
		return false;
	}

	if (state == ''){
		blinkBlink('state_region');
		alert('Please enter your state');
		root.state_region.focus();
		return false;
	}

	if (postal_code == ''){
		blinkBlink('postal_code');
		alert('Please enter the postal code');
		root.postal_code.focus();
		return false;
	}

	if (country == ''){
		blinkBlink('country');
		alert('Please select your country');
		root.country.focus();
		return false;
	}

	if (phone == ''){
		blinkBlink('phone');
		alert('Please enter your phone number');
		root.phone.focus();
		return false;
	}

	if (email == ''){
		blinkBlink('email');
		alert('Please enter your personal email');
		root.email.focus();
		return false;
	}

	if(email!=''){
		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		flag=email.match(pattern);
		if(!flag){
			blinkBlink('email');
			alert('Please insert a valid email address.');
			root.email.focus();
			return false;
		}
	}
	return true;
}

function validatePaymentType(counter){

	for(var i=0;i<counter;i++){
		if (document.delivery_address.payment_method[i].checked==true){
			if(document.delivery_address.payment_method[i].value=='1'){
				alert('Coming soon');
				return false;
			}
		}
	}
	return true;
}

function validateSpecifyPayment(){

	var root=document.delivery_address;
	if(document.delivery_address.payment_method.checked==false){
		alert('Please specify a payment method.');
		return false;
	}
	return true;
}

function validateSpecifyShipping(){
	var root=document.delivery_address;
	if(document.delivery_address.shipping_method.checked==false){
		alert('Please specify a shipping method.');
		return false;
	}
	return true;
}
function showStates(){
	/*alert(document.delivery_address.countries.options[219].value);
	return false;*/
	if (document.delivery_address.countries.options[221].selected == true ){
		theElement = eval('document.all.usstates_div.style');
		theElement.visibility='visible';
		theElement = eval('document.all.canstates_div.style');
		theElement.visibility='hidden';
		return true;
	}
	else if(document.delivery_address.countries.options[38].selected == true){
		theElement = eval('document.all.canstates_div.style');
		theElement.visibility='visible';
		theElement = eval('document.all.usstates_div.style');
		theElement.visibility='hidden';
		return true;
	}
	else{
		theElement = eval('document.all.usstates_div.style');
		theElement.visibility='hidden';
		theElement = eval('document.all.canstates_div.style');
		theElement.visibility='hidden';
		return true;
	}
}

function showStates1(){
	//	alert(document.delivery_address.countries.options[221].text);
	//	return false;
	if (document.delivery_address.countries1.options[221].selected == true ){
		theElement = eval('document.all.usstates_div1.style');
		theElement.visibility='visible';
		theElement = eval('document.all.canstates_div1.style');
		theElement.visibility='hidden';
		return true;
	}
	else if(document.delivery_address.countries1.options[38].selected == true){
		theElement = eval('document.all.canstates_div1.style');
		theElement.visibility='visible';
		theElement = eval('document.all.usstates_div1.style');
		theElement.visibility='hidden';
		return true;
	}
	else{
		theElement = eval('document.all.usstates_div1.style');
		theElement.visibility='hidden';
		theElement = eval('document.all.canstates_div1.style');
		theElement.visibility='hidden';
		return true;
	}
}


function showStatesForAddShipping(){
	//	alert(document.delivery_address.countries.options[221].text);
	//	return false;
	if (document.add_shipping.countries.options[221].selected == true ){
		theElement = eval('document.all.usstates_div2.style');
		theElement.visibility='visible';
		theElement = eval('document.all.canstates_div2.style');
		theElement.visibility='hidden';
		return true;
	}
	else if(document.add_shipping.countries.options[38].selected == true){
		theElement = eval('document.all.canstates_div2.style');
		theElement.visibility='visible';
		theElement = eval('document.all.usstates_div2.style');
		theElement.visibility='hidden';
		return true;
	}
	else{
		theElement = eval('document.all.usstates_div2.style');
		theElement.visibility='hidden';
		theElement = eval('document.all.canstates_div2.style');
		theElement.visibility='hidden';
		return true;
	}
}


function validateSpecifyAddress(c){
	var root=document.delivery_address;
	var len=document.delivery_address.length;
	var count = document.delivery_address.previous_address_count.value;
	var r= 1;
	if(count!=''){
		var r= 2;
	}

	if(document.delivery_address.address_radio[r].checked==true){

		if(root.countries.value==''){
			alert('Please specify a country.');
			return false;
		}
		if(root.countries.value=='38'){
			if(root.canstates.value==''){
				alert('Please specify a state.');
				return false;
			}
		}

		if(root.countries.value=='219'){
			if(root.usstates.value==''){
				alert('Please specify a state.');
				return false;
			}
		}

		if(root.fname.value==''){
			alert('Please specify a first name.');
			root.fname.focus();
			return false;
		}

		if(root.lname.value==''){
			alert('Please specify a last name.');
			root.lname.focus();
			return false;
		}

		if(root.phone.value==''){
			alert('Please specify a phone number.');
			root.phone.focus();
			return false;
		}

		if(root.email.value==''){
			alert('Please specify an email address.');
			root.email.focus();
			return false;
		}

		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		var email = root.email.value;
		flag=email.match(pattern);
		if(!flag){
			alert('Please insert a valid email address.');
			root.email.select();
			return false;
		}

		if(root.city.value==''){
			alert('Please specify a city.');
			root.city.focus();
			return false;
		}

		if(root.new_address.value==''){
			alert('Please specify an address.');
			root.new_address.focus();
			return false;
		}
	}
	return true;
}

function validateAddComment(){
	root = document.add_comment;
	if(root.comment.value==''){
		alert('Please enter your comment.');
		root.comment.focus();
		return false;
	}
	return true;
}

function clearform(num){
	var root=document.add_bike;

	var description=root.description;
	var vcode=root.vcode;

	if(confirm('Are you sure you want to clear this form?')){
		description.value="";
		vcode.value="";
		for(var i=0;i<num;i++){
			image = eval('root.image'+i);
			image.value="";
		}
		return false;
	}

	return false;
}

function validateAddShowOff(num){
	var root = document.add_bike;
	var desc = root.description.value;
	if(desc==''){
		blinkBlink('description');
		alert('Please supply a description.');
		root.description.focus();
		return false;
	}
	var count=0;

	for(var i=0;i<num;i++){
		var image = eval('root.image'+i+'.value');
		if(image==''){
			count++;
		}

		if(count==num){
			blinkBlink('image0');
			alert('Please supply at least one photo.');
			return false;
		}
	}

	var vcode = root.vcode.value;
	if(vcode==''){
		blinkBlink('vcode');
		alert('Please enter the visual code.');
		root.vcode.focus();
		return false;
	}
	return true;
}

function validateFaq(){
	var root=document.submit_faq;
	question1 = root.question.value;
	if(question1==''){
		blinkBlink('question');
		alert('Please provide a question.');
		root.question.focus();
		return false;
	}
	return true;
}

function clearTellaFriend(e){
	var con=confirm('Are you sure you want to clear the form?');
	if(con){
		var root = document.tell_a_friend;
		root.name.value='';
		root.email.value='';
		root.message.value='';
		root.vcode.value='';
		for(var i=0;i<e;i++){
			var f_name= eval('root.f_name'+i+'');
			var f_email= eval('root.f_email'+i+'');
			f_name.value='';
			f_email.value='';
		}
	}else{
		return false;
	}
}

function validateTellAFriend(e){
	var root = document.tell_a_friend;
	var name = root.name.value;
	if (name==''){
		blinkBlink('name');
		alert('Please fill up your name');
		root.name.focus();
		return false;
	}
	var email = root.email.value;
	if (email==''){
		blinkBlink('email');
		alert('Please fill up your email');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.match(pattern);
	if(!flag){
		blinkBlink('email');
		alert('Please insert a valid email address.');
		root.email.select();
		return false;
	}
	var count=0;
	for(var i=0;i<e;i++){
		var f_name= eval('root.f_name'+i+'.value');
		var f_email= eval('root.f_email'+i+'.value');
		if(f_name==''&&f_email==''){
			count++;
		}
		if(f_name==''&&f_email!=''){
			blinkBlink('f_name'+i);
			alert('Please fill up your friends name');
			eval('root.f_name'+i+'.focus()');
			return false;
		}
		if(f_name!=''&&f_email==''){
			blinkBlink('f_email'+i);
			alert('Please fill up your friends email');
			eval('root.f_email'+i+'.focus()');
			return false;
		}
		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if(f_name!=''){
			flag=f_email.match(pattern);
			if(!flag){
				blinkBlink('f_email'+i);
				alert('Please insert a valid email address.');
				eval('root.f_email'+i+'.select()');
				return false;
			}
		}
	}
	if(count==e){
		blinkBlink('f_name0');
		alert('Please provide at least one friend email');
		root.f_name0.focus();
		return false;
	}
	var vcode = root.vcode.value;
	if (vcode==''){
		blinkBlink('vcode');
		alert('Please provide the visual code.');
		root.vcode.focus();
		return false;
	}
	return true;
}

function checkContactform(){
	var root=document.contactForm;

	var name=root.name;
	var company=root.company;
	var phone=root.phone;
	var fax=root.fax;
	var email=root.email;
	var department=root.department;
	var subject=root.subject;
	var message=root.message;

	if(name.value==""){
		blinkBlink('name');
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(phone.value==""){
		blinkBlink('phone');
		alert('Please enter your home phone number.');
		phone.focus();
		return false;
	}

	if(email.value==""){
		blinkBlink('email');
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	if(department.value==""){
		blinkBlink('department');
		alert('Please select the department you wish to contact.');
		department.focus();
		return false;
	}
	if(subject.value==""){
		blinkBlink('subject');
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		blinkBlink('message');
		alert('Please enter your message.');
		message.focus();
		return false;
	}
}

function clearContactForm(){
	var root=document.contactForm;

	var name=root.name;
	var company=root.company;
	var street=root.street;
	var city=root.city;
	var state=root.state;
	var country=root.country;
	var phone=root.phone;
	var mobile=root.mobile;
	var email=root.email;
	var department=root.department;
	var subject=root.subject;
	var message=root.message;

	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		company.value="";
		street.value="";
		city.value="";
		state.value="";
		country.value="";
		phone.value="";
		mobile.value="";
		email.value="";
		department.value="";
		subject.value="";
		message.value="";

		return false;
	}

	return false;
}

function checkDealerLogin(){
	var root=document.dealer_login;

	var username=root.username;
	var password=root.password;

	if(username.value==''){
		blinkBlink('username1');
		alert('Please enter your username.')
		username.focus();
		return false;
	}
	if(password.value==''){
		blinkBlink('password1');
		alert('Please enter your password.');
		password.focus();
		return false;
	}
}

function checkSearchForm(){
	var root=document.search;

	var keyword=root.keyword;

	if(keyword.value==''){
		blinkBlink('keyword');
		alert('Please enter a keyword');
		keyword.focus();
		return false;
	}

}

function validateRegistration(){

	var root = document.register;

	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var country = root.country.value;
	var username = root.username.value;
	var password = root.password.value;
	var confirm= root.confirm.value;
	var address = root.address.value;
	var city = root.city.value;
	var state = root.state_region.value;
	var postal_code = root.postal_code.value;
	var company = root.company.value;
	var phone = root.phone.value;
	var email = root.email.value;
	var secret_question = root.secret_question.value;
	var secret_answer = root.secret_answer.value;
	//	var resale_license = root.resale_license.value;
	var tax = root.tax.value;

	if (company == ''){
		blinkBlink('company');
		alert('Please fill the company field');
		root.company.focus();
		return false;
	}

	if (firstName == ''){
		blinkBlink('first_name');
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}

	if (lastName == ''){
		blinkBlink('last_name');
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}

	if (username == ''){
		blinkBlink('username');
		alert('Please specify your last name');
		root.username.focus();
		return false;
	}

	if (password == ''){
		blinkBlink('reg_password');
		alert('Please specify your password');
		root.password.focus();
		return false;
	}

	if (confirm == ''){
		blinkBlink('confirm');
		alert('Please confirm your password');
		root.confirm.focus();
		return false;
	}

	if (confirm != password){
		blinkBlink('confirm');
		alert('Your password and its confirmation do not match');
		root.confirm.focus();
		return false;
	}


	if (address == ''){
		blinkBlink('address');
		alert('Please specify your address');
		root.address.focus();
		return false;
	}

	if (city == ''){
		blinkBlink('city');
		alert('Please specify your city');
		root.city.focus();
		return false;
	}

	if (state== ''){
		blinkBlink('state_region');
		alert('Please specify your state.');
		root.state_region.focus();
		return false;
	}

	if (postal_code== ''){
		blinkBlink('postal_code');
		alert('Please specify your Zip/Postal Code');
		root.postal_code.focus();
		return false;
	}

	if (country == ''){
		blinkBlink('country');
		alert('Please select your country');
		root.country.focus();
		return false;
	}

	var phone = root.phone.value;
	if (phone == ''){
		blinkBlink('phone');
		alert('Please select your phone number');
		root.phone.focus();
		return false;
	}

	if (email == ''){
		blinkBlink('email');
		alert('Please enter your personal email');
		root.email.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		blinkBlink('email');
		alert('Please insert a valid email address.');
		root.email.focus();
		return false;
	}

	var tax = root.tax.value;
	if (tax == ''){
		blinkBlink('tax');
		alert('Please insert your Tax ID Number');
		root.tax.focus();
		return false;
	}

	//	var resale_license = root.resale_license.value;
	//	if (resale_license == ''){
	//		blinkBlink('resale_license');
	//		alert('Please insert your Resale license');
	//		root.resale_license.focus();
	//		return false;
	//	}

	if (secret_question == ''){
		blinkBlink('secret_question');
		alert('Please enter your secret question');
		root.secret_question.focus();
		return false;
	}

	if (secret_answer == ''){
		blinkBlink('secret_answer');
		alert('Please enter your secret answer');
		root.secret_answer.focus();
		return false;
	}

	return true;
}

function validateUpdateProfile(){

	var root = document.update_profile;

	var company = root.company.value;
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var username = root.u_username.value;
	var address = root.address.value;
	var city = root.city.value;
	var country = root.country.value;
	var state = root.state_region.value;
	var postal_code = root.postal_code.value;
	var company = root.company.value;
	var phone = root.phone.value;
	var email = root.email.value;
	var secret_question = root.secret_question.value;
	var secret_answer = root.secret_answer.value;

	if (company == ''){
		blinkBlink('company');
		alert('Please fill the company field');
		root.company.focus();
		return false;
	}

	if (firstName == ''){
		blinkBlink('first_name');
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}

	if (lastName == ''){
		blinkBlink('last_name');
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}

	if (username == ''){
		blinkBlink('u_username');
		alert('Please specify your username');
		root.u_username.focus();
		return false;
	}

	if (address == ''){
		blinkBlink('address');
		alert('Please specify your address');
		root.address.focus();
		return false;
	}

	if (city == ''){
		blinkBlink('city');
		alert('Please specify your city');
		root.city.focus();
		return false;
	}

	if (state == ''){
		blinkBlink('state_region');
		alert('Please enter your state');
		root.state_region.focus();
		return false;
	}

	if (postal_code == ''){
		blinkBlink('postal_code');
		alert('Please enter the postal code');
		root.postal_code.focus();
		return false;
	}

	if (country == ''){
		blinkBlink('country');
		alert('Please select your country');
		root.country.focus();
		return false;
	}

	if (phone == ''){
		blinkBlink('phone');
		alert('Please enter your phone number');
		root.phone.focus();
		return false;
	}

	if (email == ''){
		blinkBlink('email');
		alert('Please enter your personal email');
		root.email.focus();
		return false;
	}

	if(email!=''){
		var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		flag=email.match(pattern);
		if(!flag){
			blinkBlink('email');
			alert('Please insert a valid email address.');
			root.email.focus();
			return false;
		}
	}

	if (secret_question == ''){
		blinkBlink('secret_question');
		alert('Please enter your secret question');
		root.secret_question.focus();
		return false;
	}

	if (secret_answer == ''){
		blinkBlink('secret_answer');
		alert('Please enter your secret answer');
		root.secret_answer.focus();
		return false;
	}
	return true;
}

function validateUpdateMemberProfile(){

	var root = document.update_profile;

	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var personal_email = root.personal_email.value;
	var secret_question= root.secret_question.value;
	var secret_answer = root.secret_answer.value;

	if (firstName == ''){
		blinkBlink('first_name');
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}

	if (lastName == ''){
		blinkBlink('last_name');
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}


	if (personal_email == ''){
		blinkBlink('personal_email');
		alert('Please enter your personal email');
		root.personal_email.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=personal_email.match(pattern);
	if(!flag){
		blinkBlink('personal_email');
		alert('Please insert a valid email address.');
		root.personal_email.focus();
		return false;
	}

	if (secret_question == ''){
		blinkBlink('secret_question');
		alert('Please enter the secret question.');
		root.secret_question.focus();
		return false;
	}

	if (secret_answer == ''){
		blinkBlink('secret_answer');
		alert('Please enter your secret answer');
		root.secret_answer.focus();
		return false;
	}

	return true;
}

function clearRegisterForm(){

	var root = document.register;

	if (confirm('Are you sure you want to clear the form?')){

		root.first_name.value = '';
		root.last_name.value = '';
		root.nationality.value = '';
		root.gender.value = '';
		root.year.selectedIndex=0;
		root.month.selectedIndex=0;
		root.day.selectedIndex=0;
		root.country.value = '';
		root.company.value = '';
		root.title.value = '';
		root.contact_mode.value = '';
		root.home_phone.value = '';
		root.personal_email.value = '';
		root.secret_question.value = '';
		root.secret_answer.value = '';
		root.address.value = '';
		root.city.value = '';
		root.state_region.value = '';
		root.postal_code.value = '';
		root.work_phone.value = '';
		root.mobile_phone.value = '';
		root.work_email.value = '';
		root.tax.value = '';
		root.comments.value = '';
	}
	return false;
}

function popImage(imageURL,imageTitle){
	//alert(imageURL);
	defaultWidth  = 500;
	defaultHeight = 500;
	//alert(imageURL);
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
	var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

	var AutoClose = true;

	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?1:0;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
		var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left=100,top=100';
		var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

		//if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
			writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
			writeln('<sc'+'ript>');
			writeln('var isNN,isIE;');
			writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
			writeln('isNN=(navigator.appName=="Netscape")?1:0;');
			writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
			writeln('function reSizeToImage(){');
			writeln('if (isIE){');
			writeln('window.resizeTo(100,100);');
			writeln('width=100-(document.body.clientWidth-document.images[0].width);');
			writeln('height=100-(document.body.clientHeight-document.images[0].height);');
			writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
			writeln('window.innerWidth=document.images["Image"].width;');
			writeln('window.innerHeight=document.images["Image"].height;}}');
			writeln('function doTitle(){document.title="'+imageTitle+'";}');
			writeln('</sc'+'ript>');
			if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
			else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
			writeln('<img name="Image" src='+imageURL+' style="display:block"></body></html>');
			close();
		}
}

function validateRegistrationForShowOff(){
	var root = document.register;

	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var personal_email = root.personal_email.value;
	var secret_question = root.secret_question.value;
	var secret_answer = root.secret_answer.value;
	var username = root.username.value;
	var pass = root.pass.value;
	var confirm_pass = root.confirm_pass.value;

	if (firstName == ''){
		blinkBlink('first_name');
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}

	if (lastName == ''){
		blinkBlink('last_name');
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}

	if (personal_email == ''){
		blinkBlink('personal_email');
		alert('Please enter your email');
		root.personal_email.focus();
		return false;
	}

	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=personal_email.match(pattern);
	if(!flag){
		blinkBlink('personal_email');
		alert('Please insert a valid email address.');
		root.personal_email.focus();
		return false;
	}

	if (username == ''){
		blinkBlink('usernameshow');
		alert('Please enter your username');
		root.username.focus();
		return false;
	}
	if (pass == ''){
		blinkBlink('pass');
		alert('Please enter your password');
		root.pass.focus();
		return false;
	}
	if (confirm_pass == ''){
		blinkBlink('confirm_pass');
		alert('Please enter your password\'s confirmation');
		root.confirm_pass.focus();
		return false;
	}
	if (confirm_pass != pass){
		blinkBlink('confirm_pass');
		alert('The password and its confirmation do not match');
		root.confirm_pass.select();
		return false;
	}
	if (secret_question == ''){
		blinkBlink('secret_question');
		alert('Please enter your secret question');
		root.secret_question.focus();
		return false;
	}

	if (secret_answer == ''){
		blinkBlink('secret_answer');
		alert('Please enter your secret answer');
		root.secret_answer.focus();
		return false;
	}


	return true;

}

function checkMembersLogin(){
	var root=document.members_login;

	var username=root.username;
	var password=root.password;

	if(username.value==''){
		blinkBlink('username');
		alert('Please enter your username.')
		username.focus();
		return false;
	}
	if(password.value==''){
		blinkBlink('password');
		alert('Please enter your password.');
		password.focus();
		return false;
	}
}

function validChars(e,goods,itemId) {

	var key, keychar;

	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
	if(key==48){
		var qty=eval('document.add_item.qty_'+itemId+'.value');
		if(qty == ''){
			return false;
		}
	}
	if (key == null) return true;



	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if (goods.indexOf(keychar) != -1)
	return true;

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27){
		return true;
	}

	return false;

}

function checkMinQty(minQty,id,name){
	var root=document.add_item;
	var qtyIn=eval('root.qty_'+id);
	var qty=eval('root.qty_'+id+'.value');
	qty=parseInt(qty);
	minQty=parseInt(minQty);

	if(qty>0){
		if(qty<minQty || qty%minQty!=0){
			alert('The item \''+name+'\' has '+minQty+' units in the pack. Selling quantity should be in multiples of '+minQty);
			qtyIn.select();
			return false;
		}
	}
}

function clearQuickOrder(){
	var root=document.quick_order;

	var reference=root.reference;
	var qty=root.qty;

	if(confirm('Are you sure you want to clear this form?')){
		reference.value='';
		qty.value='';
	}

	return false;

}


function validateChangePassword(){
	var root=document.change_password;

	var oldPass=root.old_pass;
	var newPass=root.new_pass;
	var confirm=root.confirm;

	if(oldPass.value==''){
		blinkBlink('old_pass');
		alert('Please enter your old password.');
		oldPass.focus();
		return false;
	}
	if(newPass.value==''){
		blinkBlink('new_pass');
		alert('Please enter your new password.');
		newPass.focus();
		return false;
	}
	if(confirm.value==''){
		blinkBlink('confirm');
		alert('Please enter your new password\'s confirmation.');
		confirm.focus();
		return false;
	}

	if(newPass.value.length<6){
		blinkBlink('new_pass');
		alert('Your password must be at least 6 characters long.');
		newPass.select();
		return false;
	}
	if(newPass.value!=confirm.value){
		blinkBlink('confirm');
		alert('The new password and its confirmation do not match');
		confirm.select();
		return false;
	}
}


function blinkExecute(target,color){
	document.getElementById(target).style.backgroundColor = color;
}

function blinkBlink (target){
	color1 = "#92C2ED"; // blinking color
	color2 = "#ffffff"; // background color

	setTimeout('blinkExecute("'+target+'","'+color1+'")',0);
	setTimeout('blinkExecute("'+target+'","'+color2+'")',500);
	setTimeout('blinkExecute("'+target+'","'+color1+'")',1000);
	setTimeout('blinkExecute("'+target+'","'+color2+'")',1500);
	setTimeout('blinkExecute("'+target+'","'+color1+'")',2000);
	setTimeout('blinkExecute("'+target+'","'+color2+'")',2500);
	setTimeout('blinkExecute("'+target+'","'+color1+'")',3000);
	setTimeout('blinkExecute("'+target+'","'+color2+'")',3500);
	document.getElementById(target).focus();
}


function validateQuickOrder(){
	var root=document.quick_order;
	var ref=root.reference;
	var qty=root.qty;

	if(ref.value==''){
		blinkBlink('ref');
		alert('Please fill in the reference numbers.');
		ref.focus();
		return false;
	}
	if(qty.value==''){
		blinkBlink('qty');
		alert('Please fill in the quantities.');
		qty.focus();
		return false;
	}
}

function checkShowOffAddBike(isLoggedIn){
	if(!isLoggedIn)	{
		if(confirm('You have to be logged in to add a bike.\nIf you are not already registered please click:\n\n\'Ok\' to go to the registration page or,\n\'Cancel\' to remain on this page.')){
			window.location.href='/show_off/register.php';
			return false;
		}
		else{
			return false;
		}
	}
	else{
		return true;
	}
}
function enableRegistration(){
	var regButton=document.getElementById('regButton');
	var agree=document.getElementById('agree');

	if(agree.checked==true){
		regButton.disabled=false;
	}
	else{
		regButton.disabled=true;
	}
}


function toggle(obj) {
	// Moz. or IE
	var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
	// hide or show
	if(sibling.style.display=='' || sibling.style.display=='block') {
		sibling.style.display='none';
		obj.firstChild.firstChild.data='+';
	}
	else {
		sibling.style.display='block';
		obj.firstChild.firstChild.data='-';
	}
}
//
function initCollapse() {
	var oDT=document.getElementById('content').getElementsByTagName('dt');
	for (var i=0; i < oDT.length; i++) {
		oDT[i].onclick=function() {toggle(this)};
		var oSpan=document.createElement('span');
		var sign=document.createTextNode('+');
		oSpan.appendChild(sign);
		oDT[i].insertBefore(oSpan, oDT[i].firstChild);
		oSpan.style.fontFamily='monospace';
		oSpan.style.paddingRight='0.5em';
		oDT[i].style.cursor='pointer';
		toggle(oDT[i]);
	}
	oDT=null;
}

function displayCheckAvailability(){
	var username=document.getElementById('reg_username');

	if(username.value==''){
		alert('Please enter a username.');
		username.focus();
		return false;
	}
	else{
		window.open('/dealers/check_username.php?username='+username.value,'Username Availability','top=200,left=300,width=300,height=60,menubar=0,resizable=0,scrollbars=0')
		return false;
	}
}

function useAndClose(username){
	var win = window.opener.document.register.username.value=username;
	window.close();
	return false;
}

function displayCheckMemberAvailability(){
	var username=document.getElementById('usernameshow');

	if(username.value==''){
		alert('Please enter a username.');
		username.focus();
		return false;
	}
	else{
		window.open('/show_off/check_username.php?username='+username.value,'Username Availability','top=200,left=300,width=300,height=60,menubar=0,resizable=0,scrollbars=0')
		return false;
	}
}

function useMemberAndClose(username){
	var win = window.opener.document.register.username.value=username;
	window.close();
	return false;
}

function checkAgreement(){
	var auth=document.getElementById('authorize');
	var agree=document.getElementById('agree');
	var submitt=document.getElementById('submit_button');

	if(auth.checked==false || agree.checked==false){
		submitt.disabled=true;
		return false;
	}

	if(auth.checked==true &&  agree.checked==true){
		submitt.disabled=false;
		return false;
	}
}

function checkPreviousAddress(){
	var rad = document.getElementById('address_radio');

	rad.checked=true;

}
