
var GLOB_quoteID;
var GLOB_numQuotes;
var GLOB_timeoutID;
GLOB_quoteID=1;
GLOB_numQuotes=5;
GLOB_timeoutID=-1;

function enableStylesheet(title){
	var sheet = findStylesheet(title);
	sheet.disabled = "";
}

function disableStylesheet(title){
	var sheet = findStylesheet(title);
	sheet.disabled = "true";
}

function findStylesheet(title){

	var x = document.getElementsByTagName("link");

	for(i=0;i<x.length;i++){
		
		if(x[i].getAttribute("title")==title){
	
			return x[i];
			break;
		}
		
	}

}

function initLightBox(){

	disableStylesheet("widget-print");

	x = document.getElementsByTagName('BODY');
	body = x[0];
	
	newDiv=document.createElement('DIV');
	
	newDiv.id='widget';
	
	body.appendChild(newDiv);
	
	newDiv=document.createElement('DIV');
	
	newDiv.id='widget-background';
	
	body.appendChild(newDiv);
	
	newDiv=document.createElement('A');
	
	newDiv.innerHTML='test';
	
	newDiv.onclick=open_light_box;
	
	ResizeWidgetBackground();
	
	div=document.getElementById("widget");
	
	x=document.createElement('DIV');
	/*
	x.id='loading';
	
	x.innerHTML='<div id="loading"><img src="/images/lightbox-loader.gif" alt="Loading icon" class="loading-icon" /><p>Loading</p></div>';
	
	div.appendChild(x);
	 */
	
	a=document.getElementsByTagName('A');
	
	for(i=0;i<a.length;i++)
	{
		if(a[i].getAttribute('href')){
		
			if(a[i].getAttribute('href').match(/t_widget_action=load/))
			{
			
				a[i].onclick=open_light_box;
				
			}
			
		}
	
	}
	
	try{
		if(lightbox_autorun){
			switch(lightbox_autorun){
	
			
				case "info-pack":
					var x = find_element_by_href("widget-info-pack-by-email");
					open_light_box.call(x);
					break;
				case "call-me":
					var x = find_element_by_href("widget-call-me-now");
					open_light_box.call(x);
					break;
				case "back-assessor":
					var x = find_element_by_href("widget-backassessor");
					open_light_box.call(x);
					break;
				default:
				
			}
		}
	
	}catch(e){
	
	}
	
}

function find_element_by_href(href){

	for(i=0;i<a.length;i++)
	{
		if(a[i].getAttribute('href')){
		
			if(a[i].getAttribute('href').match(href))
			{

				return a[i];
				
			}
			
		}
	
	}

}

function open_light_box(){

	
	win=document.getElementById("widget");
	
	win.innerHTML='<div id="loading"><img src="/images/lightbox-loader.gif" alt="Loading icon" class="loading-icon" /><p>Loading</p></div>';
	
	enableStylesheet("widget-print");
		
	href=this.getAttribute('href');
	
	document.getElementById('widget').style.display="block";
	
	document.getElementById('widget-background').style.display="block";
	
	sendRequest(href,popLightBox);
	
	ResizeWidgetBackground();
	
	window.scrollTo(0,0)
	
	return false;
	
}

function popLightBox(req){

	

	win=document.getElementById("widget");

	win.innerHTML=req.responseText;

	a=document.getElementsByTagName('A');

	var Matched;

	ResizeWidgetBackground();
	window.scrollTo(0,0);
	
	for(i=0;i<a.length;i++){
		
		if(a[i].hasAttribute){
		
			if(a[i].hasAttribute('href')){
				Matched=1;
			}else{
			
				Matched=0;
				
			}
		
		}else{
		
			Matched=1;
			
		}

		if(Matched==1){
		
			if(a[i].getAttribute('href').match(/t_widget_action=close/)){
			
				a[i].onclick=close_light_box;
				
			}
			
			if(a[i].getAttribute('href').match(/t_widget_action=load/)){
			
				a[i].onclick=open_light_box;
			
			}
			
		}
	
	}
	


	b=document.getElementById("widget").getElementsByTagName('FORM');
	
	for(i=0;i<b.length;i++){
	
		if(b[i].getAttribute('action').match(/t_widget_action=load/)){
			
			b[i].onsubmit=submit_light_box;
			
		}
		
	}

	ExecuteScripts(win);
	
}

function ExecuteScripts(node){

	

	for (var i=0; i<node.childNodes.length; i++) {
		var childObj = node.childNodes[i];
		
		if (childObj.nodeName) {
		
				if(childObj.nodeName=="SCRIPT"){

					eval(childObj.innerHTML);
		
				}
		
		}
		ExecuteScripts(childObj);
	}

}


function analyseThis(){

	var PostVars="";
	
	for(var i=0;i<this.length;i++)
	{
	
		PostVars=PostVars+this.elements[i].name+"="+this.elements[i].value+"&";
		
	}

	document.getElementById('debug').innerHTML=PostVars;return false;
	
}

function submit_light_box(){


	
	var PostVars="";
	
	for(var i=0;i<this.length;i++)
	{
	
		PostVars=PostVars+this.elements[i].name+"="+this.elements[i].value+"&";
		
	}
	

	sendRequest(this.getAttribute('action'),popLightBox,PostVars);
	
		x=document.getElementById("widget");
	
	x.innerHTML='<div id="loading"><img src="/images/lightbox-loader.gif" alt="Loading icon" class="loading-icon" /><p>Loading</p></div>';
	
	return false;
	
}

function close_light_box(){

	win=document.getElementById("widget");
	
	win.innerHTML='<div id="loading"><img src="/images/lightbox-loader.gif" alt="Loading icon" class="loading-icon" /><p>Loading</p></div>';
	win.style.display="none";
	
	document.getElementById("widget-background").style.display="none";
	
	disableStylesheet("widget-print");
	
	return false;
	
}

//onresize=ResizeWidgetBackground;

function ResizeWidgetBackground(){

	if(document.getElementById("widget-background"))
	{
	
		y=document.getElementById("widget-background");
		
		var page_size=___getPageSize();
		var page_scroll=___getPageScroll();
		
		y.style.width=page_size[0]+"px";
		y.style.height=page_size[1]+"px";
		
	}

	if(document.getElementById("widget"))
	{
	
		x=document.getElementById("widget");

		var left_offset=(page_size[0]-400)/2;
		var top_offset=54;
		
		x.style.top=top_offset+"px";
		x.style.left=left_offset+"px";
	}
	
	
}

function show_hide_element(){

	var element=document.getElementById("commentform");
	var label=document.getElementById("comment");
	var test=document.getElementById("edit-comment");
	if(element.style.display=="block"){
	
		element.style.display="none";
		label.style.display="block";
		test.onclick=show_hide_element;
		
	}else{
	
		element.style.display="block";
		label.style.display="none";
		test.onclick=show_hide_element;
	
	}
	
}

function show_hide_sidebarmenu(){

	if(this.parentNode.className=="close"){
	
		this.parentNode.className="open";
		
	}else{
	
		this.parentNode.className="close";
		
	}
	
}

function sendRequest(url,callback,postData){var req=createXMLHTTPObject();if(!req)return;var method=(postData)?"POST":"GET";req.open(method,url,true);req.setRequestHeader('User-Agent','XMLHTTP/1.0');if(postData)
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');req.onreadystatechange=function(){if(req.readyState!=4)return;if(req.status!=200&&req.status!=304){return;}
callback(req);}
if(req.readyState==4)return;req.send(postData);}
var XMLHttpFactories=[function(){return new XMLHttpRequest()},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}];function createXMLHTTPObject(){var xmlhttp=false;for(var i=0;i<XMLHttpFactories.length;i++){try{xmlhttp=XMLHttpFactories[i]();}
catch(e){continue;}
break;}
return xmlhttp;}
function URLEncode(clearString){var output='';var x=0;clearString=clearString.toString();var regex=/(^[a-zA-Z0-9_.]*)/;while(x<clearString.length){var match=regex.exec(clearString.substr(x));if(match!=null&&match.length>1&&match[1]!=''){output+=match[1];x+=match[1].length;}else{if(clearString[x]==' ')
output+='+';else{var charCode=clearString.charCodeAt(x);var hexVal=charCode.toString(16);output+='%'+(hexVal.length<2?'0':'')+hexVal.toUpperCase();}
x++;}}
return output;}

/*
var alreadyrunflag=0
if(document.addEventListener)
document.addEventListener("DOMContentLoaded",function(){alreadyrunflag=1;initLightBox()},false)
else if(document.all&&!window.opera){document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
var contentloadtag=document.getElementById("contentloadtag")
contentloadtag.onreadystatechange=function(){if(this.readyState=="complete"){alreadyrunflag=1
initLightBox()}}}

window.onload=function(){

	setTimeout("if (!alreadyrunflag) initLightBox()",0)
	
}

*/


function ___getPageScroll(){

	var xScroll,yScroll;
	
	if(self.pageYOffset){
	
		yScroll=self.pageYOffset;
		
		xScroll=self.pageXOffset;
		
	}else if(document.documentElement&&document.documentElement.scrollTop){
	
		yScroll=document.documentElement.scrollTop;
		xScroll=document.documentElement.scrollLeft;
		
	}else if(document.body){
	
		yScroll=document.body.scrollTop;
		xScroll=document.body.scrollLeft;
		
	}
	arrayPageScroll=new Array(xScroll,yScroll);
	
	return arrayPageScroll;
	
};

function ___getPageSize(){

	var xScroll,yScroll;
	
	if(window.innerHeight&&window.scrollMaxY)
	{
		
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
		
	}else if(document.body.scrollHeight>document.body.offsetHeight){
	
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
		
	}else{
	
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
		
	}

	var windowWidth,windowHeight;
	
	if(self.innerHeight){
	
		if(document.documentElement.clientWidth){
		
			windowWidth=document.documentElement.clientWidth;
			
		}else{
		
			windowWidth=self.innerWidth;
			
		}

	windowHeight=self.innerHeight;
	
	}else if(document.documentElement&&document.documentElement.clientHeight){
	
		windowWidth=document.documentElement.clientWidth;
		
		windowHeight=document.documentElement.clientHeight;
		
	}else if(document.body){
	
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
		
	}

	if(yScroll<windowHeight){
	
		pageHeight=windowHeight;
		
	}else{
	
		pageHeight=yScroll;
		
	}

	if(xScroll<windowWidth){
	
		pageWidth=xScroll;
		
	}else{
	
		pageWidth=windowWidth;
		
	}

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
	
};

function setOpacity(obj,value){obj.style.opacity=value/10;obj.style.filter='alpha(opacity='+value*10+')';};