var form=false;
var atomicLocations = new Array();
atomicLocations['central'] = new Array();
atomicLocations['central']['height']="53px";
atomicLocations['central']['image']="Central";
atomicLocations['central']['title']="Atomic Watch CO - Adelaide";
atomicLocations['central']['address']="Atomic - Shop LG 12, Adelaide Central Plaza<br /100 Rundle Mall, Adelaide SA 5000>";
atomicLocations['central']['phone']="Phone: (08) 8223 4541<br /><a href=\"mailto:atomic@shades.net.au\">atomic@shades.net.au</a>";

function updateLocation(loc){
	if(form==true){
	document.getElementById("mainArea").innerHTML="<img src=\"blank.gif\" alt=\"Atomic Store\" width=\"394\" height=\"384\" id=\"locPic\" />";
	document.getElementById("subArea").innerHTML="<div id=\"addressInfo\"><h2 id=\"title\"></h2><p id=\"address\"></p></div><div id=\"phoneInfo\"></div>";
	}
	var img="images/atomicLoc-"+atomicLocations[loc]['image']+".jpg";
	document.getElementById("locPic").src=img;
	document.getElementById("title").innerHTML=atomicLocations[loc]['title'];
	document.getElementById("address").innerHTML=atomicLocations[loc]['address'];
	document.getElementById("subArea").style.height=atomicLocations[loc]['height'];
	document.getElementById("phoneInfo").innerHTML=atomicLocations[loc]['phone'];
	form=false;
}
function displayEnquiryForm(){
	form=true;
	document.getElementById("subArea").innerHTML="<p style=\"font-size:9px; letter-spacing:0.5px;\">Disclaimer: Shades respects your privacy and will not give out your personal information. Shades will use the information you provide, in accordance with your enquiry or application. We may also contact you from time to time with news on our products and services, and special offers!</p>";
	
	document.getElementById("mainArea").innerHTML="<h2>Hi there, how may we help you?</h2><form action=\"formSubmit.php\" method=\"post\" enctype=\"multipart/form-data\" name=\"enquiryForm\" onsubmit=\"return ValidateForm(this);\"><div id=\"formArea\"><br /><label><span>*</span>Hi, my name is:</label><input name=\"txtName\" id=\"txtName\" type=\"text\" /><label id=\"dob\">Date of Birth:</label><input name=\"txtDob\" id=\"txtDob\" type=\"text\" /><br /><br /><label>I'm enquiring about:</label><select name=\"lstEnquiry\" id=\"lstEnquiry\"><option value=\"general\">General Enquiry</option><option value=\"job\">Job Application</option></select><br /><br /><label><span>*</span>My email is:</label><input name=\"txtEmail\" id=\"txtEmail\" type=\"text\" /><br /><br /><label>Mobile number:</label><input name=\"txtMobile\" id=\"txtMobile\" type=\"text\" /><label id=\"state\">State:</label><select name=\"lstState\" id=\"lstState\"><option value=\"SA\">SA</option><option value=\"VIC\">VIC</option><option value=\"QLD\">QLD</option></select><br /><br /><label>Message:</label><br /><br /><textarea name=\"txtMessage\" cols=\"\" rows=\"\"></textarea><br /><br /><label>Resume upload:<br />(if job enquiry)</label><input name=\"fileResume\" type=\"file\" id=\"fileResume\" /><br /><br /><input name=\"Reset\" type=\"reset\" value=\"Reset\" id=\"resetBut\" /><input name=\"Submit\" type=\"submit\" value=\"Submit\" id=\"submitBut\" /></div></form>";
}

/////////////////////////////////////////////////////////////////
//Checks that a passed string is an email address
function isEmail(str) {
    // are regular expressions supported?
    var supported = 0;
    if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
   }
   if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

var name="";
var email="";
var dob="";
var mob="";
var msg="";


/////////////////////////////////////////////////////////////////
//Main code to validate the form
function ValidateForm(obj){

    var errs=0;
	var errMsg="";
	
	
	
	if((obj.txtName.value.length==0) || (obj.txtName.value==null))
	{
		errs+=1;	
	}

   if(!isEmail(obj.txtEmail.value))
    	{
			errs+=1;	
		}
	
	if(errs>0)
	{	tmp=document.getElementById('mainArea').innerHTML;
	name=obj.txtName.value;
	email=obj.txtEmail.value;
	dob=obj.txtDob.value;
	mob=obj.txtMobile.value;
	msg=obj.txtMessage.value;
		document.getElementById('mainArea').innerHTML="<h2>Hi there, how may we help you?</h2><img src=\"images/oops.gif\" height=\"142\" width=\"326\" id=\"oops\" /><a href=\"#\" onclick=\"displayEnquiryFormWithErrors();\" id=\"goback\">back</a>";	
		return false;
	}
	else
	{
		return true;
	}
    
}

function displayEnquiryFormWithErrors(){
document.getElementById('mainArea').innerHTML=tmp;
document.enquiryForm.txtName.value=name;
document.enquiryForm.txtEmail.value=email;
document.enquiryForm.txtDob.value=dob;
document.enquiryForm.txtMobile.value=mob;
document.enquiryForm.txtMessage.value=msg;

//var spans=document.getElementById('mainArea').getElementsByTagName("span");
//		var i;
//		for(i=0;i<spans.length;i++){
//		spans[i].style.color="rgb(255,26,92)";
//		spans[i].style.display="inline";
//		alert('test');
	//	}
}