// Auto Direct Javascript functions
// (Note: form validation functions contained in validation.js)
// edited 23/10/2001 by MDW

function leaveQuote(theURL) {
	if (confirm('Are you sure you want to abort this quote?')) {
	window.location.href = theURL;
	}
}

function printNotices(theAffinity) {
	var aff = "auto";
	if (theAffinity != '') {
		aff = theAffinity;
	}
	var noticesWin = window.open('https://www.outrightplc.co.uk/PolicyDocumentsService/documents/online/' + aff + '/toba/toba_gv.pdf','noticespopup','width=530,height=400,top=15,left=15,location=no,scrollbars=yes,resizable=yes,status=yes');
}

function showProtector() {
	var protectorWin = window.open('/van-insurance/html/option_extras.asp?c=q','protectorpopup','width=530,height=400,top=15,left=15,location=no,scrollbars=yes,resizable=yes,status=yes');
}

function showProtectorQuote() {
	var protectorWin = window.open('/van-insurance/html/option_extras.asp?c=q','protectorpopup','width=530,height=400,top=15,left=15,location=no,scrollbars=yes,resizable=yes,status=yes');
}
		
function showPPP() {
	var pppWin = window.open('/van-insurance/html/option_extras.asp?c=q#ppp','ppppopup','width=530,height=400,top=15,left=15,location=no,scrollbars=yes,resizable=yes,status=yes');
}

function viewWordings(thePDF) {
  var pdfURL = "/van-insurance/html/load_wording.asp?pdf=" + thePDF;
  var wordingwin = window.open(pdfURL,'wordings','status=yes,scrollbars=yes,resizable=yes,width=500,height=350');
}

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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function furtherExamples() {
	var exampleWin = window.open('/van-insurance/html/occup_popup.html','examplePopup','width=530,height=500,scrollbars=yes,status=yes,resizable=no,location=no');
}

function checkAccNo() {
	var accountno = document.questions.PayDDMAccount.value;
	if (document.questions.PayDDMHolder.value != "") {
		if (accountno.length < 8) {
			alert("The majority of Banks and Building Societies that subscribe to this scheme operate an 8 digit account numbering system. If your account code is less than 8 digits, please enter zero(s) before your account number.");
			return false;
		}
		else {
			return true;
		}
	}
}

function BringUpWindow3(webpage) {
     var url = webpage;
     var hWnd = window.open(url,"hsbc4","width=760,height=380,left=10,top=10,resizable=no,scrollbars=no");
     if (hWnd != null) {     if (hWnd.opener == null) { hWnd.opener = self; window.name = "home"; hWnd.location.href=url; } }
}

function showStepBack() {
	var stepbackWin = window.open('/van-insurance/html/protected_ncb.asp','stepbackpopup','width=530,height=400,top=15,left=15,location=no,scrollbars=yes,resizable=yes,status=yes');
}

function driverSex() {
	var driverMale = false;
	var driverFemale = false;
	var maleTitles = new Array('Mr','Sir','Lord');
	var femaleTitles = new Array('Mrs','Miss','Ms','Dame','Lady');
	var driverTitle
	var sQuestion
	if (document.questions.DriverTitle != null) {
		driverTitle = document.questions.DriverTitle.options[document.questions.DriverTitle.selectedIndex].value;
		sQuestion = document.questions.DriverSex;
	}
	else {
		driverTitle = document.questions.ContactTitle.options[document.questions.ContactTitle.selectedIndex].value;
		sQuestion = document.questions.ProposerSex;
	}
	if (driverTitle != "") {
		for (i=0;i<maleTitles.length;i++) {
			if (driverTitle == maleTitles[i]) {
				driverMale = true;
			}
		}
		for (j=0;j<femaleTitles.length;j++) {
			if (driverTitle == femaleTitles[j]) {
				driverFemale = true;
			}
		}
		if (driverMale) {
			sQuestion[0].checked = true;
		}
		else if (driverFemale) {
			sQuestion[1].checked = true;
		}
		else {
			sQuestion[0].checked = false;
			sQuestion[1].checked = false;
		}
	}
}

function clickOut(cURL) {
	var eURL = "http://www.outrightplc.co.uk/ClickthruTracking/clickthru.asp?cSite=autodirect&cURL=" + escape(cURL);
	var cWin = window.open(eURL);
}
function showAdvert(){
	var mywin = window.open("/advert/default.asp",'advert','scrollbars=no,resizable=no,location=no,width=350,height=270');
}
function recallaction(inputname){
	if ($F(inputname) == 'PC'){
		$('recall').action = PCaction;
		//alert(document.getElementById('recall').action);
	}
	else if ($F(inputname) == 'GV'){
		$('recall').action = GVaction;
		//alert(document.getElementById('recall').action);
	}
}
function $F(str_var){
	var elements = document.getElementsByName(str_var);
	var el = elements[0];
	switch(el.type) {
		case 'text':   				return el.value; break
		case 'hidden':   			return el.value; break
		case 'select-one':  		return el.options[el.selectedIndex].value; break
		case 'select-multiple':  	return el.options[el.selectedIndex].value; break
		case 'radio':  				return get_selected(elements); break  
	}
}
/*	-------------------------------------------------------------
	FUNCTION:		$()
	+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
	Description:	This function returns the form element 
					object.
					
	Requires:		ID
	-------------------------------------------------------------*/
	function $() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}
		return elements;
	}	
function mycarchecksubmit(){
	registration = document.getElementById('registration').value;
	registration = registration.toUpperCase();
	registration = registration.replace(/\s+/g,'');
	document.getElementById('mycarcheckform').action = document.getElementById('mycarcheckform').action + registration;
}
function toggle(id){
	if(document.getElementById(id).style.display == "block" || document.getElementById(id).style.display == ""){
		document.getElementById(id).style.display = "none";
	}else{
		document.getElementById(id).style.display = "block";
	}
}
function callback() {
	window.open("/comxo/callme.asp", 'callback', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=800,height=550');
}
/*************************************** CUSTOMER HELP ************************************************/
function launchHelp(){
		var _docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
		 $('customerHelp_iFrame').src = helpService; //'http://help.autodirect.co.uk/selfservice_autodirect/template-group.do?id=40';
		show('customerHelp_Overlay');
		center('customerHelp_iFrameCont');
		$('customerHelp_iFrameCont').style.top	= "45px";
		$('customerHelp_close').style.top 	= "36px";
		//$('customerHelp_close').style.left = (parseInt($('customerHelp_iFrameCont').style.left.replace("px", "")) + 637) + "px";
		$('customerHelp_close').style.left = (parseInt($('customerHelp_iFrameCont').style.left.replace("px", "")) - 8) + "px";
		$("customerHelp_Overlay").style.height = _docHeight + "px";
		show('customerHelp_close');
	} 
function hideCustomerHelp(){
		hide('customerHelp_Overlay');
		hide('customerHelp_iFrameCont');
		hide('customerHelp_close');
	} 

