/***************************************************
 * Copyright © 2006 David Hoyt. All rights reserved. 
 *	Permission for use by All Things Insurance.
 ***************************************************/

function EmailAFriend(l,p) {
	var emailafriendWin = window.open("/emailfriend.aspx?link=" + l,"emailafriend","toolbar=0,resizable=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=450,height=375");
    emailafriendWin.focus();
}

function ScheduleDemo(p) {
	var ScheduleDemoWin = window.open("/demos/schedule.aspx","schdemo","toolbar=0,resizable=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=350,height=533");
	ScheduleDemoWin.focus();
}

function changeFormActionAndSubmit(action) {
	var f = null;
	if (typeof(document.getElementById) == "undefined" && typeof(document.forms) == "undefined")
		return;
	
	if ((f = document.getElementById("form")) == null && document.forms != null && document.forms.length > 0)
		f = document.forms[0];
	
	if (f == null)
		return;
	
	f.action = action;
	f.submit();
}

function switchSidebar() {
	if (typeof(document.getElementById) == "undefined")
		return;
	var sideBar = document.getElementById("divSidebar");
	var sideBarHidden = document.getElementById("divSidebarHidden");
	var main = document.getElementById("divMain")

	if (sideBar == null || sideBarHidden == null)
		return;
	
	if (typeof(sideBar.style.display) == "undefined" || sideBar.style.display == "" || sideBar.style.display == "block") {
		sideBar.style.display = "none";
		sideBarHidden.style.display = "block";
		if (typeof(lib) != "undefined" && typeof(lib.createCookie) != "undefined")
			lib.createCookie("sideBarShow", "none", 365);
		if (main != null)
			main.style.width = "715px";
	} else {
		sideBar.style.display = "block";
		sideBarHidden.style.display = "none";
		if (typeof(lib) != "undefined" && typeof(lib.createCookie) != "undefined")
			lib.createCookie("sideBarShow", "block", 365);
		if (main != null)
			main.style.width = "600px";
	}
}

function loadSidebar() {
	if (typeof(document.getElementById) == "undefined")
		return;
		
	var sideBar = document.getElementById("divSidebar");
	var sideBarHidden = document.getElementById("divSidebarHidden");
	var val = lib.readCookie("sideBarShow");
	
	if (sideBar == null || sideBarHidden == null) 
		return;
	
	if (val == null || val == "block") {
		sideBar.style.display = "block";
		sideBarHidden.style.display = "none";
	} else {
		sideBar.style.display = "none";
		sideBarHidden.style.display = "block";
	}
}

function preloadImages() {
	lib.preloadImages('/common/theme/images/side_spotlight.gif','/common/theme/images/nav_home_over.gif','/common/theme/images/nav_loss_over.gif','/common/theme/images/nav_market_over.gif','/common/theme/images/nav_prospects_over.gif','/common/theme/images/nav_eclaims_over.gif','/common/theme/images/nav_iipp_over.gif','/common/theme/images/nav_doc_over.gif');
}

/*
Cross Browser Gradient Backgrounds
v1.0
Last Revision: 11.03.2005
steve@slayeroffice.com
*/
function createGradient() {
	if(!document.getElementById)return;
	
	objArray = getGradientObjects();
	if(!objArray.length) return;
	
	for(i=0;i<objArray.length;i++) {
		params = objArray[i].className.split(" ");
		if(document.all && !window.opera) {
			objArray[i].style.width = objArray[i].offsetWidth + "px";
			params[3] == "horizontal"?gType = 1:gType = 0;
			objArray[i].style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType="+gType+",StartColorStr=\"#" + params[1] + "\",EndColorStr=\"#" + params[2] + "\")";
	} else {
			//objArray[i].style.backgroundColor = "#" + params[1];
			//return;
			colorArray = createColorPath(params[1],params[2]);
			x=lib.findPosX(objArray[i]);
			y=lib.findPosY(objArray[i]);
			if(params[3] == "horizontal") {
				w=Math.round(objArray[i].offsetWidth/colorArray.length);
				if(!w)w=1;
				h = objArray[i].offsetHeight;
			} else {
				h = Math.round(objArray[i].offsetHeight/colorArray.length);
				if(!h) h =1;
				w = objArray[i].offsetWidth;
			}
			makeGrandParent(objArray[i]);
			tmpDOM = document.createDocumentFragment();
			for(p=0;p<colorArray.length;p++) {
				g = document.createElement("div");
				g.setAttribute("style","position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h + "px;width:" + w + "px;background-color:rgb(" + colorArray[p][0] + "," + colorArray[p][1] + "," + colorArray[p][2] + ");");
				params[3] == "horizontal"?x+=w:y+=h;
				tmpDOM.appendChild(g);
				if(y>=objArray[i].offsetHeight || x >= objArray[i].offsetWidth) break;
			}
			objArray[i].appendChild(tmpDOM);
			tmpDOM = null;
		}
	}
}

function getGradientObjects() {
	a = document.getElementsByTagName("*");
	objs = new Array();
	for(i=0;i<a.length;i++) {
		c = a[i].className;
		if(c != "") if(c.indexOf("gradient") == 0) objs[objs.length] = a[i];
	} 
	return objs;
}
	
function createColorPath(color1,color2) {
	colorPath = new Array();
	colorPercent = 1.0;
	do {
		colorPath[colorPath.length]=setColorHue(longHexToDec(color1),colorPercent,longHexToDec(color2));
		colorPercent-=.01;
	} while(colorPercent>0);
	return colorPath;
}
		
function setColorHue(originColor,opacityPercent,maskRGB) {
	returnColor=new Array();
	for(w=0;w<originColor.length;w++) returnColor[w] = Math.round(originColor[w]*opacityPercent) + Math.round(maskRGB[w]*(1.0-opacityPercent));
	return returnColor;
}

function longHexToDec(longHex) {
	return new Array(toDec(longHex.substring(0,2)),toDec(longHex.substring(2,4)),toDec(longHex.substring(4,6)));	
}

function toDec(hex) {	
	return parseInt(hex,16);
}
	
function makeGrandParent(obj) {
	disp = document.defaultView.getComputedStyle(obj,'').display;
	disp == "block"?nSpan = document.createElement("div"):	nSpan = document.createElement("span");
	mHTML = obj.innerHTML;
	obj.innerHTML = "";
	nSpan.innerHTML = mHTML;
	nSpan.setAttribute("style","position:relative;z-index:10;");
	obj.appendChild(nSpan);
}

if (typeof(lib) != "undefined" && typeof(lib.addWindowOnload) != "undefined") {
	lib.addWindowOnload(loadSidebar);
	lib.addWindowOnload(preloadImages);
	lib.addWindowOnload(createGradient);
}

