function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function printWindow() {
	window.print();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

function disable(formelement){
	formelement.disabled=true;
}

function subcatValidate(value){
    if(value == 'Do Not Own A Home') 
        alert("Sorry! If you are not a homeowner at this time, we cannot assist you.");

	if(value == 'Residential New Bond (With Credit Bureau Listings)') 
	   alert('Sorry! We cannot assist this category at this time, please try us in 6 months..');
}

function fillSubCategory(loanTypeElement, subcatElement){
    subcatElement.disabled=false;
	removeAllOptions(subcatElement);
	
	if(loanTypeElement.value == "Asset Finance") {
		addOption(subcatElement, 'Agricultural', 'Agricultural');
		addOption(subcatElement,  'Agricultural Equipment', 'Agricultural Equipment');
		addOption(subcatElement, 'Aircraft', 'Aircraft');
		addOption(subcatElement, 'Boats', 'Boats');
		addOption(subcatElement, 'Civil Engineering', 'Civil Engineering');
		addOption(subcatElement, 'Commercial', 'Commercial');
		addOption(subcatElement, 'Earthmoving', 'Earthmoving');
		addOption(subcatElement, 'Factory', 'Factory');
		addOption(subcatElement, 'Forestry', 'Forestry');
		addOption(subcatElement, 'Forklifts', 'Forklifts');
		addOption(subcatElement, 'Industrial', 'Industrial');
		addOption(subcatElement, 'Mining', 'Mining');
		addOption(subcatElement, 'Generators', 'Generators');
		addOption(subcatElement, 'Yachts', 'Yachts');	
		addOption(subcatElement, 'Car', 'Car');
		addOption(subcatElement, 'Other', 'Other');
    } else if(loanTypeElement.value == "Bond / Home Loan") {
		addOption(subcatElement, 'Residential New Bond (No Credit Bureau Listings)', 'Residential New Bond (No Credit Bureau Listings)');
		addOption(subcatElement, 'Residential Further Bond (No Credit Bureau Listings)', 'Residential Further Bond (No Credit Bureau Listings)');	
		addOption(subcatElement, 'Residential New Bond (With Credit Bureau Listings)', 'Residential New Bond (With Credit Bureau Listings)');
		addOption(subcatElement, 'Residential Further Bond (With Credit Bureau Listings)', 'Residential Further Bond (With Credit Bureau Listings)');
	} else if(loanTypeElement.value == "Bridging") {
		addOption(subcatElement, 'Debtors Book', 'Debtors Book');
		addOption(subcatElement, 'Estate Agents Commission', 'Estate Agents Commission');
		addOption(subcatElement, 'Invoices', 'Invoices');
		addOption(subcatElement, 'Import', 'Import');
		addOption(subcatElement, 'Pension / Provident', 'Pension / Provident');
		addOption(subcatElement, 'Property - Sellers Proceeds', 'Property - Sellers Proceeds');
		addOption(subcatElement, 'Property - Equity Release', 'Property - Equity Release');
		addOption(subcatElement, 'Property - Developers Finance', 'Property - Developers Finance');
	} else if(loanTypeElement.value == "Business Finance") {
		addOption(subcatElement, 'New Business', 'New Business');
		addOption(subcatElement, 'Expansion Capital', 'Expansion Capital');
	} else if(loanTypeElement.value == "Cash Loans") {
        addOption(subcatElement, 'I have bureau listings', 'I have bureau listings');
		addOption(subcatElement, 'I do not have bureau listings', 'I do not have bureau listings');
		//disable(subcatElement);
	} else if(loanTypeElement.value == "Credit Rehabilitation") {
		addOption(subcatElement, 'I Own A Home', 'I Own A Home');
		addOption(subcatElement, 'Do Not Own A Home', 'Do Not Own A Home');
	} else if(loanTypeElement.value == "Commercial Loan") {
		addOption(subcatElement, 'Business', 'Business');
		addOption(subcatElement, 'Property', 'Property');
    }  else if(loanTypeElement.value == "Debt Consolidation") {
		addOption(subcatElement, 'I Own A Home', 'I Own A Home');
		addOption(subcatElement, 'Do Not Own A Home', 'Do Not Own A Home');
    }  else if(loanTypeElement.value == "Industrial Loan") {
		addOption(subcatElement, 'Business', 'Business');
		addOption(subcatElement, 'Property', 'Property');
	} else if(loanTypeElement.value == 'Home Rescue') {
		addOption(subcatElement, 'Willing to sell at outstanding bond amount', 'Willing to sell at outstanding bond amount');
		addOption(subcatElement, 'Not willing to sell at outstanding bond amount', 'Not willing to sell at outstanding bond amount');
	} else if(loanTypeElement.value == 'Property Development') {
		addOption(subcatElement, 'Residential (Low Cost less than R300k)', 'Residential (Low Cost less than R300k)');
		addOption(subcatElement, 'Residential (Affordable above R300k)', 'Residential (Affordable above R300k)');
		addOption(subcatElement, 'Commercial', 'Commercial');
		addOption(subcatElement, 'Industrial', 'Industrial');
		addOption(subcatElement, 'Mixed', 'Mixed');
	} else {
        addOption(subcatElement, 'N/A', 'Please select a subcategory');
		disable(subcatElement);
    }
}