// add the .click() method to html elements
try{
	HTMLElement.prototype.click = function()
	{
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}catch(e){;}

function getAjaxObj(func)
{
	var xmlhttp=false;
	if(window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			// 4 = "loaded"
			if (xmlhttp.status==200)
			{
				// 200 = OK					
				if(xmlhttp.responseText!="")
				{	
					if(func==null)
						eval(xmlhttp.responseText)
					else
						func(xmlhttp.responseText)
				}
			}
			else
			{
				alert("Problem retrieving XML data");
			}
		}
	};
	return xmlhttp;
}

function do_arrows() {		
	var imgw=21;
	var imgh=21;
	
	var img=document.createElement("img");
	img.src="/images/leftnav_top2.gif";
	img.style.position="absolute";	
	img.style.top=($("#leftnav_current").offset().top-imgh)+"px";
	img.style.left=($("#leftnav_current").width()-imgw)+"px";	
	document.body.appendChild(img);	
	
	var img=document.createElement("img");
	img.src="/images/leftnav_bottom2.gif";
	img.style.position="absolute";	
	img.style.top=($("#leftnav_current").offset().top+$("#leftnav_current").height())+"px";
	img.style.left=($("#leftnav_current").width()-imgw)+"px";	
	document.body.appendChild(img);		
}

function reset_frm() {
	var frm=document.getElementById("find_att_frm");
	var inp=frm.getElementsByTagName("input");
	for(var x=0;x<inp.length;x++) {
		if(inp[x].type=="text") {
			inp[x].value="";
		}
	}
	var sel=frm.getElementsByTagName("select");
	for(var x=0;x<sel.length;x++) {		
		sel[x].options[0].selected=true;		
	}
}

function submit_frm(frm) {
	document.getElementById(frm).submit();
}

$(function(){
	do_arrows();
	company_form();
	//$(".next").attr("disabled","disabled").css({"opacity" : ".3", "cursor" : "default"});
	$(".next").attr("disabled","disabled").addClass("notactive").removeClass("active");
	$("#agree").click(function() {
		var checked_status = this.checked;
		if (checked_status == true) {
			//$(".next").removeAttr("disabled").css({"opacity":"1.0","cursor":"pointer"});
			$(".next").removeAttr("disabled").addClass("active").removeClass("notactive");
		}
		else {
			//$(".next").attr("disabled", "disabled").css({"opacity" : ".3", "cursor" : "default"});
			$(".next").attr("disabled", "disabled").addClass("notactive").removeClass("active");
		}
	});
	$(".attorney_name_box").hide();
	$(".attorney_sheet").click(function(){
		
		var tmp = $(this).attr("name").split("_");
		var int=tmp[tmp.length-1];
		
		if ($(this).val()=="1"){
			$("#attorney_name_box_"+int).show();
			$("#attorney_name_"+int).addClass("required");
		} else {
			$("#attorney_name_box_"+int).hide();
			$("#attorney_name_"+int).removeClass("required");
		}
		
		
	});
});

function company_form(){
	$(".services_form input:text").css({"border":"1px solid #003263","padding":"2px"});
	$(".services_form input:text").focus(function(){
		$(this).css({"background":"#f4f4f4"});
	});
	$(".services_form input:text").blur(function(){
		$(this).css("background","#fff");
	});
	$(".corporate_services_form").validate();
}

var company_counter=1;
function add_company() {
	var tbl=document.getElementById("company_tbl");
	var x=tbl.rows.length-1;
	tbl.insertRow(x);
	tbl.rows[x].id="company_row_"+company_counter;
	tbl.rows[x].insertCell(0);
	tbl.rows[x].insertCell(1);
	tbl.rows[x].insertCell(2);
	tbl.rows[x].cells[0].innerHTML='<strong><label for="companyinput_'+company_counter+'">* Company Name</label></strong>';
	tbl.rows[x].cells[1].innerHTML='<input name="companyinput_'+company_counter+'" id="companyinput_'+company_counter+'" class="required one" type="text" />';
	tbl.rows[x].cells[2].innerHTML='<a href="javascript:remove_company('+company_counter+');"><img src="/images/remove.gif" alt="Remove"/></a>';
	
	company_counter++;
	tbl.rows[x].cells[1].getElementsByTagName("input")[0].focus();
	company_form();
}

function remove_company(i) {
	var tr=document.getElementById("company_row_"+i);
	tr.parentNode.removeChild(tr);
}

function add_principal(id) {
	var div=document.getElementById("add_principal_div_"+id);
	var tbls=div.getElementsByTagName("table");
	var tblcount=tbls.length;
	// there will always be one
	var newtbl=tbls[0].cloneNode(true);
	div.appendChild(newtbl);
	var inp=newtbl.getElementsByTagName("input");
	for(var x=0;x<inp.length;x++) {
		inp[x].value='';
	}
	company_form();
	update_add_principal_counter(id);
}

function update_add_principal_counter(id) {
	var div=document.getElementById("add_principal_div_"+id);
	var tbls=div.getElementsByTagName("table");
	var tblcount=tbls.length;
	for(var x=0;x<tbls.length;x++) {
		tbls[x].rows[0].cells[0].innerHTML='<strong>'+(x+1)+'</strong>';
	}	
}