function querySt(ji) 
{
	
	hu = unescape(window.location.search.substring(1));
	var space = ji.indexOf("%20") != -1 ? "&" : "&";
	var delimiter = ji.indexOf("&") != -1 ? "&" : "&";
	gy = hu.split(delimiter);
	for (i=0;i<gy.length;i++) 
	{
		ft = gy[i].split("=");
		if (ft[0] == ji) 
		{
			return ft[1];
		}
	}
}

function hashSt(ji)
{

 hu = unescape(window.location.hash.substring(1));
 var space = ji.indexOf("%23") != -1 ? "&" : "&";
 var delimiter = ji.indexOf("&") != -1 ? "&" : "&";
 gy = hu.split(delimiter);
 for (i=0;i<gy.length;i++)
 {
 ft = gy[i].split("=");
 if (ft[0] == ji)
 {
 return ft[1];
 }
 }
} 

function ShowRoute(source, destination)
{

 if(source == '')
 {
	alert('Please insert the source and try again');
	return;
 }
 
 if(destination == '')
 {
	alert('Please insert the destination and try again');
	return;
 }
 
 source = source.replace(" ", "+");
 destination = destination.replace(" ", "+");
 window.open("http://maps.google.co.uk/maps?f=d&source=s_d&saddr=" + source + "&daddr=" + destination,"RoutePlanner","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1");
 //window.open("http://maps.google.co.uk/maps?f=d&source=s_d&saddr=" + source + "&daddr=" + destination);
}

function IsMatch(regex, valueToCheck)
{
	var re = new RegExp(document.demoMatch.regex.value);
	if(document.demoMatch.subject.value.match(re)) 
		return true;
    
	return false;
}

var CustomEvent = function() 
{
	//name of the event
	this.eventName = arguments[0];
	var mEventName = this.eventName;

	//function to call on event fire
	var eventAction = null;

	//subscribe a function to the event
	this.subscribe = function(fn) {
		eventAction = fn;
	};

	//fire the event
	this.fire = function(sender, eventArgs) {
		if(eventAction != null) {
			eventAction(sender, eventArgs);
		}
		else {
			//console.log('There was no function subscribed to the ' + mEventName + ' event!');
		}
	};
};

function deFormatPerMill(num) 
{
	return num.replace(",","")
}

function formatPerMill(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


// break currency int with comma, returns string 
function CurrencyFormatted(amount)
{
	var nStr; 
	nStr += '';
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;

	/*
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
	*/
}
// end of function CurrencyFormatted()

function appendToTestDrive()
{
    var strOp = "?"
    var strMetaTestLnk = $('meta[name=booktestparam]').attr("content"); 
    if (strMetaTestLnk != "")
   { 
       $( ".lnk_test_drive" ).each(
       
           // loop iteration index on the current element.
           function( intIndex ){
               
               var t=$(this); 
               var originalHref = t.attr("href");
               t.attr('href', originalHref + strOp + strMetaTestLnk);
               }
       );
       
   }
} 

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function show_detail(elementId) {
	document.getElementById(elementId).style.display = "block";	
}


function hide_detail(elementId) {
	document.getElementById(elementId).style.display = "none";
}




