// JavaScript Document

function validate(objForm){
	if(objForm.email.value==""){
		objForm.email.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.email.value)){
		objForm.email.focus();
		return false;
	}
}

function validateSubscribe(objForm){
	if(objForm.txtFirstname.value==""){
		objForm.txtFirstname.focus();
		alert("Please enter your first name");
		return false;
	}
	if(objForm.txtLastname.value==""){
		objForm.txtLastname.focus();
		alert("Please enter your last name");
		return false;
	}
	/*
	if(objForm.txtAddress.value==""){
		objForm.txtAddress.focus();
		alert("Please enter your address.");
		return false;
	}
	if(objForm.txtSuburb.value==""){
		objForm.txtSuburb.focus();
		alert("Please enter your suburb.");
		return false;
	}*/
	if(objForm.ddlState.value==""){
		objForm.ddlState.focus();
		alert("Please select a state.");
		return false;
	}
	if(objForm.txtPostcode.value==""){
		objForm.txtPostcode.focus();
		alert("Please enter your a postcode.");
		return false;
	}
	if(isNaN(objForm.txtPostcode.value)){
		objForm.txtPostcode.focus();
		alert("Postcode may only contain numerals.");
		return false;
	}
	if(objForm.txtEmail.value==""){
		objForm.txtEmail.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.txtEmail.value)){
		objForm.txtEmail.focus();
		return false;
	}
	if(checkRadio(objForm.rbAge)==""){
		alert("Please specify your age range.");
		return false;
	}
	/*
	if(objForm.txtFeedback.value==""){
		objForm.txtFeedback.focus();
		alert("Please enter your feedback.");
		return false;
	}*/
	if(!objForm.cbTerms.checked){
		alert("You must agree with the terms and conditions to recieve further updates, by checking the 'I have read and agree with the terms and conditions' checkbox.");
		return false;
	}
}

function validateComp(objForm){
	
	if(objForm.txtFirstname.value==""){
		objForm.txtFirstname.focus();
		alert("Please enter your first name");
		return false;
	}
	if(objForm.txtLastname.value==""){
		objForm.txtLastname.focus();
		alert("Please enter your last name");
		return false;
	}
	if(objForm.ddlState.value==""){
		objForm.ddlState.focus();
		alert("Please select a state.");
		return false;
	}
	/*
	if(objForm.txtAddress.value==""){
		objForm.txtAddress.focus();
		alert("Please enter your address.");
		return false;
	}
	if(objForm.txtSuburb.value==""){
		objForm.txtSuburb.focus();
		alert("Please enter your suburb.");
		return false;
	}
	if(objForm.txtPostcode.value==""){
		objForm.txtPostcode.focus();
		alert("Please enter your a postcode.");
		return false;
	}
	if(isNaN(objForm.txtPostcode.value)){
		objForm.txtPostcode.focus();
		alert("Postcode may only contain numerals.");
		return false;
	}
	*/
	if(objForm.txtEmail.value==""){
		objForm.txtEmail.focus();
		alert("Please enter your email");
		return false;
	}
	if(!checkemail(objForm.txtEmail.value)){
		objForm.txtEmail.focus();
		return false;
	}
	if(checkRadio(objForm.rbAge)==""){
		alert("Please specify your age range.");
		return false;
	}
	if(objForm.txtHeight.value==""){
		objForm.txtHeight.focus();
		alert("Please enter your height");
		return false;
	}
	if(objForm.txtShoeSize.value==""){
		objForm.txtShoeSize.focus();
		alert("Please enter your shoe size");
		return false;
	}
	if(objForm.txtShoesYear.value==""){
		objForm.txtShoesYear.focus();
		alert("How many pairs of shoes do you buy in a year?");
		return false;
	}
	if(objForm.comp25words.value==""){
		objForm.comp25words.focus();
		alert("Please tell us in 25 words or less why you would love to win your height in Zensu shoes");
		return false;
	}
	if(checkWordSpaces(objForm.comp25words.value)>25){
		objForm.comp25words.focus();
		alert("Please tell us in 25 words or less.");
		return false;		
	}
	if(objForm.txtEmail1.value!=""){
		if(!checkemail(objForm.txtEmail1.value)){
			objForm.txtEmail1.focus();
			return false;
		}
	}
	if(objForm.txtEmail2.value!=""){
		if(!checkemail(objForm.txtEmail2.value)){
			objForm.txtEmail2.focus();
			return false;
		}
	}
	if(objForm.txtEmail3.value!=""){
		if(!checkemail(objForm.txtEmail3.value)){
			objForm.txtEmail3.focus();
			return false;
		}
	}
	if(!objForm.cbTerms.checked){
		alert("You must agree with the competiton terms and conditions by checking the checkbox to enter this competition.");
		return false;
	}
}

function checkWordSpaces(string){
	var spaceCount = 0;
	for(var i=1; i<string.length; i++){
		if(string.charAt(i)==" " || string.charAt(i)=="\r"){
			spaceCount += 1;
		}
	}
	return(spaceCount + 1);
}

function checkemail(strEmail){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(strEmail)){
		return true;
	}else{
		alert("Please enter a valid email address");
		return false;
	}
}
function checkRadio(radioObj) {
	var checkedValue = "";
	if(!radioObj)
		return checkedValue;
	var radioLength = radioObj.length;
	if(radioLength == undefined){
		if(radioObj.checked)
			return radioObj.value;
		else
			return checkedValue;
	}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			checkedValue = radioObj[i].value;
		}
	}
	return checkedValue;
}

var newwindow = '';
function newPopup(theURL,width,height,scrollbars) {
	x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = theURL;
	}
	else {
		newwindow=window.open(theURL,'newWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars='+scrollbars+',status=no,resizable=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
}


function show(object) {
	var obj = document.getElementById(object);
  if (obj != null)
	{
    obj = (obj.style) ? (obj.style):obj;
    obj.display = "block";
    obj.visibility = "visible";
   }
}



function hide(object) {
	var obj = document.getElementById(object);
	if (obj != null)
	{
     obj = (obj.style) ? (obj.style):obj;
	   obj.display = "none";
     obj.visibility = "hidden";  	 
	}
}

function writeInnerHTML(object,strHtml){
	var obj = document.getElementById(object);
	if (obj != null) obj.innerHTML = strHtml;
}


function showDetail(shoename){
	var obj = document.getElementById('shoeDetailImage');
	if(obj != null) obj.innerHTML = '<img src="images/detail/' + shoename + 'detail.jpg">';
	hide('zoomin');
	show('zoomout');
	show('shoeDetailOverlay');
	show('shoeDetailImage')
}

function hideDetail(shoename){
	var obj = document.getElementById('shoeDetailImage');
	if(obj != null) obj.innerHTML = '';
	show('zoomin');
	hide('zoomout');
	hide('shoeDetailOverlay');
	hide('shoeDetailImage')
}
