/**************************************/
/*
Unite and Rule JavaScript
CopyrightŠUnite and Rule Ltd.
*/
/**************************************/

/**************************************/
/* Swap the active CSS */
function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) a.disabled = true;
			if (a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

/**************************************/
/* Counter */
var countContainer=0;
var currentSeconds=0;
var countPause=20;

function ActivateCount(strContainerID, initialValue) {
    countContainer = document.getElementById(strContainerID);
    SetCountText(initialValue);
    window.setTimeout("CountTick()", countPause);
}
 
function CountTick() {
    if (currentSeconds >= 123) {
        return; //skip count
    }
    SetCountText(currentSeconds+1);
    window.setTimeout("CountTick()", countPause);
}
 
function SetCountText(seconds) {
    currentSeconds = seconds;
    var strText = AddZero(seconds);
    countContainer.innerHTML = strText;
}
 
function AddZero(num) {
    num = ((num >= 0)&&(num < 10))?"0"+num:num+"";
    num = ((num >= 0)&&(num < 100))?"0"+num:num+"";
	return num;
} 

/*window.onload=WindowLoad;
function WindowLoad(event) {
    ActivateCount("CountPanel", 0);
}*/

/**************************************/
/* Registration Validation */
function validateRegistration(oForm) {
	var bValid = true;
/*
	//check for security code
	if (oForm.code.value.length < 4) {
		alert('Please enter the security code');
		return false;
	}
*/

	//check normal form
	if (oForm.contactName.value == '' ||
		oForm.businessName.value == '' ||
		oForm.address1.value == '' || 
		oForm.postcode.value == '' || 
		oForm.telephone.value == '' ||
		oForm.website.value == '') {
		bValid = false;
	}
	
	//check business category
	if (oForm.category.options[oForm.category.selectedIndex].text == 'Please Select') {
		alert('Please select a category for your business');
		return false;
	}

	//check email
	if (validateEmail(oForm.email) == false) {
		alert('Please enter a valid email address');
		return false;
	}
	if (oForm.email.value != oForm.emailConfirm.value) {
		alert('Your email address and confirmation do not match');
		return false;
	}

	//check for registration and password
	if (oForm.password.value.length < 5) {
		alert('Your password must be 5 or more characters');
		return false;
	}
	if (oForm.password.value != oForm.passwordConfirm.value) {
		alert('Your password and confirmation do not match');
		return false;
	}

	//return correctly
	if (bValid == false) {
		alert('Please fill out all fields');
		return false;
	}

	return true;
}

/**************************************/
/* Account Details Validation */
function validateAccountDetails(oForm) {
	var bValid = true;

	//check normal form
	if (oForm.contactName.value == '' ||
		oForm.businessName.value == '' ||
		oForm.address1.value == '' || 
		oForm.postcode.value == '' || 
		oForm.telephone.value == '') {
		bValid = false;
	}

	//check password
	if (oForm.currentPassword.value == '') {
		alert('You must enter your current password to update any account information.');
		return false;
	}

	//return correctly
	if (bValid == false) {
		alert('Please fill out all fields');
		return false;
	}

	return true;
}

/**************************************/
/* Login Detail Validation */
function validateLoginDetails(oForm) {
	var bValid = true;

	//check email
	if (validateEmail(oForm.email) == false) {
		alert('Please enter a valid email address');
		return false;
	}
	if (oForm.email.value != oForm.emailConfirm.value) {
		alert('Your email address and confirmation do not match');
		return false;
	}

	//check for registration and password
	if (oForm.password.value.length < 5) {
		alert('Your password must be 5 or more characters');
		return false;
	}
	if (oForm.password.value != oForm.passwordConfirm.value) {
		alert('Your password and confirmation do not match');
		return false;
	}

	//check password
	if (oForm.currentPassword.value == '') {
		alert('You must enter your current password to update any account information.');
		return false;
	}

	return true;
}

/**************************************/
/* Referral Link Request Validation */
function validateRequest(oForm) {

	if (oForm.understand.checked == false) {
		alert('You must check the box to indicate that you understand that requesting a link does not guarantee it will be accepted by the receiver in order to submit a request.');
		return false;
	}

	return true;
}

/**************************************/
/* Testimonial Validation */
function validateTestimonial(oForm) {

	if (oForm.testimonial.value.length <= 25) {
		alert('That\'s not much! ... we would be really greatful if you could write just a little more.');
		return false;
	}

	//check score
	if (oForm.score.options[oForm.score.selectedIndex].text == 'Please Select') {
		alert('Please specify a satisfaction score for the member.');
		return false;
	}

	return true;
}

/**************************************/
/* SEO Company Review Validation */
function validateReview(oForm) {

	if (oForm.review.value.length <= 25) {
		alert('That\'s not much! ... we would be really greatful if you could write just a little more.');
		return false;
	}

	//check score
	if (oForm.score.options[oForm.score.selectedIndex].text == 'Please Select') {
		alert('Please specify a satisfaction score for the company.');
		return false;
	}

	return true;
}

/**************************************/
/* SEO Company Consideration Validation */
function validateConsideration(oForm) {

	if (oForm.companyName.value.length <= 5) {
		alert('Please give the name of the SEO company you wish to submit for consideration.');
		return false;
	}

	if (oForm.websiteURL.value.length <= 5) {
		alert('Please specify the full URL of the SEO companies website, including the http:// bit.');
		return false;
	}

	if (oForm.review.value.length <= 25) {
		alert('That\'s not much! ... we would be really greatful if you could write just a little more.');
		return false;
	}

	//check score
	if (oForm.score.options[oForm.score.selectedIndex].text == 'Please Select') {
		alert('Please specify a satisfaction score for the company.');
		return false;
	}

	return true;
}

/**************************************/
/* validate contact form */
function validateContact(oForm) {
	var bValid = true;

	//check for security code
	if (oForm.code.value.length < 4) {
		alert('Please enter the security code');
		return false;
	}

	//check email
	if (validateEmail(oForm.email) == false) {
		alert('Please enter a valid email address');
		return false;
	}

	return true;
}

/**************************************/
/* validate the email field */
function validateEmail(field) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) { return false; }
		else { return true; }
	}
}

