// -------------------------------------------------------- //
// pCodeField	= the ID of the input that has the postcode //
// pJourney		= the journey ID                            //
// customParam	= (optional) for passing function results   //
// -------------------------------------------------------- //
function navigateWithPostCode(pCodeField, pJourney, customParam)
{	
	if (customParam === '') {
		// only return false if the type is string and it actually IS empty
		return false;
	}
	
	// debugger
	var pcode = document.getElementById(pCodeField);
	var startPage = GetHTTPPrefix() + "/at_home/applications/QuoteAndSwitch/AffiliateStart.aspx?journeyid=" + pJourney;
	// var startPage = GetHTTPSite() + "/at_home/forms/ApplicationStart.aspx?journeyid=" + pJourney;
	// var startPage = "http://localhost/at_home/forms/ApplicationStart.aspx?journeyid=" + pJourney;
	
	//append any query string to the URL?
	var q = location.search.substring(1);
	if (q) {
		startPage += '&' + q;
	}
	
	//append any custom parameter
	if (customParam) {
		startPage += '&' + customParam;
	}

	if (pcode) {
	    var oNew = window.open(startPage + "&pcode=" + pcode.value, "quoteAndSwitch", "width=800,height=600,scrollbars,resizable,status");
	}else{
		var oNew = window.open(startPage,"qw","width=800,height=600,scrollbars,resizable,status");
	}
	
	return false;
}


// -------------------------------------------------------- //
// FOR MAXYMISER                                            //
// -------------------------------------------------------- //
function navigateWithPostCodeMaxi(pCodeField, pJourney, customParam)
{	
	if (customParam === '') {
		// only return false if the type is string and it actually IS empty
		return false;
	}
	
	// debugger
	var pcode = document.getElementById(pCodeField);
	var startPage = GetHTTPPrefix() + "/at_home/applications/QandS/AffiliateStart.aspx?journeyid=" + pJourney;
	
	//append any query string to the URL?
	var q = location.search.substring(1);
	if (q) {
		startPage += '&' + q;
	}
	
	//append any custom parameter
	if (customParam) {
		startPage += '&' + customParam;
	}

	if (pcode) {
		var oNew = window.open(startPage + "&pcode=" + pcode.value,"quoteAndSwitch","width=1000,height=700,scrollbars,resizable,status");
	}else{
		var oNew = window.open(startPage,"quoteAndSwitch","width=1000,height=700,scrollbars,resizable,status");
	}
	
	return false;
}

// -------------------------------------------------------- //
// For Salesadvisers                                        //
// -------------------------------------------------------- //
function navigateWithPostCodeAndPin(pCodeField, pPin, pJourney, customParam) {
    if (customParam === '') {
        // only return false if the type is string and it actually IS empty
        return false;
    }

    // debugger
    var pcode = document.getElementById(pCodeField);
    var pin = document.getElementById(pPin);
    var startPage = GetHTTPPrefix() + "/at_home/applications/QuoteandSwitch/AffiliateStart.aspx?journeyid=" + pJourney;
    //var startPage = "http://localhost/at_home/applications/QandS/AffiliateStart.aspx?journeyid=" + pJourney;

    //append any query string to the URL?
    var q = location.search.substring(1);
    if (q) {
        startPage += '&' + q;
    }

    //append any custom parameter
    if (customParam) {
        startPage += '&' + customParam;
    }
    else {
        startPage += '&AG=004&CH=FA';
    }

    var queryString = '';

    if (pin && pin.value != '') {
        queryString += "&REF=" + pin.value;
        var _cs = "AG=004;CH=FA" ;
        _cs += ";REF=" + pin.value;

        QuickWinsSetCookie("QSCookie", _cs, 30);
    }
    else {
        alert("Please enter an adviser pin.");
        return false;
    }

    if (pcode) {
        queryString += "&pcode=" + pcode.value;
    }

    var oNew = window.open(startPage + queryString, "quoteAndSwitch", "width=1000,height=700,scrollbars,resizable,status");
    
    return false;
} /*
<fieldset>
<form id="frmMain" onsubmit="return navigateWithPostCodeAndPin('txtPcode','pin','10004'); return false;" action="/at_home/applications/QandS/affiliatestart.aspx?journeyid=10004" target="quoteAndSwitch">
<div id="postCodeEntry"><label for="txtPcode">Enter postcode</label> <input type="text" maxlength="10" id="txtPcode" name="pcode" /></div>
<label for="Pin">Adviser Pin</label>: <input maxlength="6" type="text" name="REF" id="pin" />
<input type="submit" class="pcode_submit" onclick="return navigateWithPostCodeAndPin('txtPcode','pin','10004')" alt="Compare npower prices" value="Compare npower prices" name="btnQuote" /></div>

</form>
</fieldset>
*/
function QuickWinsSetCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value + "; path=/";
}

