function validateWinForm(){
	var root = document.win;
	
	var name = root.name.value;
	var email = root.email.value;
	var address = root.address.value;
	var phone = root.phone.value;
	
	if (name == '' || email == '' || address == '' || phone == '') {
		alert('Please fill up all the fields');
		return false;
	}
	return true;
}
function openWinJewelry(url){
	window.open(""+url+"/win_jewelry/reduction.php", "winreduction", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=815,height=220,top=5,left=5");
	return false;
}

function validatePrintUserRegistrationForm1(){
	var username = document.registration_form.username.value;
	var name = document.registration_form.full_name.value;
	var tax = document.registration_form.tax_number.value;

	if (username == ''){
		alert('Please enter a username.');
		document.registration_form.username.focus();
		return false;
	}
	test = isPasswordLength('registration_form', 'password','password');
	if (!test) {
		return false;
	}

	var test = isPasswordConf('registration_form', 'password', 'conf_password');
	if (!test) {
		return false;
	}
	if (name == ''){
		alert('Please enter your full name.');
		document.registration_form.full_name.focus();
		return false;
	}
	

	var email = document.registration_form.email.value;
	if (email == ''){
		alert('Please enter your email address.');
		document.registration_form.email.focus();
		return false;
	}

	var test = isEmpty('registration_form', 'address','address');
	if (!test) {
		return false;
	}

	var test = isEmpty('registration_form', 'country_id','country');
	if (!test) {
		return false;
	}
	var city = document.registration_form.city.value;
	var zip = document.registration_form.zip.value;
	if (city == '') {
		alert('Please enter your city');
		document.registration_form.city.focus();
		return false;
	}
	var len = zip.length;
	if (zip != '' && (isNaN(zip) || len < 5)){
		alert('Please enter a valid zip code.');
		document.registration_form.zip.focus();
		return false;
	}
	var secretQuestion = document.registration_form.secret_question.value;
	var answer = document.registration_form.answer.value;
	if (secretQuestion == ''){
		alert('Please enter the secret question.');
		document.registration_form.secret_question.focus();
		return false;
	}
	if (answer == ''){
		alert('Please enter the answer to the secret question.');
		document.registration_form.answer.focus();
		return false;
	}
	
	var test = isEmpty('registration_form', 'area_code','area code');
	if (!test) {
		return false;
	}
	
	var test = isEmpty('registration_form', 'phone','phone');
	if (!test) {
		return false;
	}

	return;
}

function isPasswordLength(formName, fieldName,fieldDisplay){
	var password = eval ('document.' + formName + '.' + fieldName + '.value');
	var passwordFocus = eval ('document.' + formName + '.' + fieldName);
	if (password.length < 8){
		alert ('The '+fieldDisplay+' must be a minimum of 8 characters.');
		passwordFocus.focus();
		return false;
	}
	return true;
}

function isPasswordConf(formName, passFieldName, confFieldName){
	var pass = eval('document.' + formName + '.' + passFieldName + '.value');
	var conf = eval('document.' + formName + '.' + confFieldName + '.value');
	var confFocus = eval('document.' + formName + '.' + confFieldName);
	if (pass != conf){
		alert ('The password and the confirmation do not match.');
		confFocus.focus();
		return false;
	}
	return true;
}

function validatePrintUserRegistrationForm(){
	var username = document.registration_form.username.value;
	var name = document.registration_form.full_name.value;
	
	if (username == ''){
		alert('Please enter a username.');
		document.registration_form.username.focus();
		return false;
	}
	test = isPasswordLength('registration_form', 'password','password');
	if (!test) {
		return false;
	}

	var test = isPasswordConf('registration_form', 'password', 'conf_password');
	if (!test) {
		return false;
	}
	if (name == ''){
		alert('Please enter your full name.');
		document.registration_form.full_name.focus();
		return false;
	}
	

	var email = document.registration_form.email.value;
	if (email == ''){
		alert('Please enter your email address.');
		document.registration_form.email.focus();
		return false;
	}

	var test = isEmpty('registration_form', 'address','address');
	if (!test) {
		return false;
	}

	var test = isEmpty('registration_form', 'country_id','country');
	if (!test) {
		return false;
	}
	var city = document.registration_form.city.value;
	var zip = document.registration_form.zip.value;
	if (city == '') {
		alert('Please enter your city');
		document.registration_form.city.focus();
		return false;
	}
	var len = zip.length;
	if (zip != '' && (isNaN(zip) || len < 5)){
		alert('Please enter a valid zip code.');
		document.registration_form.zip.focus();
		return false;
	}
	
	var secretQuestion = document.registration_form.secret_question.value;
	var answer = document.registration_form.answer.value;
	if (secretQuestion == ''){
		alert('Please enter the secret question.');
		document.registration_form.secret_question.focus();
		return false;
	}
	if (answer == ''){
		alert('Please enter the answer to the secret question.');
		document.registration_form.answer.focus();
		return false;
	}
	
	var test = isEmpty('registration_form', 'phone','phone');
	if (!test) {
		return false;
	}
	var test = isEmpty('registration_form', 'area_code','area code');
	if (!test) {
		return false;
	}

	return;
}


function isEmpty(formName, fieldName,fieldDisplay){
	var temp = eval('document.' + formName + '.' + fieldName + '.value');
	var tempFocus = eval('document.' + formName + '.' + fieldName);
	if (temp == ''){
		alert ('Cannot set an empty field in '+fieldDisplay +' .');
		tempFocus.focus();
		return false;
	}
	return true;
}

function validateEditUserRegistrationForm(){
	var address = document.registration_form.address.value;
	var country = document.registration_form.country_id.value;
	var phone = document.registration_form.phone.value;
	var org = document.registration_form.organization.value;
	
	var test = isEmail('registration_form', 'email','email');
	if (!test) {
		return false;
	}
	if (isNaN(country) || country == ''){
		alert ('Please select a country.');
		document.registration_form.country_id.focus;
		return false;
	}
	var city = document.registration_form.city.value;
	var zip = document.registration_form.zip.value;
	if (city == '') {
		alert('Please enter your city');
		document.registration_form.city.focus();
		return false;
	}
	var len = zip.length;
	if (zip != '' && (isNaN(zip) || len < 5)){
		alert('Please enter a valid zip code.');
		document.registration_form.zip.focus();
		return false;
	}
	var test = isEmpty('registration_form', 'area_code','area code');
	if (!test){
		return false;
	}
	
	var test = isEmpty('registration_form', 'phone','phone');
	if (!test){
		return false;
	}
	
	
		
	return true;
}

function isEmail(formName, fieldName,fieldDisplay){
	var email = eval('document.' + formName + '.' + fieldName + '.value');
	var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z]+)(.[a-zA-Z]+)*$/;
	var emailFocus = eval('document.' + formName + '.' + fieldName);
	flag = pattern.test(email);
	if (!flag){
		alert ('Please enter a valid ' +fieldDisplay+ ' format.');
		emailFocus.focus();
		return false;
	}
	return true;
}

function validateEditPasswordForm(){
	var mold = document.edit_password.mold.value;
	var mnew = document.edit_password.mnew.value;
	var mconf = document.edit_password.mconf.value;
	if (mold == ''){
		alert('Please enter your old password.');
		document.edit_password.mold.focus();
		return false;
	}
	if (mnew.length < 8){
		alert('Your password must be a minimum of 8 characters.');
		document.edit_password.mnew.focus();
		return false;
	}
	if (mnew != mconf){
		alert('The new password and its confirmation do not match.');
		document.edit_password.mnew.focus();
		return false;
	}
	return true;
}

function loginFirst(){
	alert('You have to login in first.');
	return false;
}

function openGroupImage(path){
	window.open(path, "image", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=480,top=50,left=100");
	return false;
}

function openGroupImage1(name){
	var array = name.split("|");
	var name1 = array[0];
	window.open('/us/catalog/preview_image_in_size_for_w.php?name=' + name1, 'view_thumb', 'width=' + array[1] +',height=' + array[2] + ',status=0,toolbar=0,scrollbars=0,history=0,left=100,top=100');
	return false;
}

function openGroupImage2(name){
	var array = name.split("|");
	var name1 = array[0];
	window.open('/us/catalog/preview_image_in_size_for_r.php?name=' + name1, 'view_thumb', 'width=' + array[1] +',height=' + array[2] + ',status=0,toolbar=0,scrollbars=0,history=0,left=100,top=100');
	return false;
}

function validateChoosePayment(){
	var set = 0;
	for (var i = 0; i < 4; i++){
		var p = document.choose_payment.payment[i].checked;
		if (p == true) {
			set = 1;
			break;
		}
	}
	
	if (set == 0) {
		alert('Please choose a Payment Method.');
		return false;
	}
	return true;
}

function validateContactUs(){
	var country = document.contact.country_id.value;
	var address = document.contact.address.value;
	var zip = document.contact.zip.value;
	var comments = document.contact.comments.value;
	var name = document.contact.name.value;
	var email = document.contact.email.value;
	
	if (name == ''){
		alert ('Please enter your full name.');
		document.contact.name.focus();
		return false;
	}
	if (email == ''){
		alert('Please enter your email address.');
		document.contact.email.focus();
		return false;
	}
	
	if (isNaN(country) || country==''){
		alert ('Please select a country');
		document.contact.country_id.focus();
		return false;
	}
	
	if (address == ''){
		alert('Please enter your address.');
		document.contact.address.focus();
		return false;
	}
	if (zip != ''){
		if (isNaN(zip)){
			alert ('Please enter a valid zip code');
			document.contact.zip.focus();
			return false;
		}
	}
		
	if (comments == ''){
		alert('Please enter your comments.');
		document.contact.comments.focus();
		return false;
	}
	return true;
	
}

function validateChoosePaymentForNLI(){
	
	var root = document.choose_payment;
	var fullName = root.full_name.value;
	var email = root.email.value;
	var address = root.address.value;
	var country = root.country_id.value;
	var city = root.city.value;
	var phone = root.phone.value;
	
	if (fullName == ''){
		alert('Please give your name');
		root.full_name.focus();
		return false;
	}
	if (email == ''){
		alert('Please give your email');
		root.email.focus();
		return false;
	}
	if (address == ''){
		alert('Please give your address');
		root.address.focus();
		return false;
	}
	if (country == ''){
		alert('Please select your country');
		root.country_id.focus();
		return false;
	}
	if (city == ''){
		alert('Please give your city');
		root.city.focus();
		return false;
	}
	if (phone == ''){
		alert('Please give your phone number');
		root.phone.focus();
		return false;
	}
	
	
	var set = 0;
	for (var i = 0; i < 4; i++){
		var p = document.choose_payment.payment[i].checked;
		if (p == true) {
			set = 1;
			break;
		}
	}
	
	if (set == 0) {
		alert('Please choose a Payment Method.');
		return false;
	}
	return true;
}

function confirmResetContactForm(){
	
	if (confirm('Are you sure you sure you want to reset the form?')){
		var root = document.contact;
		root.name.value = '';
		root.email.value = '';
		root.country_id.value = '';
		root.address.value = '';
		root.zip.value = '';
		root.work.value = '';
		root.mobile.value = '';
		root.website.value = '';
		root.organization.value = '';
		root.comments.value = '';
		return false;
	}
	else return false;
	
	
}

function confirmResetWRegistration(){
	
	if (confirm('Are you sure you sure you want to reset the form?')){
		var root = document.registration_form;
		root.tax_number.value = '';
		root.username.value = '';
		root.password.value = '';
		root.conf_password.value = '';
		root.full_name.value = '';
		root.email.value = '';
		root.address.value = '';
		root.country_id.value = '';
		root.city.value = '';
		root.zip.value = '';
		root.country_id.value = '';
		root.secret_question.value = '';
		root.answer.value = '';
		root.area_code.value = '';
		root.phone.value = '';
		root.fax.value = '';
		root.organization.value = '';
	}
	else return false;
}

function confirmResetRRegistration(){
	
	if (confirm('Are you sure you sure you want to reset the form?')){
		var root = document.registration_form;
		root.username.value = '';
		root.password.value = '';
		root.conf_password.value = '';
		root.full_name.value = '';
		root.email.value = '';
		root.address.value = '';
		root.country_id.value = '';
		root.city.value = '';
		root.zip.value = '';
		root.country_id.value = '';
		root.secret_question.value = '';
		root.answer.value = '';
		root.area_code.value = '';
		root.phone.value = '';
		root.fax.value = '';
		root.organization.value = '';
	}
	else return false;
}
