function openWindow( tURL, tWidth, tHeight )
{
	var tName = Math.ceil(Math.random()*100);
	window.open(tURL, tName, "width=" + tWidth + ",height=" + tHeight + ",scrollbars=yes" );
}


$(function(){
		var filePath = $("#filePath").html();

		$("#navigation .navItem a")
		.mouseover(function(){
			var nav = $(this).attr("rel");
			if($(this).find("img").attr("src") != filePath+"/_images/nav_"+nav+"_on.gif"){
				$(this).find("img").attr("src", filePath+"/_images/nav_"+nav+"_over.gif");
			}
		})
		.mouseout(function(){
			var nav = $(this).attr("rel");
			if($(this).find("img").attr("src") != filePath+"/_images/nav_"+nav+"_on.gif"){
				$(this).find("img").attr("src", filePath+"/_images/nav_"+nav+"_off.gif");
			}
		});
});

// JavaScript Document
insurers = new Array();
insurers[0] = "AAMI";
insurers[1] = "Suncorp";
insurers[2] = "Allianz";
insurers[3] = "GIO";
insurers[4] = "RAA";
insurers[5] = "RACQ";
insurers[6] = "RACT";
insurers[7] = "RAC";

repairerRel = new Array();
repairerRel[0] = "Financial";
repairerRel[1] = "Partnership";
repairerRel[2] = "Director";
repairerRel[3] = "Family";
repairerRel[4] = "Other";

function validateDetailsForm(details){
	f = document.forms["detailsForm"];
	var x = f;
	err="";

	if(details==true && f.abNumber.value=="") err+="Please enter your Australian Business Number\n";
	if(details==true && f.companyName.value=="") err+="Please enter your Company Name\n";
	if(f.contactName.value=="") err+="Please enter your Contact Name\n";
	if(details==true && f.businessAddress.value=="") err+="Please enter your Business Address\n";
	if(validEmail(f.emailAddress.value)==false) err+="Please enter a valid Email Address\n";
	if(f.emailAddress.value!=f.emailAddressConfirm.value) err+="Email Addresses do not match\n";
	if(f.postcode.value.value=="") err+="Please enter your Postcode\n";

	if(err!=""){
		alert(err);
	}else{
		f.submit();
	}
}

function gotoSurvey(){
	f = document.forms["submit"];

	f.submit();

}


function validateForm(){
	f = document.forms["questionnaire"];
	err="";

	if(f.otherInsurer[0].checked!=true && f.otherInsurer[1].checked!=true) err+="Please select if you are currently part of another insurers repairer network\n";

	// check repairers
	if(f.otherRepairers[0].checked!=true && f.otherRepairers[1].checked!=true) err+="Please select if you currently have an interest in any other smash repair facilities?\n";
	if(f.otherRepairers[0].checked==true){
		for(i=0;i<otherRepairersArray.length; i++){
			if(otherRepairersArray[i][0]=="") err+="Please choose a repairer name (question 2, item #"+(i+1)+")\n";
		}
	}

	if(f.previouslyApplied[0].checked!=true && f.previouslyApplied[1].checked!=true) err+="Please select if you have previously applied for a repairer status with us\n";
	if(f.previouslyApplied[0].checked==true && f.previouslyAppliedMonth.value=="") err+="Please select the month you have previously applied for a repairer status with us\n";
//	if(f.previouslyApplied[0].checked==true && f.previouslyAppliedYear.value=="") err+="Please select the year you have previously applied for a repairer status with us\n";
	if(f.previousRel[0].checked!=true && f.previousRel[1].checked!=true) err+="Please select if you have previously had a relationship with us\n";
	//if(f.catchmentState.value=="" || f.catchmentSuburb.value=="") err+="Please enter your catchment area state and suburb/postcode\n";
	if(f.measureSatis[0].checked!=true && f.measureSatis[1].checked!=true) err+="Please select if you currently measure your customers' satisfaction with your service levels\n";
	if(f.measureSatis[0].checked==true && f.measureSatisSupplyData[0].checked!=true && f.measureSatisSupplyData[1].checked!=true) err+="Please select if you can supply data on customer satisfaction\n";
	if(f.measureQuality[0].checked!=true && f.measureQuality[1].checked!=true) err+="Please select if you currently have a process in place to measure and/or control your quality\n";
	if(f.measureQuality[0].checked==true && f.measureQualitySupplyData[0].checked!=true && f.measureQualitySupplyData[1].checked!=true) err+="Please select if you can supply data on your quality control processes\n";
	if(f.measureCosts[0].checked!=true && f.measureCosts[1].checked!=true) err+="Please select if you currently have a process in place to measure and/or control your costs\n";
	if(f.measureCosts[0].checked==true && f.measureCostsSupplyData[0].checked!=true && f.measureCostsSupplyData[1].checked!=true) err+="Please select if you can supply data on your cost control processes\n";
	if(f.staffTraining[0].checked!=true && f.staffTraining[1].checked!=true) err+="Please select if you currently have a staff training program in place\n";
	if(f.staffTraining[0].checked==true && f.staffTrainingSupplyData[0].checked!=true && f.staffTrainingSupplyData[1].checked!=true) err+="Please select if you can supply data on your staff training processes\n";
	if(f.apprenticeProg[0].checked!=true && f.apprenticeProg[1].checked!=true) err+="Please select if you currently have an apprenticeship program in place\n";
	if(f.apprenticeProg[0].checked==true && f.apprenticeProgSupplyData[0].checked!=true && f.apprenticeProgSupplyData[1].checked!=true) err+="Please select if you can supply data on your apprentice program\n";
	if(f.codeOfConduct[0].checked!=true && f.codeOfConduct[1].checked!=true)err+="Please select if you are a signatory to the Motor Vehicle Insurers and Repairer Industry voluntary code of conduct\n";

	if(err!=""){
		alert(err);
	}else{
		f.submit();
	}
}

function validEmail(email) {
	invalidChars = " /:,;"
	if(email=="") {
		return false;
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) {
		  return false;
		}
	}
	atPos=email.indexOf("@",1);
	if(atPos == -1) {
		return false;
	}
	if(email.indexOf("@", atPos+1) !=-1) {
		return false;
	}
	periodPos=email.indexOf(".", atPos+1)
	if(periodPos==-1) {
		return false;
	}
	if(periodPos+3>email.length) {
		return false;
	}
	atPos2=email.indexOf("@.",1);
	if(atPos2 != -1) {
		return false;
	}
	return true;
}


function placeForm(field){
	f = document.forms.questionnaire[field];
	c = document.getElementById(field+'Content');

	if(f[0].checked==true){
		if(field=="otherInsurer"){
			c.innerHTML=html='';
			if(f[0].checked==true){
				c.style.visibility='visible';
				html='<div><div class="questions">Insurer name:<br/>';
				for(i=0;i<otherInsurerArray.length;i++){
					if(i<otherInsurerArray.length){
						val=otherInsurerArray[i];
					}else{
						val="";
					}
					html+='<select name="otherInsurer'+i+'" onChange="setInsurer('+i+')">';
					for(j=0;j<insurers.length;j++){
						html+='<option value="'+insurers[j]+'"'+((val==insurers[j])?" selected":"")+'>'+insurers[j]+'</option>';
					}
					html+='</select>';
					if(i!=0) html+='&nbsp;<img src="/_images/add_more_remove.gif" width="15" height="13" border="0" /> <a class="remove" href="javascript:removeInsurer('+i+');">remove</a>'
					html+='<br/>';
				}
				html+='</div><div class="questionAddName"><img src="/_images/add_more_plus.gif" width="15" height="13" border="0" />'
				+'If you have a business relationship with more than one insurer, <a href="javascript:addInsurer();">click here to add another name</a>.'
				+'</div></div>';
				c.style.display='block';
				c.innerHTML=html;
			}
		}else if(field=="otherRepairers"){
			c.innerHTML=html='';

			if(f[0].checked==true){
				c.style.visibility='visible';
				html='<div><div class="questions">'
				+'<table cellpadding="0" cellspacing="0" border="0">'
				+'<tr>'
				+'<td>Repairer name:</td><td>&nbsp;</td><td>Type of relationship</td></tr>';

				for(i=0;i<otherRepairersArray.length;i++){
					if(i<otherRepairersArray.length){
						val0=otherRepairersArray[i][0];
						val1=otherRepairersArray[i][1];
					}else{
						val0=val1="";
					}
					html+='<tr><td valign="bottom"><input type="text" style="width:130px;" name="repairerName'+i+'" value="'+val0+'" onchange="setRepairer('+i+')" /></td><td>&nbsp;</td>';
					html+='<td><select name="repairerRel'+i+'" onchange="setRepairer('+i+')">';

					for(j=0;j<repairerRel.length;j++){
						html+='<option'+((val1==repairerRel[j])?" selected":"")+'>'+repairerRel[j]+'</option>';
					}
					html+='</select>';
					if(i!=0) html+='<a class="remove" href="javascript:removeRepairer('+i+');"><img src="/_images/add_more_remove.gif" width="15" height="13" border="0" /> remove</a>'
					html+='</td></tr>';
				}

				html+='</table></div><div class="questionAddName"><img src="/_images/add_more_plus.gif" width="15" height="13" border="0" />'
				+'If you have a relationship with more than one repairer, <a href="javascript:addRepairer();">click here to add another name</a>.'
				+'</div></div>';
				c.style.display='block';
				c.innerHTML=html;
			}
		}
	}else{
		c.style.display='none';
		c.style.visibility='hidden';
	}
}

function showContent(what, show){
	what=document.getElementById(what).style;
	if(show==true){
		what.visibility='visible';
		what.display='block';
	}else{
		what.visibility='hidden';
		what.display='none';
	}
}

function addInsurer(){
	if(otherInsurerArray.length<insurers.length){
		otherInsurerArray.push("");
		placeForm("otherInsurer");
	}
}

function addRepairer(){
	if(otherRepairersArray.length<10){
		otherRepairersArray.push(["",""]);
		placeForm("otherRepairers");
	}
}

function removeInsurer(n){
	if(n!=0 && n<otherInsurerArray.length){
		otherInsurerArray.splice(n,1);
		placeForm("otherInsurer");
	}
}
function removeRepairer(n){
	if(n!=0 && n<otherRepairersArray.length){
		otherRepairersArray.splice(n,1);
		placeForm("otherRepairers");
	}
}
function setInsurer(n){
	if(n<otherInsurerArray.length) otherInsurerArray[n]=document.forms.questionnaire['otherInsurer'+n].value;
}
function setRepairer(n){
	if(n<otherRepairersArray.length){
		otherRepairersArray[n][0]=document.forms.questionnaire['repairerName'+n].value;
		otherRepairersArray[n][1]=document.forms.questionnaire['repairerRel'+n].value;
	}
}

function getContentLines(line,ar){
	html='';
	for(i=0;i<ar.length;i++){
		html+=line;
	}
	return html;
}

function setFormArrays(){
	otherInsurerArray = new Array(1);
	otherRepairersArray = new Array(["",""]);
}

function imRoll(way, what, type){
	document.images[type+'_'+what].src=path+'/_images/'+type+'_'+what+'_'+way+'.gif';
}

function sfHover() {

	var buttonDiv = document.getElementById("buttonDiv");
	if(buttonDiv!=null){
		buttonDiv.onmouseover=function() {
			document.getElementById("arrow").style.backgroundImage = 'url('+path+'/_images/button_arrow_over.gif)';
			document.getElementById("buttoncontent").style.backgroundImage = 'url('+path+'/_images/button_bg_over.gif)';
			document.getElementById("right").style.backgroundImage = 'url('+path+'/_images/button_right_over.gif)';
		}
		buttonDiv.onmouseout=function() {
			document.getElementById("arrow").style.backgroundImage = 'url('+path+'/_images/button_arrow_off.gif)';
			document.getElementById("buttoncontent").style.backgroundImage = 'url('+path+'/_images/button_bg_off.gif)';
			document.getElementById("right").style.backgroundImage = 'url('+path+'/_images/button_right_off.gif)';
		}
	}

}
if (window.attachEvent) window.attachEvent("onload", sfHover);

im1 = new Image();
im1.src=path+'/_images/button_arrow_over.gif';
im2 = new Image();
im2.src=path+'/_images/button_bg_over.gif';
im3 = new Image();
im3.src=path+'/_images/button_right_over.gif';
im4 = new Image();
im4.src=path+'/_images/button_arrow_off.gif';
im5 = new Image();
im5.src=path+'/_images/button_bg_off.gif';
im6 = new Image();
im6.src=path+'/_images/button_right_off.gif';

