/* ================================================================ 
Local JavaScript
Created by: David Copp
===================================================================*/

document.onkeypress = keyHandler;


function keyHandler(e) {
		var pressedKey;
		if (document.all)	{ e = window.event; pressedKey = e.keyCode; }
		if (document.layers || e.which) { pressedKey = e.which; }
		
		if(pressedKey == 13)
		{
			var zipval  = trim(document.getElementById("consultantZip").value);
			var productcode = document.getElementById("productcodes").value;
		  	if(zipval != null && zipval != '' && zipval != 'zip code')
			{
				CallZipLookUp(productcode);

			}
			
				 
			
		}
}




function myWindow(url, a){
	window.open(url,a,"width=1016, height=700, toolbar=yes, menubar=yes, scrollbars=yes, resizeble=yes")
}

function podTabs() {
	$(".basicPod .tabs ul li").click(function(){
		$(".basicPod .tabs ul li").removeClass("active");
		$(this).addClass("active");
	});
}

/* Temp function*/
function prodTabs() {	
	try{
	    var getURL = document.URL;
	    var getUL = document.getElementById("TabList");
	    var getAnchor = getUL.getElementsByTagName("a");	    
	    for(var i=0; i<=getAnchor.length; i++){
	    //alert(getAnchor[i].href);
	        if(getAnchor[i].href == getURL){	            
	            getAnchor[i].className = "selected";
	            if(i>0){
	                getAnchor[0].className = "";
	            }
	            return false;
	        } else{
	            getAnchor[0].className = "selected";
	        }
	    }
	}
	catch (Exception){
	    //Log this error
	}
}

function setFindSpecialist() {
	$("#findrep").focus(function(){
		$("#findrep").css("color","#000");
		$("#findrep").val("");
		}, function () {
		$("#findrep").css("color","#ccc");
	});
}

function modalPopup() {
	if($.browser.msie && $.browser.version=="6.0") {
		// the modal popup doesn't work in IE6 so we're opening it in a new window.
		window.open ("modalForm-ie6.asp","newwindow","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=600,height=450");
	}
	else {
		$("#modal").modal({
			opacity:60,
			overlayCss: {backgroundColor:"#000"}
		});
	}
}
function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function CallZipLookUp(productCode){

var zipval  = trim(document.getElementById("consultantZip").value);


  if(zipval != null && zipval != '' && zipval != 'zip code')
  {	
	
//url = 'http://law.lexisnexis.com/spn/default.aspx?tabtype=150&zipcode='+zipval+'&products='+productCode+'#searchlist';
  
	  url = 'http://law.lexisnexis.com/spn/default.aspx?ZipCode='+zipval+'&Products='+productCode;

window.location = url;
//window.open(url,"","");
	 


  }
  else{
    alert("Zip Code cannot be blank.");
  }
}

function subMenu() {
	if ($("#menuTab").length > 0){
		
		$("#menuTab .submenu").hide();
		
		$("#menuTab").hoverIntent(function(){
			$(this).find(".submenu").fadeIn("fast");
			}, function () {
			$(this).find(".submenu").hide();
		});
	}
}

function contactPod() {
	if ($("#contactUs").length > 0){
		
		$("#contactUs div.contactContent").hide();
		$("#contactUs div.contactContent:first").show();
		$("#contactUs h2:first").addClass("active");
		
		$("#contactUs h2 span").click(function(){
			if ($(this).parent("h2").attr("class")=="active"){
				return false;
			}
			$("#contactUs h2").removeClass("active");
			$(this).parent("h2").addClass("active");
			$("#contactUs div.contactContent").slideUp();
			$(this).parent("h2").next("div.contactContent").slideDown();
		});
		
		$("#chatBox textarea").focus(function(){
			if ($(this).val()=="Please type your question here...")
			{
				$(this)
					.val("")
					.addClass("active")
			}
		});
		$("#chatBox textarea").blur(function(){
			if ($(this).val()=="")
			{
				$(this)
					.val("Please type your question here...")
					.removeClass("active")
			}
		});


// Set textbox styles
		$("#findConsultant input").focus(function(){
			if ($(this).val()=="zip code")
			{
				$(this)
					.val("")
					.addClass("active")
			}
		});
		$("#findConsultant input").blur(function(){
			if ($(this).val()=="")
			{
				$(this)
					.val("zip code")
					.removeClass("active")
			}
		});
	}
}

function helpTable() {
	if ($(".helpTable").length > 0){
		$(".helpTable td.details div a").click(function(){
			var url = $(this).attr("href");
			var target = $(this).attr("target");
			if(target=="_blank"){
				window.open(url,'newWindow','scrollbars=1,width=900,height=600');
			}
			else {
				location.href=url;
			}
		});
		
		$(".helpTable td.details").toggle(function(){
			$(this).children("div").slideToggle();
			$(this).addClass("detailsActive");
			$(this).css("background-image","url(/law-firm-practice-management/images/icons/btn-details-close.gif)");
			}, function () {
			$(this).children("div").slideToggle();
			$(this).removeClass("detailsActive");
			$(this).css("background-image","url(/law-firm-practice-management/images/icons/btn-details.png)");
		});
		
		$(".helpTable tr").hover(function(){
			$(this).find("td").css("background-color","#eaeaea");
			$(this).find("th").css("background-color","#eaeaea");
			}, function () {
			$(this).find("td").css("background-color","#f8f8f8");
			$(this).find("th").css("background-color","#f4f4f4");
		});
		
		
		
	}
}

function breadcrumbClass(){
    try{
        $("#breadcrumbHolder ul").addClass("breadcrumb");
        $("#breadcrumbHolder ul li").first().addClass("home");
        $("#breadcrumbHolder ul li a").first().attr("href","/law-firm-practice-management");
        $("#breadcrumbHolder ul li:eq(1)").css("display", "none");
        var pcLaw =  $("#breadcrumbHolder ul li").last().html(); 
        
        if(pcLaw == "Pclaw"){          
            $("#breadcrumbHolder ul li").last().html("PCLaw");
        }        
        var getText = pcLaw.search("Pclaw");
        if(getText!=-1){
            $("#breadcrumbHolder ul li").last().html("PCLaw");
        }
        var ProductServ = $("#breadcrumbHolder ul li:eq(2) a").html();
        var ProdSer =  $("#breadcrumbHolder ul li:eq(2)").html();   
        // var ProdSer =$("#breadcrumbHolder").find("li").eq(2).html();  
        //var ProdSer =$("#breadcrumbHolder ul li").last().text(); 
             
        if(ProductServ=="Products And Services"){                   
            $("#breadcrumbHolder ul li:eq(2) a").html("Products &amp; Services")
        }
          
        if(ProdSer=="Products And Services"){             
            
            //$("#breadcrumbHolder ul li:eq(2)").html("Products &amp; Services")
            $("#breadcrumbHolder ul li").last().html("Products &amp; Services")
        }

       
        
        $("#breadcrumbHolder").show();    
    }
    catch(Error){
    }
}

function searchQuery(a){
	var URLRedirect = "/law-firm-practice-management/search.aspx?query="+a;
	window.location = URLRedirect;
}
function search(){
	if($(".field-btn-wrapper").length > 0){
		$(".field-btn-wrapper button").click(function(){
			var getQuery = $("#searchfield").val();
			var URLRedirect = "/law-firm-practice-management/search.aspx?query="+getQuery;
			window.location = URLRedirect;
		});
		var  smallSearchBox = $("#searchfield");	
		var code =null;
		smallSearchBox.keypress(function(e)
		{		
			code= (e.keyCode ? e.keyCode : e.which);
			if (code == 13) {				
				searchQuery($("#searchfield").val());
				return false;
			};		
		});
	}
	if($("#P1").length > 0){
		$("input#BSearch").click(function(){
				searchQuery($("#searchtop").val());
				return false;						
		});
		var largeSearchBox = $(".largesearchfield");
		var code =null;
		largeSearchBox.keypress(function(e)
		{			
			code= (e.keyCode ? e.keyCode : e.which);
			if (code == 13) {
				searchQuery($("#searchtop").val());
				return false;				
			};		
		});
	}
}

function checkQueryString(){
	if($("#P1").length > 0){
		var querystring = location.search.replace( '?', '' ).split( '&' );	
		var queryObj = {};
		for ( var i=0; i<querystring.length; i++ ) {		  
		  	var name = querystring[i].split('=')[0];
		  	var value = querystring[i].split('=')[1];
		  	queryObj[name] = value;
		}
		if(queryObj[name]!=""){
			$(".largesearchfield").val(queryObj[name]);
		}
	}
}

$(document).ready(function() {
	 	 
	 podTabs();
	 prodTabs();
	 setFindSpecialist();
	 subMenu();
	 contactPod();
	 helpTable();
	 breadcrumbClass();
	 search();	 	
	 checkQueryString();
});
