
var req = null;

function InitXMLHttpRequest() {
	// Make a new XMLHttp object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
if (typeof window.ActiveXObject != 'undefined' ) req = new ActiveXObject("Microsoft.XMLHTTP");
else req = new XMLHttpRequest();
}

function SelectCountry(section, destination) {
	InitXMLHttpRequest();
	// Load the result from the response page
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				destination.innerHTML = req.responseText;
			} else {
				destination.innerHTML = "<select style=\"width:150px; margin:0px;\" class=\"index_select\"><option>WAIT LOADING DATA...</option></select>";
			}
		}
		req.open("GET", "http://www.theattorneylawyer.com/location.php?sec=" + section + "&sel=country", true);
		req.send(null);
	} else {
		destination.innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function SelectRegion(section, States, destination) { 
	if (States != '') {
		InitXMLHttpRequest();
		// Load the result from the response page
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					destination.innerHTML = req.responseText;
				} else {
					destination.innerHTML = "<select style=\"width: 150px;\"  margin:0px;\"><option>WAIT LOADING DATA...</option></select>";
				}
			} 
			req.open("GET", "http://www.theattorneylawyer.com/location.php?sec=" + section + "&sel=region&States=" + States, true);
			req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	} else {
		destination.innerHTML = "Country is not selected";
	}
 }

function countTotal(catVal) {
		var drpDnCatCnt;
		
		total = 0
		
		drpDnCatCnt = 6; //Max. number of category dropdowns
		
		if (isNaN(total)) total = 0;
		
		for (i=1;i<=drpDnCatCnt;i++)
		{
			if (document.getElementById("CATEGORY_ID_" + i).value != "")
			{
				total = total + 1;
			}
			
		}
		
		if (total < 0) total = 0;
		
		
		if (total == "0") { document.getElementById("listingsNum").innerHTML = "0"; }
		else if (total == "1") { document.getElementById("listingsNum").innerHTML = total+" Listing"; }
		else { document.getElementById("listingsNum").innerHTML = total+" Listings"; }

		var subTotal = total*150;
		var totalAmount = 0;
		var discount = Math.floor((total-1)/10);
		
		if (total == "1") totalAmount = 150;
		else if (total == "2") totalAmount = 285;
		else if (total == "3") totalAmount = 405;
		else if (total == "4") totalAmount = 505;
		else if ((total >= "5") && (total <= "10")) totalAmount = 505 + ((total-4) * 100);
		else if (total >= "11") totalAmount = totalAmount = 505 + ((total-4-discount) * 100);

      var savings = (total*150)-totalAmount;

		//document.getElementById("listingsSubTotal").innerHTML = subTotal;
		//document.getElementById("listingsSavings").innerHTML = savings;
		document.getElementById("listingsTotal").innerHTML = totalAmount;
		
		//count additional savings
		total++;
		var discount = Math.floor((total-1)/10);
		if (total == "1") totalAmount = 150;
		else if (total == "2") totalAmount = 285;
		else if (total == "3") totalAmount = 405;
		else if (total == "4") totalAmount = 505;
		else if ((total >= "5") && (total <= "10")) totalAmount = 505 + ((total-4) * 100);
		else if (total >= "11") totalAmount = totalAmount = 505 + ((total-4-discount) * 100);
		
		var additionalSavings = (total*150)-totalAmount-savings;

		//document.getElementById("additionalSavings").innerHTML = "BUY ONE MORE AND SAVE ADDITIONAL: <b>$" + additionalSavings + ".00</b>";
		
		//total--;
	}


function RunFlash(width, height, src, align) {

  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' +width+ '" height="' +height+ '" align="' +align+ '">\n');
  document.write('<param name="movie" value="' +src+ '" />\n');
  document.write('<param name="wmode" value="transparent" />\n');
  document.write('<param name="id" value="myFlash" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<embed src="' +src+ '" quality="high" name="myFlash" and swLiveConnect="true" wmode="transparent" align="' +align+ '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' +width+ '" height="' +height+ '">\n');
  document.write('</embed>\n');
  document.write('</object>\n');
}

function setState(state) {
	document.formSearch.dd_states.value=state;
}

	
	function runFlash(width, height, src, align) {
	  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' +width+ '" height="' +height+ '" align="' +align+ '">\n');
	  document.write('<param name="movie" value="' +src+ '" />\n');
	  document.write('<param name="wmode" value="transparent" />\n');
	  document.write('<param name="quality" value="high" />\n');
	  document.write('<embed src="' +src+ '" quality="high" wmode="transparent" align="' +align+ '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' +width+ '" height="' +height+ '">\n');
	  document.write('</embed>\n');
	  document.write('</object>\n');
	}

function fn_validateForm(){
	
		var strMsg = "";
		if (document.formSearch.States.selectedIndex < 2)
			strMsg = "Please select a state." ;
		if (document.formSearch.PracticeAreas.selectedIndex < 2){
			if (strMsg != "") 	
				strMsg = "Please select a state and a practice area." ;
			else
				strMsg = "Please select a practice area." ;
		}
		if (strMsg != "") {
			alert(strMsg);
			return false;
		}
		else{
         var location=("http://www.theattorneylawyer.com/"+document.formSearch.States.value +"/" + document.formSearch.PracticeAreas.value +"/");
         this.location.href = location;
		}
	}	
	
	  	function fn_validateForm_pc(){
	
		var strMsg = "";
		if (document.getElementById("states").value == "")
			strMsg = "Please select a state." ;
		if (document.formSearch.PracticeAreas.selectedIndex < 2){
			if (strMsg != "") 	
				strMsg = "Please select a state and a practice area." ;
			else
				strMsg = "Please select a practice area." ;
		}
		if (strMsg != "") {
			alert(strMsg);
			return false;
		}
		else{
         var location=("http://www.theattorneylawyer.com/"+document.formSearch.States.value +"/" + document.formSearch.PracticeAreas.value +"/");
         this.location.href = location;
		}
	}	
	

  	function fn_validateForm_Int(){
	
		var strMsg = "";
		if (document.formSearch.Countries.selectedIndex < 2)
			strMsg = "Please select a country." ;
		if (document.formSearch.PracticeAreas.selectedIndex < 2){
			if (strMsg != "") 	
				strMsg = "Please select a country and a practice area." ;
			else
				strMsg = "Please select a practice area." ;
		}
		if (strMsg != "") {
			alert(strMsg);
			return false;
		}
		else{
         var location=("http://www.theattorneylawyer.com/"+document.formSearch.States.value +"/" + document.formSearch.PracticeAreas.value +"/");
         this.location.href = location;
		}
	}