function openPopImage(value){
	var array = value.split("|");
	var image=array[3];
		popImage('/items/preview/'+image,image);
	return false;
}


function validatePaymentType(counter){
	var root=document.delivery_address;
		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 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;
	}
	
	var choice = eval(document.delivery_address.address_radio[r].checked);
	if(choice==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.new_address.value==''){
			alert('Please specify a delivery address.');
			root.new_address.focus();
			return false;
		}
		}
	return true;
}

function validateAddressForEdit(){
		var root=document.delivery_address;
		if(root.countries.value!=''){
		
			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;
		}
	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 viewItemImage(catId){
	var imgName = eval('document.customize.cat_'+catId+'.src');
	popImage(imgName,Image)
}


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)+12;');
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 validChars(e,goods,typeId,photoId) {
	
	var key, keychar;
	
	key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
		if(key==48){
	var qty=eval('document.sc.text_'+typeId+'_'+photoId+'.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 changeCustomizeImage(catId){

	var item = eval('document.customize.item_'+catId+'[document.customize.item_'+catId+'.selectedIndex].value;');
	array=item.split("|");
	item_id=array[0];
	//alert(eval('cat_'+catId+'.src'));
	eval('document.customize.cat_'+catId+'.src = image_'+item_id+'.src;');
	
	var currentPrice= document.customize.current_price_temp.value;
	var finalPrice = currentPrice;
	var counter = document.customize.counter.value;
	
	for(i=0;i<counter;i++){
		
		//item_price= eval('document.customize.elements[document.customize.elements['+i+'].selectedIndex].value');
		var item_price= eval('document.customize.elements['+i+'].value');
		alert(document.customize.elements['+i+'].value);
		array1=item_price.split("|");
		sign= array1[1];
		price = array1[2];
		
		if(sign=='m'){
			finalPrice = parseInt(finalPrice) - parseInt(price);
		}else if(sign=='p'){
			finalPrice = parseInt(finalPrice) + parseInt(price);
		}
	}
	document.customize.current_price.value=finalPrice;
	
}*/


function changeCustomizeImage(catId){

	var item = eval('document.customize.item_'+catId+'[document.customize.item_'+catId+'.selectedIndex].value;');
	array=item.split("|");
	item_id=array[0];
	//alert(eval('cat_'+catId+'.src'));
	eval('document.customize.cat_'+catId+'.src = image_'+item_id+'.src;');
	
	var currentPrice= document.customize.current_price_temp.value;
	var finalPrice = currentPrice;
	var counter = document.customize.counter.value;
	
	for(i=1;i<=counter;i++){
		//item_price= eval('document.customize.elements[document.customize.elements['+i+'].selectedIndex].value');
		var item_price = eval('document.customize.elements['+i+'].value');
		
		array1=item_price.split("|");
		sign= array1[1];
		price = array1[2];
		
		if(sign=='m'){
			finalPrice = parseInt(finalPrice) - parseInt(price);
		}else if(sign=='p'){
			finalPrice = parseInt(finalPrice) + parseInt(price);
		}
	}
	document.customize.current_price.value=finalPrice;
	return true;
	
}

function validateSearch(){
	root = document.search;
	if(root.keyword.value==''){
	alert('Please enter a search word.');
	root.keyword.focus();
	return false;
	}
	return true;
}

function reloadBike(){
	var cat = document.myForm.categories[document.myForm.categories.selectedIndex].value;
	if(cat == ''){
		return false;
	}
	else{
		window.location.href='index.php?page=1&categories='+cat;
		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 passValidation(){
	var root = document.change_password;
	var oldp = root.old.value;
	var newp = root.newp.value;
	var confnew = root.confnew.value;
	
	if (oldp == '' || newp == '' || confnew == ''){
		alert('Please fill up all the fields');
		root.old.focus();
		return false;
	}
	if (!isNaN(newp)){
		alert('Please insert a password that contains characters.');
		root.newp.focus();
		return false;
	}
	
	if (newp != confnew){
		alert('The password and it\'s confirmation do not match');
		root.confnew.focus();
		return false;
	}
	
	oldp = hex_md5(oldp);
	newp = hex_md5(newp);
	confnew = hex_md5(confnew);
	
	root.old.value = oldp;
	root.newp.value = newp;
	root.confnew.value = confnew;
	root.enc.value = '1';
	
	return true;
}

function validateEditProfile(){
	
	var root = document.register;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var nationality = root.nationality.value;
	var gender = root.gender.value;
	var address = root.address.value;
	var city = root.city.value;
	var country = root.country.value;
	var contact_mode = root.contact_mode.value;
	var home_phone = root.home_phone.value;
	var work_email = root.work_email.value;
	var personal_email = root.personal_email.value;

	if (firstName == ''){
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}
	
	if (lastName == ''){
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}
	
	if (nationality == ''){
		alert('Please select your nationality');
		root.nationality.focus();
		return false;
	}
	
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	
	if (address == ''){
		alert('Please provide your address');
		root.address.focus();
		return false;
	}
	
	if (city == ''){
		alert('Please provide your city');
		root.city.focus();
		return false;
	}
	
	if (country == ''){
		alert('Please select your country');
		root.country.focus();
		return false;
	}
	
	if (contact_mode == ''){
		alert('Please select your preferred contact mode');
		root.contact_mode.focus();
		return false;
	}
	
	if (home_phone == ''){
		alert('Please give your home phone');
		root.home_phone.focus();
		return false;
	}
	
	if(work_email!=''){
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=work_email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.work_email.focus();
		return false;
	}
	}
	
	if (personal_email == ''){
		alert('Please give 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){
		alert('Please insert a valid email address.');
		root.personal_email.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==''){
		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){
		alert('Please supply at least one photo.');
		return false;
		}
	}
	
	var vcode = root.vcode.value;
	if(vcode==''){
		alert('Please enter the visual code.');
		root.vcode.focus();
		return false;
	}
	return true;
}

function validateLogin(){
	var root = document.login;
	
	var username = root.username.value;
	var password = root.password.value;
	if (username == ''){
		alert('Please give your username.');
		root.username.focus();
		return false;
	}
	if (password == ''){
		alert('Please give your password.');
		root.password.focus();
		return false;
	}
	password = hex_md5(password);
	root.password.value = password;
	root.hashed.value = 'yes';
	return true;
}

function clearForm(){
	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 checkContactform(){
	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(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	/*if (street.value == ''){
		alert('Please specify your address');
		street.focus();
		return false;
	}
	
	if (city.value == ''){
		alert('Please specify your city');
		city.focus();
		return false;
	}
	if(country.value==""){
		alert('Please select a country from the list.');
		country.focus();
		return false;
	}
	if(phone.value==""){
		alert('Please enter your phone number.');
		phone.focus();
		return false;
	}
	if(isNaN(phone.value)){
		alert('The phone number should only contain digits.');
		phone.select();
		return false;
	}
	if(isNaN(mobile.value) && mobile.value!=""){
		alert('The mobile phone number should only contain digits');
		mobile.select();
		return false;
	}*/
	
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.value.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		email.select();
		return false;
	}
	/*if(department.value==""){
		alert('Please select the department you wish to contact.');
		department.focus();
		return false;
	}
	if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}*/
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}
}

function validateRegistration(){
	
	var root = document.register;
	
	var firstName = root.first_name.value;
	var lastName = root.last_name.value;
	var nationality = root.nationality.value;
	var gender = root.gender.value;
	var country = root.countries.value;
	var address = root.address.value;
	var city = root.city.value;
	var contact_mode = root.contact_mode.value;
	var home_phone = root.home_phone.value;
	var mobile_phone = root.mobile_phone.value;
	var personal_email = root.personal_email.value;
	var work_email = root.work_email.value;
	var username = root.username.value;
	var password = root.password.value;
	var confirm_password = root.confirm_password.value;
	var secret_question = root.secret_question.value;
	var secret_answer = root.secret_answer.value;
	
	if (firstName == ''){
		alert('Please specify your first name');
		root.first_name.focus();
		return false;
	}
	
	if (lastName == ''){
		alert('Please specify your last name');
		root.last_name.focus();
		return false;
	}
	
	if (nationality == ''){
		alert('Please select your nationality');
		root.nationality.focus();
		return false;
	}
	
	if (gender == ''){
		alert('Please select your gender');
		root.gender.focus();
		return false;
	}
	
	if (address == ''){
		alert('Please specify your address');
		root.address.focus();
		return false;
	}
	
	if (city == ''){
		alert('Please specify your city');
		root.city.focus();
		return false;
	}
	
	if (country == ''){
		alert('Please select your country');
		root.countries.focus();
		return false;
	}
	
	if (username == ''){
		alert('Please give your username');
		root.username.focus();
		return false;
	}
	
	if (password == ''){
		alert('Please specify your password');
		root.password.focus();
		return false;
	}
	
	if (password != confirm_password){
		alert('Your password and its confirmation do not match');
		root.confirm_password.focus();
		return false;
	}
	
	if (secret_question == ''){
		alert('Please give your secret question');
		root.secret_question.focus();
		return false;
	}
	
	if (secret_answer == ''){
		alert('Please give your secret answer');
		root.secret_answer.focus();
		return false;
	}
	
	if (contact_mode == ''){
		alert('Please select your preferred contact mode');
		root.contact_mode.focus();
		return false;
	}
	
	if (home_phone == ''){
		alert('Please give your home phone');
		root.home_phone.focus();
		return false;
	}
	
	if (contact_mode == '2'){
		if(mobile_phone==''){
			alert('Please specify your mobile phone number');
			root.mobile_phone.focus();
			return false;
		}
	}	
	
	if(work_email!=''){
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=work_email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.work_email.focus();
		return false;
	}
	}
	if (personal_email == ''){
		alert('Please give 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){
		alert('Please insert a valid email address.');
		root.personal_email.focus();
		return false;
	}
		
	password = hex_md5(password);
	confirm_password = hex_md5(confirm_password);
	
	root.hashed.value = '1';
	root.password.value = password;
	root.confirm_password.value = confirm_password;
	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.countries.value = '';
		root.contact_mode.value = '';
		root.home_phone.value = '';
		root.personal_email.value = '';
		root.username.value = '';
		root.password.value = '';
		root.confirm_password.value = '';
		root.secret_question.value = '';
		root.secret_answer.value = '';
		root.address.value = '';
		root.city.value = '';
		root.state_region.value = '';
		root.postal_code.value = '';
		root.mobile_phone.value = '';
		root.work_email.value = '';
	}
	return false;
}


var link10 = new Image();
var link11 = new Image();
var link12 = new Image();
var link13 = new Image();
var link14 = new Image();
var link15 = new Image();
var link16 = new Image();
var link17 = new Image();
var link18 = new Image();
var link19 = new Image();
var link20 = new Image();
var link21 = new Image();

link10.src = "/images/members/home.gif";
link11.src = "/images/members/home_vis.gif";
link12.src = "/images/members/members.gif";
link13.src = "/images/members/members_vis.gif";
link14.src = "/images/members/show_off.gif";
link15.src = "/images/members/show_off_vis.gif";
link16.src = "/images/members/cust_u_bike.gif";
link17.src = "/images/members/cust_u_bike_vis.gif";
link18.src = "/images/members/games.gif";
link19.src = "/images/members/games_vis.gif";
link20.src = "/images/members/contact_us.gif";
link21.src = "/images/members/contact_us_vis.gif";
