fr=1;

function oldsetInsParms( Parms ){
		exists = GetCookie('INS');
		if (!exists) {
			SourceCodes = (parent.location.search) ? parent.location.search : ("?" + Parms)
			SetCookie('INS',SourceCodes,'/');
		}
	}

function setInsParms( Parms ){

if (parent.window.location.search.indexOf("srcsite") != -1)
{
Parms=Parms.replace("&srcsite=TD","");
}
          exists = GetCookie('INS');
          if (!exists) {
               if (parent.location.search){
        			URLParms = parent.location.search
     				SplitParms = Parms.split("&")
     				for (i=0; i<SplitParms.length; i++){
      					SourceCodes = URLParms.replace(SplitParms[i], "");
						URLParms = SourceCodes;
     				}
     				SourceCodes = SourceCodes + "&" + Parms
     				re = /%26/gi
     				SourceCodes = SourceCodes.replace(re,"&")
     				re = /&&/gi
     				SourceCodes = SourceCodes.replace(re,"&")
      			}
      			else {
        			SourceCodes = "?" + Parms
      			}
               SetCookie('INS',SourceCodes,'/');
          }
     }
function getAllParms( moreParms ){

	cgiParms="https://www.w4.dev.tdcanadatrust.com/tdinsurance/app.jsp?"

 	SetCookie('QUOTE','OK','/');
 	OK = GetCookie('QUOTE');

 	if (!OK) // no cookie - no quote
 	{
 			if (fr) {
 				alert ("Pour pouvoir débuter une soumission en ligne, il est primordial que votre " +
 "navigateur accepte les témoins de session (session cookies). Si cette option " +
 "n'est pas activée, vous ne serez pas en mesure d'utiliser notre service en ligne.")
 			}
 			else
 			{
 				alert ("To access our online quote, it is essential that your browser setting " +
 "enables session cookies. If this option is not activated, you will not be able to use our online service.")
 			}
 			return;
 	}
	exists = GetCookie('INS');

	if (!exists) {
		exists = "";
		URLArg = window.location + "";
		if (URLArg.indexOf(".tdcanadatrust.com/francais")!= -1) { exists = "brand=TDCT&language=FR&rg=7001"; }
		else if (URLArg.indexOf(".tdcanadatrust.com/")!= -1)    { exists = "brand=TDCT&language=EN&rg=7001"; }
		else if (URLArg.indexOf(".primmum.com/francais/")!= -1) { exists = "brand=PRID&language=FR"; }
		else if (URLArg.indexOf(".primmum.com/")!= -1)          { exists = "brand=PRID&language=EN"; }
		else if (URLArg.indexOf(".tdiha.com/")!= -1)			{ exists = "brand=CTDI&language=EN"; }
		else if (URLArg.indexOf(".tdaha.com/")!= -1)			{ exists = "brand=CTDI&language=FR"; }
		else if (URLArg.indexOf(".melochemonnex.com/en")!= -1)	{ exists = "brand=MMI&language=EN"; }
		else if (URLArg.indexOf(".melochemonnex.com/fr")!= -1)	{ exists = "brand=MMI&language=FR"; }
	}


	sAgent = navigator.userAgent;
	bIsIE6 = sAgent.indexOf("IE 6")  > -1;

	if (bIsIE6){
		if (!fr) {
	 ie6 = "NOTICE TO USERS OF INTERNET EXPLORER 6.0\n " +
"Please be advised that the Internet Explorer 6.0 software has not been fully "+
"tested for compatibility with our website, and as such, we are unable to "+
"provide support for this product. As with the first release of any software "+
"you may experience stability and compatibility issues. We recommend the use "+
"of Microsoft Internet Explorer version 4.0 to 5.5.";
		}
		else
		{
	 ie6= "AVIS AUX UTILISATEURS D'INTERNET EXPLORER 6.0\n" +
"Veuillez prendre note que les vérifications concernant la compatibilité du "+
"logiciel Internet Explorer 6.0 avec notre site Web n'ont pas été effectuées. "+
"Par conséquent, nous sommes dans l'impossibilité d'offrir un soutien "+
"technique pour ce produit. Lors du lancement de tout logiciel, il est "+
"possible que des problèmes de compatibilité et de stabilité surviennent."+
"Nous recommandons l'utilisation de Internet Explorer version 4.0 à 5.5.";
		}
		//alert (ie6);- removed aug8,02
	}
               if (parent.location.search){
        			URLParms = parent.location.search
     				re = /\?/gi
     				URLParms = URLParms.replace(re,"")
     				SplitParms = URLParms.split("&")
     				for (i=0; i<SplitParms.length; i++){
						if (SplitParms[i].indexOf("srcsite") != -1)
						{
						exists = exists + "&" + SplitParms[i]
						}
						if (SplitParms[i].indexOf("campaignid") != -1)
						{
						exists = exists + "&" + SplitParms[i]
						}
						if (SplitParms[i].indexOf("associationid") != -1)
						{
						exists = exists + "&" + SplitParms[i]
						}

     				}
				}
// changing srcsite for EasyWeb traffic

		if (typeof srcSite != "undefined") {
			exists = exists.replace("&srcsite=TD","&srcsite=" + srcSite);
		}

		Parms = exists.split("&")
		for (x=0; x < Parms.length; x++) {

    		if ((Parms[x].indexOf("campaignid") != -1) && (cgiParms.indexOf("campaignid") != -1))
			{ // avoid doubling campaignid
			continue;
			}

    		if ((Parms[x].indexOf("associationid") != -1) && (moreParms.indexOf("associationid") != -1))
			{ // avoid doubling associationid
			continue;
			}

    		if (Parms[x].indexOf("province") == -1){ // don't take province from cookie
     		cgiParms=cgiParms+Parms[x]+"&"
			}

		}
			// form name used - selecter1
			if (document.selecter1.selectbox.options[document.selecter1.selectbox.selectedIndex].value != "") {
				provcode = document.selecter1.selectbox.options[document.selecter1.selectbox.selectedIndex].value
				cgiParms = cgiParms + "&province=" + provcode
				
				
				if (provcode.indexOf("NB")!= -1  || provcode.indexOf("NS")!= -1  || provcode.indexOf("PE")!= -1  || 
				provcode.indexOf("NF")!= -1   || provcode.indexOf("NL")!= -1  )
				{
				alert("Malheureusement, nous ne sommes pas en mesure de vous offrir \nune soumission en ligne dans cette région. Afin de recevoir une soumission, \nnous vous invitons à nous joindre sans frais au 1 800 338-0218.");
				return;
				}
				cgiParms = chkFrProv(cgiParms)+moreParms;
				if (cgiParms.indexOf("TDCT") !=-1)
				{
					if (provcode.indexOf("ON") != -1 ) {
						if (cgiParms.indexOf("COUPON") > 0) {
							cgiParms = cgiParms.replace("7001","7754");
						} else {
							if (cgiParms.indexOf("MOTO") > 0){
							cgiParms = cgiParms.replace("7001","7141");
							} else {
							cgiParms = cgiParms.replace("7001","7161");
							}
						}
					}
					if (provcode.indexOf("BC") != -1 ) cgiParms = cgiParms.replace("7001","2754");
					if (provcode.indexOf("AB") != -1 ) cgiParms = cgiParms.replace("7001","1754");
					if (provcode.indexOf("SK") != -1 ) cgiParms = cgiParms.replace("7001","9754");
					if (provcode.indexOf("MB") != -1 ) cgiParms = cgiParms.replace("7001","3754");
					if (provcode.indexOf("QC") != -1 ) cgiParms = cgiParms.replace("7001","8754");
					if (provcode.indexOf("NB") != -1 ) cgiParms = cgiParms.replace("7001","4754");
					if (provcode.indexOf("NS") != -1 ) cgiParms = cgiParms.replace("7001","5754");
					if (provcode.indexOf("PE") != -1 ) cgiParms = cgiParms.replace("7001","6754");
					if (provcode.indexOf("NF") != -1 ) cgiParms = cgiParms.replace("7001","0754");
					if (provcode.indexOf("NL") != -1 ) cgiParms = cgiParms.replace("7001","0754");
				}

     				re = /\&\&/gi
     				cgiParms = cgiParms.replace(re,"&")
					re = /\?\?/gi
     				cgiParms = cgiParms.replace(re,"?")

if (cgiParms.indexOf("language=") == -1)
{
	cgiParms = cgiParms + "&brand=TDCT&language=EN";
}
				parent.window.location.href = cgiParms
				//win=window.open(cgiParms,'quote','scrollbars=yes,resizable=yes,width=800,height=600');
				//win.focus();
			}
			else {

				if (fr) {
				alert ("Veuillez choisir votre province.")
				}
				else
				{
				alert ("Please select a province.")
				}
			}
		}

function chkFrProv( Parms ){
		Parms = Parms.split("&")
		for (x=0; x < Parms.length; x++) {
    		if (Parms[x].indexOf("province") != -1){
     		SubParms = Parms[x].split("=")
     		Province = SubParms[1]
    	    }
			if (Parms[x].indexOf("language") != -1){
				if (fr) {
				Parms[x]="language=FR" // FRENCH version
				} else {
				Parms[x]="language=EN" // ENGLISH version
				}
			}
		}
		inParms=""
		for (x=0; x < Parms.length; x++) {
			inParms=inParms+Parms[x]+"&"
		}
		if (Province != "QC" && Province != "NB" && fr)
		{
		alert("Veuillez prendre note que pour une question pratique, nous vous\n"+
	"offrons la possibilité d'obtenir une soumission en ligne en français.\n"+
	"Toutefois, le service à la clientèle et la documentation reliée à nos\n"+
	"programmes d'assurance seront disponibles en anglais seulement.\n"+
	"Nous vous remercions de votre compréhension. ");
		}
		return(inParms);
	}

function getProvince(){
  exists = GetCookie('INS');
 if (exists) {  Parms = exists.split("&");
  for (x=0; x < Parms.length; x++) {
  	if (Parms[x].indexOf("province") != -1){
       SubParms = Parms[x].split("=")
        Province = SubParms[1]    //form1 is the name of the form
    //selectbox is the name of the select kitem
    for (var i=0; i < document.selecter1.selectbox.length ; i++) {
     if (document.selecter1.selectbox.options[i].value == Province) {
      document.selecter1.selectbox.options[i].selected=true
     }
    }
   }
  }
 }
}

function SendParms(Page) {
	var Goto = Page
	if (location.search){
		Goto = Goto + location.search
	}
	location.href = Goto
}

