

//	CSutils.inc - Client Side Utility functions

//	Author: Andy Sanderson, Adam Fraser & Andy Pearce

//	Date: February 1999


function letURL() {
	document.quote.offline.value = "Y"
}

function notURL() {
	document.quote.offline.value = "N"

}


function SetCookie(name,value) {
document.cookie = name + "=" + value;
}

function AddCookie(name,value) {
document.cookie += name + "=" + value;
}

function getCookie(Name) {
          var search = Name + "="
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(search) 
                    if (offset != -1) { // if cookie exists 
                              offset += search.length 
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset) 
                              // set index of end of cookie value
                              if (end == -1) 
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    } 
          }
}



function GetCookieStuff() {
	var str = getCookie( "CTQuipsOffline" );

	if ( str != null ) {
		arr = str.split( "," );
	
		document.quote.flatrate.value=arr[0];
		document.quote.cashprice.value=arr[1];
		document.quote.cashdeposit.value=arr[2];
		document.quote.partexchange.value=arr[3];
		document.quote.selPPP.value=arr[4];
		document.quote.PPPScheme.value=arr[5];
	}

}


function SetCookieStuff() {

	var str = document.quote.flatrate.value;
	str = str + "," + document.quote.cashprice.value;
	str = str + "," + document.quote.cashdeposit.value;
	str = str + "," + document.quote.partexchange.value;
	str = str + "," + document.quote.selPPP.value;
	str = str + "," + document.quote.PPPScheme.value;

	SetCookie( "CTQuipsOffline",  str );
}


function isInteger(x) {
	if (parseInt(x, 10) == x) {return true;}
	else {return false;}
}

function isPositive(x) {
	if (x > 0) {return true;}
	else {return false;}
}

function isPositiveInteger(x) {
	if ((isInteger(x)) && isPositive(x)) {return true;}
	else {return false;}
}

function isZero(x) {
	if ((isInteger(x)) && (x == 0)) {return true;}
	else {return false;}
}

function isPositiveIntegerOrZero(x) {
	if ((isPositiveInteger(x)) || (isZero(x))) {return true;}
	else {return false;}
}

function getIntegerPart(x) {
	x = parseInt(x, 10);
	x = makeNaNZero(x);
	return x;
}

function getValue(strString) {
	var x = makeNaNBlank(parseFloat(strString));
	return x;
}

function getDecimalPart(x) {
	x = parseFloat(x);
	x = x - parseInt(x, 10);
	x = makeNaNZero(x);
	return x;
}

function makeNaNZero(x) {
	if (isNaN(x)) {
		x = 0;
	}
	return x;
}

function makeNaNBlank(x) {
	if (isNaN(x)) {
		x = '';
	}
	return x;
}

function makeZeroBlank(x) {
	if (x == 0) {
		x = '';
	}
	return x;
}

function makeBlankZero(x) {
	if (x == '') {
		x = '0';
	}
	return x;
}

function isInRange(x, low, high) {
	if ((x >= low) && (x <= high)) {return true;}
	else {return false;}
}

function capitalisePhrase(strPhrase) {
	strPhrase = strPhrase.substring(0,1).toUpperCase() + strPhrase.substring(1);
	return strPhrase;
}

function titleCasePhrase(strPhrase) {
	var bSpaceFlag;
	bSpaceFlag = true;
	var i;
	var strNewPhrase;
	strNewPhrase = "";
	var strCharacter;
	for (i = 0; i < strPhrase.length; i++) {
		strCharacter = strPhrase.substr(i,1);
		strCharacter = strCharacter.toLowerCase();
		if (bSpaceFlag == true) {strCharacter = strCharacter.toUpperCase();}
		strNewPhrase = strNewPhrase + strCharacter;
		bSpaceFlag = false;
		if (strCharacter == " ") {bSpaceFlag = true;}
	}
	return strNewPhrase;
}




