function validatePollForm(){
	var root = document.poll;
	var poll = root.vote[0].checked;
	var poll1 = root.vote[1].checked;
	var poll2 = root.vote[2].checked;
	var poll3 = root.vote[3].checked;
	if(!poll&&!poll1&&!poll2&&!poll3){
		alert('Please select a choice before submitting.');
		return false;			
	}
	return true;
}

function validateGuestbook(){
	var root = document.guestbook;
	var name = root.name.value;
		
	if (name==''){
		alert('Please enter a name.');
		root.name.focus();
		return false;		
	}
	
	var email = root.email.value;
	if (email==''){
		alert('Please enter an email address.');
		root.email.focus();
		return false;		
	}
	
	var country = root.countries.value;
	if (country==''){
		alert('Please select a country.');
		root.countries.focus();
		return false;		
	}
	var comment = root.comments.value;
	if (comment==''){
		alert('Please enter a comment.');
		root.comments.focus();
		return false;		
	}
	
	return true;
}

function clearEditPassword(){
	
	if(confirm('Clicking reset will clear all your fields. Are you sure you want to continue?')){
		var root=document.change_password;
		root.old.value='';
		root.newp.value='';
		root.confnew.value='';
	}
	return false;

}

function clearEditProfile(){
	
	if(confirm('Clicking reset will clear all your fields. Are you sure you want to continue?')){
		var root=document.add_user;
		root.name.value='';
		root.email.value='';
		root.phone.value='';
	}
	return false;

}

function cleartestimonialform(){
	
	if(confirm('Clicking reset will clear all your fields. Are you sure you want to continue?')){
		var root=document.guestbook;
		root.name.value='';
		root.email.value='';
		root.countries.value='';
		root.comments.value='';
	}
	return false;

}

function validateAddContact(){
	var root=document.contact;
	
	var purpose=root.purpose.selectedIndex;
	if(purpose==0){
		alert("Please specify your purpose.");
		root.purpose.focus();
		return false;
	}
	
	var name=root.name.value;
	if(name==''){
		alert("Please specify your name.");
		root.name.focus();
		return false;
	}
	var email=root.email.value;
	if(email==''){
		alert("Please specify an email address.");
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.focus();
		return false;
	}
	var countries=root.countries.value;
	if(countries==''){
		alert("Please select a country from the drop down menu.");
		root.countries.focus();
		return false;
	}
	var comment=root.comments.value;
	if(comment==''){
		alert("Please enter your comments.");
		root.comments.focus();
		return false;
	}
	
	return true;
		
}

function clearform(){
	
	if(confirm('Clicking reset will clear all your fields. Are you sure you want to continue?')){
		var root=document.contact;
		root.name.value='';
		root.email.value='';
		root.countries.value='';
		root.comments.value='';
		root.phone.value='';
	}
	return false;

}

function validateUserLoginForm(){
	var root = document.userlogin;
	var username = root.username.value;
	if(username==''){
	alert('Please enter your username.');
	root.username.focus();
	return false;
	}
	
	var password = root.password.value;
	if(password==''){
	alert('Please enter your password.');
	root.password.focus();
	return false;
	}
	
return true;

}

function validateLoginForm(){
	var root = document.login;
	var username = root.name.value;
	if(username==''){
	alert('Please enter your name.');
	root.name.focus();
	return false;
	}
	
	var email = root.email.value;
	if(email==''){
	alert('Please enter your email.');
	root.email.focus();
	return false;
	}
	
return true;

}

function previewImage1(choice,page,folder,existingName){
	var newEntry = eval('document.'+page+'.'+existingName+'.value');
	var array = newEntry.split("|");
	if (newEntry == ''){
		alert('Please select an image.');
		return false;
	}
	var entry = folder+'/'+array[0];
	if (newEntry == ''){
		alert('Please select an image.');
		return false;
	}
	window.open('/media/users/banners/admin/view_wallpaper1.php?entry='+entry,'view_image','width='+array[1]+',height='+array[2]+',status=0,toolbar=0,scrollbars=0,history=0,left=100,top=100');
	return false;
}

function rbchange1(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[0].checked = true');
	return true;
}

function rbchange2(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[1].checked = true');
	return true;
}

function rbchange3(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[1].checked = true');
	return true;
}

function rbchange4(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[2].checked = true');
	return true;
}

function rbchange5(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[2].checked = true');
	return true;
}

function rbchange6(form,name){
	var root = eval('document.'+form);
	eval('root.'+name+'[3].checked = true');
	return true;
}

function validateAddBanner(){
	var root = document.add_banner;
	var count=0;
	
	var url = root.url.value;	
	var name = root.name.value;
	var photon = root.newp.value;
		
		if(name==''){
			alert('Please add a name for banner');
			root.name.focus();
			return false;
		}
		
		if(url==''){
			alert('Please add a url for banner');
			root.url.focus();
			return false;
		}
		
		
		var photon = root.newp.value;
		if(photon==''){
			alert('Please browse a photo for banner');
			root.newp.focus();
			return false;
		
		}
	return true;
}


function validateEditBanner(){
	var root = document.add_banner;
	var count=0;
		
	var photor = root.radiop[1].checked;
	var url = root.url.value;	
	var name = root.name.value;
		
		if(name==''){
			alert('Please add a name for banner');
			root.name.focus();
			return false;
		}
		
		if(url==''){
			alert('Please add a url for banner');
			root.url.focus();
			return false;
		}
		if(photor){
			
			var photon = root.newp.value;
			if(photon==''){
				alert('Please browse a photo for banner');
				root.newp.focus();
				return false;
			
			}
		
		}
	
	return true;
}



function validateAddCampaign(){
	var root= document.campaign;
	var media = root.medias.value
	if (media == ''){
		alert('Please specify a media');
		return false;
	}
	var s_date = root.s_date.value
	if (s_date == ''){
		alert('Please specify a start date');
		return false;
	}
	var e_date = root.e_date.value
	if (e_date == ''){
		alert('Please specify an end date');
		return false;
	}
	
	var banner_size = root.banner_size.value
	if (banner_size == ''){
		alert('Please specify a banner type');
		return false;
	}
	
	return true;
}

function validateAddUser(){
	var root = document.add_user;
	
	var name = root.name.value;
	var countries = root.countries;
	var address = root.address;
	var con_email = root.con_email;
	var phone = root.phone;
	var website = root.website;
	if(name==''){
		alert('Please add a name for the user');
		root.name.focus();
		return false;
	}
	if(countries.value==''){
		alert('Please select a country from the list.');
		countries.focus();
		return false;
	}
	if(address.value==''){
		alert('Please enter you address.');
		address.focus();
		return false;
	}
	
	if(phone.value==''){
		alert('Please enter you phone number.');
		phone.focus();
		return false;
	}
	
	if(website.value==''){
		alert('Please enter you website.');
		website.focus();
		return false;
	}
	
	var email = root.email.value;
	if(email==''){
		alert('Please add an email for the user');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.focus();
		return false;
	}
	if(con_email.value!=email){
		alert('The email and its confirmation do not match.');
		con_email.select();
		return false;
	}
	var username= root.username.value;
	if(username==''){
		alert('Please add a username for the user');
		root.username.focus();
		return false;
	}
	
	if(username.length<6){
		alert('Please add a username that contains more than 6 characters');
		root.username.focus();
		return false;
	}
	
	var password= root.password.value;
	if(password==''){
		alert('Please add a password for the user');
		root.password.focus();
		return false;
	}
	
	var con_password= root.con_password.value;
	if(con_password==''){
		alert('Please add a confirmation password.');
		root.con_password.focus();
		return false;
	}
	if(password.length<6){
		alert('Please add a password that contains more than 6 characters');
		root.password.focus();
		return false;
	}
	if(!isNaN(password)){
		alert('Please add a password that contains characters and digits');
		root.password.focus();
		return false;
	}
	if(password!=con_password){
		alert('The password and its confirmation do not match');
		root.password.focus();
		return false;
	}
	
	return true;
}


function validateEditUser(){
	
	var root = document.add_user;
	
	var name = root.name.value;
	if(name==''){
		alert('Please add a name for the user');
		root.name.focus();
		return false;
	}
	
	var countries = root.countries.value;
	if(countries==''){
		alert('Please Select a country');
		root.countries.focus();
		return false;
	}
	
	var address = root.address.value;
	if(address==''){
		alert('Please insert an address');
		root.address.focus();
		return false;
	}
	
	var phone = root.phone.value;
	if(phone==''){
		alert('Please insert a phone');
		root.phone.focus();
		return false;
	}
	
	var website = root.website.value;
	if(website==''){
		alert('Please insert a website url');
		root.website.focus();
		return false;
	}
	
	var email = root.email.value;
	if(email==''){
		alert('Please add an email for the user');
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.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');
		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;
	
	return true;
}


	function reloadpage2(direct){
	var id = document.media.medias[document.media.medias.selectedIndex].value;	
	location.href= direct + '?m_id=' + id;
	}
	
	
	function openEnlarged(name,width,height) {
		window.open('/catalogue/images/items_previews/'+name,'view_enlarged','width='+width+', height='+height+',status=0,toolbar=0,scrollbars=1,history=0,left=100,top=100');
		return false;
	}
	function openCountryPrices() {
		window.open('/catalogue/display_country_prices.php','view_prices','width=400, height=400,status=0,toolbar=0,scrollbars=1,history=0,left=100,top=100');
		return false;
	}
	
function reloadPage(){
   	var id = document.paymentgateway.countries[document.paymentgateway.countries.selectedIndex].value;
  	if (id == ''){
       return false;
   	}
   	
   	var root = document.paymentgateway;
   	var name = root.name.value;
	var email = root.email.value;
	var phone = root.phone.value;
	var city = root.city.value;
	var mailing_address_1 = root.mailing_1.value;
	var mailing_address_2 = root.mailing_2.value;
	var shipping_cost = root.shipping_cost.value;
	if ((!isNaN(shipping_cost) && shipping_cost != '') && (shipping_cost == '38' || shipping_cost == '219')) var state1 = root.state1.value;
	var city1 = root.city1.value;
	var mailing_address_1_1 = root.mailing_1_1.value;
	var mailing_address_1_2 = root.mailing_1_2.value;

	location.href = '/catalogue/display_order_checkout1.php?country=' + id + '&shipping_cost='+ shipping_cost +'&name='+name+'&email='+email+'&phone='+phone+'&city='+city+'&mailing_address_1='+mailing_address_1+'&mailing_address_2='+mailing_address_2+'&state1='+state1+'&city1='+city1+'&mailing_address_1_1='+mailing_address_1_1+'&mailing_address_1_2='+mailing_address_1_2+'#halfway';
   	return false;
}
function reloadPage1(){
   	var id = document.paymentgateway.shipping_cost[document.paymentgateway.shipping_cost.selectedIndex].value;
  	if (id == ''){
       return false;
   	}
   	
   	var root = document.paymentgateway;
   	
   	var name = root.name.value;
	var email = root.email.value;
	var phone = root.phone.value;
	
	var country = root.countries.value;
	if ((!isNaN(country) && country != '') && (country == '38' || country == '219'))var state = root.state.value;
	var city = root.city.value;
	var mailing_address_1 = root.mailing_1.value;
	var mailing_address_2 = root.mailing_2.value;
	
	var city1 = root.city1.value;
	var mailing_address_1_1 = root.mailing_1_1.value;
	var mailing_address_1_2 = root.mailing_1_2.value;

	location.href = '/catalogue/display_order_checkout1.php?shipping_cost='+id+'&country=' + country + '&name='+name+'&email='+email+'&phone='+phone+'&state='+state+'&city='+city+'&mailing_address_1='+mailing_address_1+'&mailing_address_2='+mailing_address_2+'&city1='+city1+'&mailing_address_1_1='+mailing_address_1_1+'&mailing_address_1_2='+mailing_address_1_2+'#halfway';
   	return false;
}
function validateCheckoutForm(){
	var root = document.paymentgateway;
	
	var name = root.name.value;
	var email = root.email.value;
	var phone = root.phone.value;
	var countries = root.countries.value;
	if ((!isNaN(countries) && countries != '') && (countries == '38' || countries == '219')) var state = root.state.value;
	var city = root.city.value;
	var mailing_address_1 = root.mailing_1.value;
	var country1 = root.shipping_cost.value;
	if ((!isNaN(country1) && country1 != '') && (country1 == '38' || country1 == '219')) var state1 = root.state1.value;
	var city1 = root.city1.value;
	var mailing_address_1_1 = root.mailing_1_1.value;
	
	if (name == '') {
		alert('Please enter your name.');
		root.name.focus();
		return false;
	}
	if (email == '') {
		alert('Please enter your email.');
		root.email.focus();
		return false;
	}
	if (phone == '') {
		alert('Please enter your phone.');
		root.phone.focus();
		return false;
	}
	if (countries == '') {
		alert('Please select your country.');
		return false;
	}
	if ((!isNaN(countries) && countries != '') && (countries == '38' || countries == '219') && state == '') {
		alert('Please select your state.');
		root.state.focus();
		return false;
	}
	if (city == '') {
		alert('Please enter your city.');
		root.city.focus();
		return false;
	}
	if (mailing_address_1 == '') {
		alert('Please enter your mailing address.');
		root.mailing_1.focus();
		return false;
	}
	if (country1 == '') {
		alert('Please select the country you would like to ship the order to.');
		return false;
	}
	if ((!isNaN(country1) && country1 != '') && (country1 == '38' || country1 == '219') && state1 == '') {
		alert('Please please select the state you would like to ship the order to.');
		root.state1.focus();
		return false;
	}
	if (city1 == '') {
		alert('Please enter the city you would like to ship the order to.');
		root.city1.focus();
		return false;
	}
	if (mailing_address_1_1 == '') {
		alert('Please enter the address where to ship the order.');
		root.mailing_1_1.focus();
		return false;
	}
	return true;
	
}