function oneChecked(group){
	var blAtLeastOneClicked = false;
	if (group.length){
		for (i = 0; i < group.length; i++) {
			if (group[i].checked == true) {
				blAtLeastOneClicked = true;
			}
		}
	}
	else {
		if (group.checked){
			blAtLeastOneClicked = true;
		}
		else {
			blAtLeastOneClicked = false;
		}
	}
	return blAtLeastOneClicked;
}

function echeck(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	
	if (str.indexOf(at) == -1) { return false;}
	if ((str.indexOf(at) == -1) || (str.indexOf(at) == 0) || (str.indexOf(at) == lstr)) { return false; }
	if ((str.indexOf(dot) == -1) || (str.indexOf(dot) == 0) || (str.indexOf(dot) == lstr)){ return false; }
	if (str.indexOf(at, (lat+1)) != -1){ return false; }
	if ((str.substring(lat-1, lat) == dot) || (str.substring(lat+1, lat+2) == dot)){ return false; }
	if (str.indexOf(dot, (lat+2)) == -1){ return false; }
	if (str.indexOf(" ") != -1){ return false; }
	return true;
}

function validateEmailForm1() {
	var blValid = true;
	var strError = 'Please ensure the following form fields are completed before proceeding:\n\n';
	
	 
	txtName = document.frmContact.txtname.value;
	txtselcountry = document.frmContact.selcountry.value;
	txtEmail = document.frmContact.txtemail.value;
	intDataCheck = oneChecked(document.frmContact.iddata);
	intPrivacyCheck = oneChecked(document.frmContact.idprivacy);
	txttelephone = document.frmContact.txttelephone.value;
	
	if ((txtName == '')) {
		strError = strError + "Your name\n";
		blValid = false;
	}

	if ((txtEmail == '') || (!echeck(txtEmail))) {
		strError = strError + "Your email address\n";
		blValid = false;
	}
	
	if (!(txttelephone == '')) {
		if ((txttelephone.length < 5)) {
			strError = strError + "Valid telephone number\n ";
			blValid = false;
		}
	}


	if (intDataCheck == false) {
		strError = strError + "Please accept that data will be held by Retail Decisions Group outside the EEA\n";
		blValid = false;
	}
	
	if (intPrivacyCheck == false) {
		strError = strError + "Please confirm you have read our privacy policy\n";
		blValid = false;
	}
	
	if (blValid) {
		document.frmContact.submit();
	}
	else {
		window.alert (strError);
		return (false);
	}	
}

function validateEmailForm2() {
	var blValid = true;
	var strError = 'Please ensure the following form fields are completed before proceeding:\n\n';
	
	txtEmail = document.frmContact.txtemail.value;
	intDataCheck = oneChecked(document.frmContact.iddata);
	intPrivacyCheck = oneChecked(document.frmContact.idprivacy);

	if ((txtEmail == '') || (!echeck(txtEmail))) {
		strError = strError + "Your email address\n";
		blValid = false;
	}
	
	if (intDataCheck == false) {
		strError = strError + "Please accept that data will be held by Retail Decisions Group outside the EEA\n";
		blValid = false;
	}
	
	if (intPrivacyCheck == false) {
		strError = strError + "Please confirm you have read our privacy policy\n";
		blValid = false;
	}
	
	if (blValid) {
		document.frmContact.submit();
	}
	else {
		window.alert (strError);
		return (false);
	}	
}

function validateApplicationForm1() {
	var blValid = true;
	var strError = 'Please ensure the following form fields are completed before proceeding:\n\n';
	
	
	txtEmail = document.frmContact.txtemail.value;
	txtCV = document.frmContact.AttachyourCVfile.value;
	intDataCheck = oneChecked(document.frmContact.iddata);
	intPrivacyCheck = oneChecked(document.frmContact.idprivacy);

	if ((txtEmail == '') || (!echeck(txtEmail))) {
		strError = strError + "Your email address\n";
		blValid = false;
	}
	


	if (intDataCheck == false) {
		strError = strError + "Please accept that data will be held by Retail Decisions Group outside the EEA\n";
		blValid = false;
	}
	
	if (intPrivacyCheck == false) {
		strError = strError + "Please confirm you have read our privacy policy\n";
		blValid = false;
	}
	
	var txtCVExt = txtCV.toLowerCase().substring(txtCV.length-3,txtCV.length);
	if ((txtCVExt=="zip") || (txtCVExt=="doc") || (txtCVExt=="pdf")) {
		//Valid upload
	}
	else{
		//Invalid upload
		strError = strError + "Please only upload a .zip, a .pdf or .doc file.\n";
		blValid = false;
	}

	if (blValid) {
		document.frmContact.submit();
	}
	else {
		window.alert (strError);
		return (false);
	}	
}

function validatePartnerReferralForm1() {
	var blValid = true;
	var strError = 'Please ensure the following form fields are completed before proceeding:\n\n';
	
	txtfirstname = document.frmPartnerReferral.first_name.value;
	txtlastname = document.frmPartnerReferral.last_name.value;
	seltitle = document.frmPartnerReferral.title.value;
	txtcompany = document.frmPartnerReferral.company.value;
	txtwebsite = document.frmPartnerReferral.URL.value;
	txtemail = document.frmPartnerReferral.email.value;
	txtphone = document.frmPartnerReferral.phone.value;

	
	intDataCheck = oneChecked(document.frmPartnerReferral.iddata);
	intPrivacyCheck = oneChecked(document.frmPartnerReferral.idprivacy);

	if ((txtfirstname == '')) {
		strError = strError + "Your first name\n";
		blValid = false;
	}

	if ((txtlastname == '')) {
		strError = strError + "Your last name\n";
		blValid = false;
	}

	if (seltitle == '0') {
		strError = strError + "Your title\n";
		blValid = false;
	}

	if ((txtcompany == '')) {
		strError = strError + "Your company name\n";
		blValid = false;
	}

	if ((txtwebsite == '')) {
		strError = strError + "Your website address\n";
		blValid = false;
	}

	if ((txtemail == '') || (!echeck(txtemail))) {
		strError = strError + "Your email address\n";
		blValid = false;
	}

	if ((txtphone == '')) {
		strError = strError + "Your phone number\n";
		blValid = false;
	}



	if (intDataCheck == false) {
		strError = strError + "Please accept that data will be held by Retail Decisions Group outside the EEA\n";
		blValid = false;
	}
	
	if (intPrivacyCheck == false) {
		strError = strError + "Please confirm you have read our privacy policy\n";
		blValid = false;
	}
	
	if (blValid) {
		if (txtselcountry == 'redinfo@red-usa.com') {
			document.frmPartnerReferral.action = 'http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8' //http://www.salesforce.com/
		}
		document.frmPartnerReferral.submit();
	}
	else {
		window.alert (strError);
		return (false);
	}	
}

function validateGoldSupport() {
	var blValid = true;
	var strError = 'Please ensure the following form fields are completed before proceeding:\n\n';
	
	txtcompany = document.frmGoldSupport.txtcompany.value;
	txtcontact = document.frmGoldSupport.txtcontact.value;
	txttelephone = document.frmGoldSupport.txttelephone.value;
	txtcomments = document.frmGoldSupport.txtcomments.value;

	if ((txtcompany == '')) {
		strError = strError + "Your Company\n";
		blValid = false;
	}

	if ((txtcontact == '')) {
		strError = strError + "Your Contact\n";
		blValid = false;
	}

	if ((txttelephone == '')) {
		strError = strError + "Your Phone Number\n";
		blValid = false;
	}

	if ((txtcomments == '')) {
		strError = strError + "Your Comments\n";
		blValid = false;
	}
	
	if (txtcomments.length > 88) {
		strError = strError + "Please shorten the description\n";
		blValid = false;
	}

	if (blValid) {
		document.frmGoldSupport.submit();
	}
	else {
		window.alert (strError);
		return (false);
	}	
}
