﻿// JScript File

// GLOBAL VARIABLES ---------------------------------------------------------------------------------------

var blnMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1) ? true : false;
var blnNs4 = (document.layers) ? true : false;
var blnIe4 = (document.all && !document.getElementById) ? true : false;
var blnIe5 = (document.all && document.getElementById) ? true : false;
var blnNs6 = (!document.all && document.getElementById) ? true : false;
var blnNs7 = (!document.all && document.getElementById) ? true : false;
var blnOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1) ? true : false;

// BROWSER DEPENDENCE CORE FUNCTIONS -----------------------------------------------------------------------

function addLoadEvent(func) {
 var oldonload = window.onload;
 //window.onload = textResize;
 if (typeof window.onload != 'function') {
    window.onload = func;
 } else {
    window.onload = function() {
    oldonload();
    func();
    }
 }
}

function addEvents() {
    var oTopNav = document.getElementById('top_menu');
    if (!oTopNav) return false;
    if (oTopNav.firstChild) {
    var oLi = oTopNav.firstChild;
    while (oLi) {
        oLi.onmouseover = function() { this.className+="hover"; };
        oLi.onmouseout = function() { this.className=this.className.replace(new RegExp("hover\\b"), ""); };
        oLi = oLi.nextSibling;
    }
    textResize();
 }
 return true;
}
addLoadEvent(addEvents);


function ftnGetObjectString(strObjectId) {
/*Purpose	:	Used to return a string that represents the path to an object in the DOM
				    dependent on the browser being used.
	Effects	:	None
	Inputs	:	strObjectId - String - the id of an object
	Returns	:	String - the path to the object in the DOM
*/
	if(blnNs4) return "document." + strObjectId;
	if(blnIe4) return "document.all." + strObjectId;
	if(blnIe5 || blnNs6 || blnNs7 || blnOpera){
		if (blnMac && blnIe5)
			return "document.all['" + strObjectId + "']";
		else
			return "document.getElementById('" + strObjectId + "')";
	}
}

function ftnGetObject(strObjectId) {
/*Purpose	:	Used to return an object in the DOM.
	Effects	:	None
	Inputs	:	strObjectId - String - the id of an object
	Returns	:	Object - the object in the DOM
*/
	var strEval = ftnGetObjectString(strObjectId);
	return eval(strEval);
}


function ftnClearTextArea() {
    /*CHB - Clear Text Area Box for message*/
    ftnGetObject('txtTellUs').value = '';
}   


function showhidegeneral(id){ 
    if (document.getElementById){ 
        obj = ftnGetObject(id); 
        if (obj.style.display == "none"){ 
        obj.style.display = ""; 
        } else { 
        obj.style.display = "none"; 
        } 
    } 
}

function showdeliveryprice(){ 
    if (document.getElementById){ 
        obj = ftnGetObject('deliveryprice'); 
        obj.style.display = ""; 
    } 
}

function showhide(id){ 
    hideallfaqs();
    if (document.getElementById){ 
        obj = ftnGetObject(id); 
        if (obj.style.display == "none"){ 
        obj.style.display = ""; 
        } else { 
        obj.style.display = "none"; 
        } 
    } 
} 

function hideallfaqs(){ 
    objFAQA1 = ftnGetObject('faqA1');
    objFAQA2 = ftnGetObject('faqA2');
    objFAQA4 = ftnGetObject('faqA4');
    objFAQA1.style.display = "none";
    objFAQA2.style.display = "none";
    objFAQA4.style.display = "none";
    
} 

function calculateloan(intBudget, intPeriod) {
    objLoanAmountText = ftnGetObject('frmLoanAmountText');
    objLoanAmountText.value = intBudget * intPeriod;
}

function calculateloanwithpartexchange(intBudget, intPeriod, intPartEx) {
    objLoanAmountTextWithPartEx = ftnGetObject('frmppartextext');
    objLoanAmountText.value = intBudget * intPeriod - intPartEx;
}

function approxpartexchange(strmake, strmodel, strderivative, stryear, intmiles) {
    alert('Make' + strmake);
    alert('Model' + strmodel);
    alert('Derivative' + strderivative);
    alert('Year' + stryear);
    alert('Miles' + intmiles);
    objLoanAmountTextWithPartEx = ftnGetObject('frmppartextext');
    objLoanAmountTextWithPartEx.value = "2500";
} 

function carbudget() {
    objcarbudget = ftnGetObject('frmcarbudget');
    objcarbudget.value = "15,000";
}

function GetDay(nDay)
{
	var Days = new Array("Sunday","Monday","Tuesday","Wednesday",
	                     "Thursday","Friday","Saturday");
	return Days[nDay]
}

function GetMonth(nMonth)
{
	var Months = new Array("January","February","March","April","May","June",
	                       "July","August","September","October","November","December");
	return Months[nMonth] 	  	 
}

function DateString()
{
	var Today = new Date();
	var suffix = "th";
	switch (Today.getDate())
	{
		case 1:
		case 21:
		case 31: 
			suffix = "st"; break;
		case 2:
		case 22:
			suffix = "nd"; break;
		case 3:
		case 23:
			suffix = "rd"; break;
	};

	var strDate = GetDay(Today.getDay()) + " " + Today.getDate();
	strDate +=  suffix + " " + GetMonth(Today.getMonth()) + " " + Today.getYear();
	return strDate
}

function setdeliveryprice(strplace) {
    /*Get Delivery place*/
    
    switch (strplace)
    {
    case 'Aberdeen': intprice = 268; break;
    case 'Aberystwyth': intprice = 153; break;
    case 'Barnstaple':intprice = 181; break;
    case 'Birmingham': intprice = 88; break;
    case 'Brighton': intprice= 92; break;
    case 'Bristol': intprice= 128; break;
    case 'Cambridge': intprice= 28; break;
    case 'Cardiff': intprice= 146; break;
    case 'Carlisle': intprice= 155; break;
    case 'Camarthen': intprice= 180; break;
    case 'Dorchester': intprice= 133; break;
    case 'Dover': intprice= 95; break;
    case 'Edinburgh': intprice= 197; break;
    case 'Exeter': intprice= 172; break;
    case 'Fort William': intprice= 264; break;
    case 'Glasgow': intprice= 208; break;
    case 'Gloucester': intprice= 177; break;
    case 'Guildford': intprice= 88; break;
    case 'Hereford': intprice= 118; break;
    case 'Holyhead': intprice= 177; break;
    case 'Hull': intprice= 81; break;
    case 'Inverness': intprice= 298; break;
    case 'Kendal': intprice= 152; break;
    case 'Leeds': intprice= 96; break;
    case 'Lincoln': intprice= 57; break;
    case 'Liverpool': intprice= 132; break;
    case 'Maidstone': intprice= 72; break;
    case 'Manchester': intprice= 102; break;
    case 'Middlesbrough': intprice= 123; break;
    case 'Newcastle': intprice= 140; break;
    case 'Northampton': intprice= 65; break;
    case 'Norwich': intprice= 0; break;
    case 'Nottingham': intprice=65; break;
    case 'Oxford': intprice= 80; break;
    case 'Penzance': intprice=238 ; break;
    case 'Perth': intprice= 222; break;
    case 'Peterborough': intprice= 35; break;
    case 'Plymouth': intprice= 200; break;
    case 'Portsmouth': intprice= 112; break;
    case 'Preston': intprice= 129; break;
    case 'Salisbury': intprice= 117; break;
    case 'Sheffield': intprice= 81; break;
    case 'Shrewsbury': intprice= 112; break;
    case 'Southampton': intprice= 112; break;
    case 'Stoke-on-Trent': intprice= 95; break;
    case 'Stranraer': intprice= 213; break;
    case 'Taunton': intprice= 160; break;
    case 'Wick': intprice= 354; break;
    case 'York': intprice= 99; break;
    case 'London': intprice= 65; break;
    };
    strResponse = 'The estimated cost of delivery to ' + strplace + ' is £' + intprice + ' plus vat.';
    showdeliveryprice();
    var priceholder = ftnGetObject("deliveryprice");
    priceholder.innerHTML = "";
    var newdiv = document.createElement("div");
    newdiv.appendChild (document.createTextNode(strResponse));
    priceholder.appendChild(newdiv);   
}


function smallText() { 
var bodyElement = document.getElementsByTagName("body")[0]; 
bodyElement.style.fontSize = '1.1em'; 
} 

function mediumText() { 
var bodyElement = document.getElementsByTagName("body")[0]; 
bodyElement.style.fontSize = '1.2em'; 
} 

function bigText() { 
var bodyElement = document.getElementsByTagName("body")[0]; 
bodyElement.style.fontSize = '1.3em'; 
} 


function textResize() { 
var small = document.getElementById('smallLink'); 
var medium = document.getElementById('mediumLink'); 
var big = document.getElementById('bigLink'); 
small.onclick = smallText; 
medium.onclick = mediumText; 
big.onclick = bigText; 
} 

function addBookmark() {
    var title = document.title;
    var url = document.location.href;
    if (window.sidebar) { 
    window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
    window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
    return true;
    }
}
