function showHelp(mode)
{
	switch(mode)
	{
	case 0: 
		document.all['ts_help'].style.display = 'none'; 
		break;
	case 1:
		document.all('ts_help_txt').innerHTML = "<b>Trade: </b>Select a trade from this list. You can choose from a more extensive list by selecting the 'none of these...' option at the bottom of the list.";
		document.all['ts_help'].style.top = 50; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 2:
		document.all('ts_help_txt').innerHTML = "<b>Location: </b>Enter either your suburb name or postcode. We will find tradesmen close this place.";
		document.all['ts_help'].style.top = 120; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 3: 
		document.all('ts_help_txt').innerHTML = "<b>Value: </b>Choose an approximate value of the job. Do not underestimate the value, since this will discourage trades from seeking your job - you can negotiate the best price once you have found an interested subbie.";
		document.all['ts_help'].style.top = 65; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 4: 
		document.all('ts_help_txt').innerHTML = "<b>When: </b>Select how soon you need the job done. Keep in mind most subbies are busy, so give them a little time to finish the job they are on.";
		document.all['ts_help'].style.top = 150; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 5: 
		document.all('ts_help_txt').innerHTML = "<b>Description: </b>Provide a very brief description of the job. You can see examples of other peoples jobs by clicking the 'Examples' link.";
		document.all['ts_help'].style.top = 195; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 6: 
		document.all('ts_help_txt').innerHTML = "<b>Email: </b>Tell us your email address and we will send you the replies from the subbies for your records.";
		document.all['ts_help'].style.top = 385; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	case 7: 
		document.all('ts_help_txt').innerHTML = "<b>Mobile: </b>Provide your mobile number and we will SMS their replies to you. You can list your land-line number, but we will not be able to send you SMS notifications as they arrive.";
		document.all['ts_help'].style.top = 345; 
		document.all['ts_help'].style.display = 'block'; 
		break;
	default:
		alert('other'+ mode);
		break;
	}
}	

function checkTrade(){
	var txt = document.frm.trade[document.frm.trade.selectedIndex].value;
	switch(txt)
	{
	case "0": 
		alert("No Problem. BANGitUP will process this job when we have had a chance to look at it and determine the apprpriate trades to send it to.")
		break;
	case "-1":
		alert("No problem. We will help you search for the less frequently used trades on the next page.")
		break;
	default:
		//nothing
		break;
	}
}


function removeHelp(cntrl){
	if(document.all[cntrl].value == 'Type a short job description here')
		document.all[cntrl].value = '';
}
	
function showTab(tab){
	document.all["tab1"].style.display = "none";
	document.all["tab2"].style.display = "none";
	document.all["tab3"].style.display = "none";
	document.all["tab" + tab].style.display = "block";
}

function checkMobileNumer(mob){
	mob = mob.replace(/ /g, '')
	var msg = "";
	if (mob.substr(0,2)!='04' &&  mob.substr(0,2)!='05') {msg = msg + "\n- Does not start with a mobile number prefix 04 or 05" }
	if (mob.length!=10)                                  {msg = msg + '\n- Is not the correct number of digits for a mobile number'}
	if (msg.length!=0)                                   {msg = 'ERROR: you must specify a valid mobile number to use tradeSelect' + msg; alert(msg);}
}

function isMobileNumber(mob){
	mob = mob.replace(/ /g, '')
	if (mob.substr(0,2)!='04' &&  mob.substr(0,2)!='05') {return false;}
	if (mob.length!=10)                                  {return false;}
	return true;
}

function checkEmail(str){
	if(!isEmail(str)){alert("ERROR: you must enter a valid email address")}
}

function isEmail(str){
	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,}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


function validateForm(){
		//alert(document.frm.trade.selectedIndex);
		//alert(document.frm.trade[document.frm.trade.selectedIndex].value);
	if (document.frm.trade[document.frm.trade.selectedIndex].value=='')
		{alert ('please select a trade'); return false};
	if (document.frm.suburb.value.length==0)
		{alert ('please enter a suburb or postcode'); return false};
	if (document.frm.desc.value=='')
		{alert ('please provide a description'); return false};
	if (document.frm.value.selectedIndex==0)
		{alert ('please select a value'); return false};
	if (document.frm.start.selectedIndex==0)
		{alert ('please select a start timeframe'); return false};
	if (!isEmail(document.frm.email.value))
		{alert ('please provide your email address'); return false};
	if (!isMobileNumber(document.frm.mobile.value))
		{alert ('please provide your mobile number'); return false};
	if (!checkShortDescription2())
		{return false};
	document.frm.submit();
}


function checkOther(){
	//if (document.frm.trade[document.frm.trade.selectedIndex].value=="")
	//	{window.open('http://tradeselect.BANGitUP.com/ts.aspx?page=trades', 'tradesList', 'toolbar=no, scrollbars=yes, resizable=yes, width=300')};
	checkTrade();
}


function showSMS(){
	var txt="";
	if (document.frm.trade.selectedIndex !=0)
		{txt=txt + document.frm.trade[document.frm.trade.selectedIndex].text + " wanted"};
	if (document.frm.suburb.value !='')
		{txt=txt + " in " + document.frm.suburb.value}
	if (document.frm.desc.value !='')
		{txt=txt + ", " + document.frm.desc.value + ""}
	//if (document.frm.value.selectedIndex !=0)
	//	{txt=txt + " (" + document.frm.value[document.frm.value.selectedIndex].text + ")"}
	if (document.frm.start.selectedIndex !=0)
		{txt=txt + ". " + document.frm.start[document.frm.start.selectedIndex].text}
	txt = txt + ". Interested? SMS Reply or phone 1300796279"
	tsPhoneTxt1.innerHTML=txt;
	checkShortDescription();
}


function numChars(){
	var nc;
	nc = (document.frm.trade[document.frm.trade.selectedIndex].text.length + 7)
		+ (document.frm.suburb.value.length + 4)
		+ 2
		+ (document.frm.start[document.frm.start.selectedIndex].text.length +1)
		+ 43;
	return nc;
}

function checkShortDescription(){
	var txt;
	txt = tsPhoneTxt1.innerHTML;
	document.frm.desc.maxlength = 160 - numChars();
	document.frm.charsremaining.value = document.frm.desc.maxlength - document.frm.desc.value.length;
	//document.frm.desc.value = document.frm.desc.value.substring(1,160);
	if (document.frm.desc.value.length>document.frm.desc.maxlength)
		{alert("The Very Short Description is too long, please make it "
			+ (document.frm.desc.value.length-document.frm.desc.maxlength)
			+ " characters shorter");
			return false;
		}
		else
		{return true;}
}

function checkShortDescription2(){
	var txt;
	txt = document.frm.desc.value
	if(txt=="Type a short job description here"){
		alert("Please enter a job description")
		return false;
	}
	return checkShortDescription();
}


function reloadMe(){
	var url;
	url = "rfq.html";
	url = url + "?trade=" + document.frm.trade.selectedIndex;
	url = url + "&region=" + document.frm.region.value;
	url = url + "&value=" + document.frm.value.selectedIndex;
	url = url + "&start=" + document.frm.start.selectedIndex;
	url = url + "&email=" + document.frm.email.value;
	url = url + "&mobile=" + document.frm.mobile.value;
	window.location=url;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  //alert('Query Variable ' + variable + ' not found');
  return null;
}

function addscript()
{
	oScr = document.createElement("SCRIPT");
	oScr.language = 'javascript';
	oScr.src = 'test.js';
	document.body.appendChild(oScr);
}

function populatePulldowns(){
	// populatePulldowns
	var x;
	var p;

	x=document.frm.trade; p=0;
	x.options[++p] = new Option("Architect", "139");
	x.options[++p] = new Option("Airconditioning", "116");
	x.options[++p] = new Option("Bricklayer", "37");
	x.options[++p] = new Option("Builder", "230");
	x.options[++p] = new Option("Cabinetmaker", "61");
	x.options[++p] = new Option("Carpenter", "122");
	x.options[++p] = new Option("Concretor", "25");
	x.options[++p] = new Option("Drainer", "314");
	x.options[++p] = new Option("Drafting Service", "303");
	x.options[++p] = new Option("Electrician", "223");
	x.options[++p] = new Option("Excavator", "18");
	x.options[++p] = new Option("Fencing & Gates", "329");
	x.options[++p] = new Option("Floor/Wall Tiler", "87");
	x.options[++p] = new Option("Formworker", "26");
	x.options[++p] = new Option("Gasfitter", "174");
	x.options[++p] = new Option("Glazier", "83");
	x.options[++p] = new Option("Handyman", "1960");
	x.options[++p] = new Option("Joinery", "61");
	x.options[++p] = new Option("Labourer", "1880");
	x.options[++p] = new Option("Landscaper", "35");
	x.options[++p] = new Option("Metalworker", "41");
	x.options[++p] = new Option("Metal Roofer", "72");
	x.options[++p] = new Option("Painter n Decorator", "99");
	x.options[++p] = new Option("Paver", "104");
	x.options[++p] = new Option("Plasterer", "77");
	x.options[++p] = new Option("Plumber", "174");
	x.options[++p] = new Option("Reo Fixer", "28");
	x.options[++p] = new Option("Renderer", "90");
	x.options[++p] = new Option("Roof Plumber", "1680");
	x.options[++p] = new Option("Roof Tiler", "73");
	x.options[++p] = new Option("Roof Guttering", "1680");
	x.options[++p] = new Option("Staircase Mfr", "62");
	x.options[++p] = new Option("Steel Roofer", "72");
	x.options[++p] = new Option("Stone Mason", "1474");
	x.options[++p] = new Option("Waterproofer", "1340");
	x.options[++p] = new Option("I DONT KNOW", "0");
	x.options[++p] = new Option("NONE OF THESE ...", "-1");

	if(getQueryVariable("trade")!=null){x.selectedIndex=getQueryVariable("trade")}

	x=document.frm.value; p=0;
	x.options[++p] = new Option("Less than $2k", "0");
	x.options[++p] = new Option("$2k to $10k", "1");
	x.options[++p] = new Option("$10k to $25k", "2");
	x.options[++p] = new Option("$25k to $100k", "3");
	x.options[++p] = new Option("$100 to $500k", "A");
	x.options[++p] = new Option("$500k to $3m", "B");
	x.options[++p] = new Option("$3m to $6m", "C");
	x.options[++p] = new Option("$6m to $20m", "D");

	if(getQueryVariable("value")!=null){x.selectedIndex=getQueryVariable("value")}

	x=document.frm.start; p=0;
	x.options[++p] = new Option("Start ASAP Today", "0");
	x.options[++p] = new Option("Start Tomorrow", "1");
	x.options[++p] = new Option("Start within 7 days", "7");
	x.options[++p] = new Option("Start within 14 days", "14");
	x.options[++p] = new Option("Start within 30 days", "30");
	x.options[++p] = new Option("Start after 30 days", "90");
	if(getQueryVariable("start")!=null)
		{x.selectedIndex=getQueryVariable("start")}
	else
		{x.selectedIndex=4}

	if(getQueryVariable("email")!=null){document.frm.email.value=getQueryVariable("email")}
	if(getQueryVariable("mobile")!=null){document.frm.mobile.value=getQueryVariable("mobile")}
	if(window.location.search.length>0){showSMS()}
}


function addTrade(trdID, Desc){
	var trdLen = document.frm.trade.length;
	document.frm.trade.options[trdLen] = new Option(Desc, trdID);
	document.frm.trade.selectedIndex = trdLen;
}

//checkShortDescription();

function testTime(cntrl){
	var msg;
	var idx = cntrl.selectedIndex;
	if(idx==0){return true};
	if(idx>3) {return true};
	if(idx<4) {msg = "Most tradesmen are busy, and usually have work booked at least a week into the future.\n"};
	if(idx==3){msg = msg + "You might be lucky and find someone available this week.\n"};
	if(idx==2){msg = "Good luck... \n" + msg + "You might be lucky and find someone available tomorrow.\n"};
	if(idx==1){msg = "You're dreamin'... \n" + msg + "You might be lucky and find someone available today, but we can not guarantee anyone will reply.\n"};
	msg = msg + "Jobs 'within 30 days' get the most replies from our tradesmen.";
	alert(msg);
}

populatePulldowns()