var form=false;
var tmp="";
var shadesLocations = new Array();
shadesLocations['admin'] = new Array();
shadesLocations['admin']['height']="53px";
shadesLocations['admin']['image']="Loc";
shadesLocations['admin']['title']="Shades - Administration";
shadesLocations['admin']['address']="";
shadesLocations['admin']['phone']="Phone: (08) 8232 6099";

shadesLocations['glenelg'] = new Array();
shadesLocations['glenelg']['height']="53px";
shadesLocations['glenelg']['image']="Glenelg";
shadesLocations['glenelg']['title']="Shades - Glenelg";
shadesLocations['glenelg']['address']="32 Jetty Road<br />Glenelg SA 5045";
shadesLocations['glenelg']['phone']="Phone: (08) 8294 5450<br /><a href=\"mailto:glenelg@shades.net.au\">glenelg@shades.net.au</a>";


shadesLocations['airport'] = new Array();
shadesLocations['airport']['height']="53px";
shadesLocations['airport']['image']="Airport";
shadesLocations['airport']['title']="Shades - Airport";
shadesLocations['airport']['address']="Shop 22, Terminal 2, 1 James Schofield Drive<br />Adelaide Airport SA 5950";
shadesLocations['airport']['phone']="Phone: (08) 8234 4116<br /><a href=\"mailto:airport@shades.net.au\">airport@shades.net.au</a>";

shadesLocations['rundle'] = new Array();
shadesLocations['rundle']['height']="53px";
shadesLocations['rundle']['image']="Rundle";
shadesLocations['rundle']['title']="Shades - Rundle Mall";
shadesLocations['rundle']['address']="101 Rundle Mall<br />Adelaide SA 5000";
shadesLocations['rundle']['phone']="Phone: (08) 8232 5588<br /><a href=\"mailto:rundlemall@shades.net.au\">rundlemall@shades.net.au</a>";

shadesLocations['chadstone'] = new Array();
shadesLocations['chadstone']['height']="53px";
shadesLocations['chadstone']['image']="Chadstone";
shadesLocations['chadstone']['title']="Shades - Chadstone";
shadesLocations['chadstone']['address']="Shop 320 Chadstone Shopping Centre<br />Chadstone VIC 3148";
shadesLocations['chadstone']['phone']="Phone: (03) 9568 5430<br /><a href=\"mailto:chaddy@shades.net.au\">chaddy@shades.net.au</a>";


shadesLocations['queensplaza'] = new Array();
shadesLocations['queensplaza']['height']="53px";
shadesLocations['queensplaza']['image']="BrisQueens";
shadesLocations['queensplaza']['title']="Shades - Brisbane Queens Plaza";
shadesLocations['queensplaza']['address']="Shop LG 18-226, Queen Street Mall<br />Brisbane QLD 4000";
shadesLocations['queensplaza']['phone']="Phone: (07) 3003 1663<br /><a href=\"mailto:queens@shades.net.au\">queens@shades.net.au</a>";

shadesLocations['fortitude'] = new Array();
shadesLocations['fortitude']['height']="53px";
shadesLocations['fortitude']['image']="TCB";
shadesLocations['fortitude']['title']="Shades - Fortitude Valley";
shadesLocations['fortitude']['address']="Shop 33 TCB Building, Brunswick Mall<br />Fortitude Valley QLD 4006";
shadesLocations['fortitude']['phone']="Phone: (07) 3252 7953<br /><a href=\"mailto:tcb@shades.net.au\">tcb@shades.net.au</a>";

shadesLocations['noosa'] = new Array();
shadesLocations['noosa']['height']="53px";
shadesLocations['noosa']['image']="Noosa";
shadesLocations['noosa']['title']="Shades - Noosa";
shadesLocations['noosa']['address']="Shop 2 Sandcastles at Noosa<br />1 Hastings Street, Noosa Heads QLD 4000";
shadesLocations['noosa']['phone']="Phone: (07) 5474 5822<br /><a href=\"mailto:noosa@shades.net.au\">noosa@shades.net.au</a>";

shadesLocations['SOchad'] = new Array();
shadesLocations['SOchad']['height']="53px";
shadesLocations['SOchad']['image']="Loc";
shadesLocations['SOchad']['title']="Street Optics - Chadstone";
shadesLocations['SOchad']['address']="116/117B Chadstone Shopping Centre<br />Chadstone VIC 3148";
shadesLocations['SOchad']['phone']="Phone: (03) 9568 8900<br /><a href=\"mailto:so@shades.net.au\">so@shades.net.au</a>";







function updateLocation(loc){
	if(form==true){
	document.getElementById("mainArea").innerHTML="<img src=\"blank.gif\" alt=\"Shades 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/Shades_"+shadesLocations[loc]['image']+".jpg";
	document.getElementById("locPic").src=img;
	document.getElementById("title").innerHTML=shadesLocations[loc]['title'];
	document.getElementById("address").innerHTML=shadesLocations[loc]['address'];
	document.getElementById("subArea").style.height=shadesLocations[loc]['height'];
	document.getElementById("phoneInfo").innerHTML=shadesLocations[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');
	//	}
}
