function init ()
{
	loadPage ();
	$("#divMenu > div > a").mouseover(function () {$(this).animate ({marginLeft:"12px"}); $(this).css ("color", "#f40"); $(this).parent().attr ("className", "cVMenuHover")});
	$("#divMenu > div > a").mouseout(function () {$(this).animate ({marginLeft:"0px"}); $(this).css ("color", "#A64B00"); $(this).parent().attr ("className", "cVMenu")});
}

function getCInfo (refId)
{
	$("#divContentRight").fadeOut ("fast");
	for (var i = 1;i < 2;i++)
	{
		if (i == refId)
		{
			document.getElementById ("lblCompany" + i).className = "cOfficeLinkFront";
		}
		else
		{
			document.getElementById ("lblCompany" + i).className = "cOfficeLinkBack";
		}
	}
	
	if (!httpReq)
	{
		httpReq = createRequestObject ();
	}

	httpReq.open("GET", mainUrl + "receiver.php?req=comp_info&qry=" + refId, true);
	httpReq.onreadystatechange = loadRPane;
	httpReq.send (null);
}

function getOffice (refId)
{
	$("#divContentRight").fadeOut ("fast");
	for (var i = 1;i < 12;i++)
	{
		if (i == refId)
		{
			document.getElementById ("lblOffice" + i).className = "cOfficeLinkFront";
		}
		else
		{
			document.getElementById ("lblOffice" + i).className = "cOfficeLinkBack";
		}
	}
	
	if (!httpReq)
	{
		httpReq = createRequestObject ();
	}

	httpReq.open("GET", mainUrl + "receiver.php?req=office_info&qry=" + refId, true);
	httpReq.onreadystatechange = loadRPane;
	httpReq.send (null);
}

function getInsuranceGroup (refGroup, refSubGroup)
{
	$("#divContentRight").fadeOut ("fast");
	for (var i = 1;i < 6;i++)
	{
		if (i == refGroup)
		{
			document.getElementById ("lblInsurance" + i).className = "cOfficeLinkFront";
		}
		else
		{
			document.getElementById ("lblInsurance" + i).className = "cOfficeLinkBack";
		}
	}
	
	if (!httpReq)
	{
		httpReq = createRequestObject ();
	}

	httpReq.open("GET", mainUrl + "receiver.php?req=insurance_group&group=" + refGroup + "&subgroup=" + refSubGroup, true);
	httpReq.onreadystatechange = loadRPane;
	httpReq.send (null);
}

function getCalculator (refCalculator)
{
	$("#divContentRight").fadeOut ("fast");
	for (var i = 1;i < 6;i++)
	{
		if (i == refCalculator)
		{
			document.getElementById ("lblCalculators" + i).className = "cOfficeLinkFront";
		}
		else
		{
			document.getElementById ("lblCalculators" + i).className = "cOfficeLinkBack";
		}
	}
	
	if (!httpReq)
	{
		httpReq = createRequestObject ();
	}

	httpReq.open("GET", mainUrl + "receiver.php?req=calc&qry=" + refCalculator, true);
	httpReq.onreadystatechange = loadRPane;
	httpReq.send (null);
}

function loadRPane ()
{
	if (checkReadyState (httpReq))
	{
		if (httpReq.responseText)
		{
			document.getElementById ("divContentRight").innerHTML = httpReq.responseText;
			$("#divContentRight").fadeIn ("fast");
		}
	}
}

function checkPolicy ()
{
	var txtPolicy = document.getElementById ("txtPolicy").value;
	var txtIName = document.getElementById ("txtIName").value;
	
	if (txtPolicy.replace(/^\s+|\s+$/g,"") == "" || txtIName.replace(/^\s+|\s+$/g,"") == "")
	{
		alert (document.getElementById ("hddnPleaseFill").value);
		return;
	}
	
	$("#divPolicyResult").fadeOut ("fast");
	
	if (!httpReq)
	{
		httpReq = createRequestObject ();
	}

	httpReq.open("GET", mainUrl + "receiver.php?req=check_policy&policy=" + txtPolicy + "&owner=" + txtIName, true);
	httpReq.onreadystatechange = loadPolicyInfo;
	httpReq.send (null);
}

function loadPolicyInfo ()
{
	if (checkReadyState (httpReq))
	{
		if (httpReq.responseText)
		{
			document.getElementById ("divPolicyResult").innerHTML = httpReq.responseText;
			$("#divPolicyResult").fadeIn ("fast");
		}
	}
}

function submitOnlineForm ()
{
	var requiredTexts = $("input[class='required'], select[class='required']");
	var hddnCorrectValues = document.getElementById ("hddnCorrectValues").value;
	var hddnPolicyType = document.getElementById ("hddnPolicyType").value;
	var allCorrect = true;
	var getQry = "";
	
	for (var i = 0;i < requiredTexts.length;i++)
	{
		var actualValue = requiredTexts[i].value.replace(/^\s+|\s+$/g, "");
		if (actualValue == "" || actualValue == "- -")
		{
			$("#" + requiredTexts[i].id).css ("backgroundColor", "#fdd");
			$("#" + requiredTexts[i].id).blur (function (){$(this).css ("backgroundColor", "#ffc")});
			allCorrect = false;
		}
		else
		{
			getQry += "&" + requiredTexts[i].id + "=" + escape (requiredTexts[i].value);
		}
	}
	var radioChecks = $("input[type='radio'], input[type='checkbox']");
	for (i = 0;i < radioChecks.length;i++)
	{
		if (radioChecks[i].checked === true)
		{
			getQry += "&" + radioChecks[i].name + radioChecks[i].id + "=" + escape (radioChecks[i].value);
		}
	}
	//alert (getQry);
	
	
	if (allCorrect === false)
	{
		alert (hddnCorrectValues); 
	}
	else
	{
		if (!httpReq)
		{
			httpReq = createRequestObject ();
		}
		
		httpReq.open("GET", mainUrl + "receiver.php?req=online&policy=" + hddnPolicyType + getQry, true);
		httpReq.onreadystatechange = loadOnlineResult;
		httpReq.send (null);
	}
	
}

function loadOnlineResult ()
{
	if (checkReadyState (httpReq))
	{
		if (httpReq.responseText)
		{
			var hddnSuccess = document.getElementById ("hddnSuccess").value;
			alert (hddnSuccess);
			document.forms["frmMain"].reset ();
		}
	}
}

function array_search (needle, haystack, argStrict)
{
	// http://kevin.vanzonneveld.net
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: Brett Zamir (http://brett-zamir.me)
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
	// *     returns 1: 'surname'

	var strict = !!argStrict;
	var key = '';
	
	for	(key in haystack)
	{
		if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle))
		{
			return key;
		}
	}

	return false;
}

function slideIn ()
{
	$("#divSlider").animate ({left:"-330px"}, {duration:500, queue:false});
}

function slideOut ()
{
	$("#divSlider").animate ({left:"-140px"}, {duration:500, queue:false});
}
