//script for open a pop up window for confidential callback
function openPopUpWindow(url,winName,features) {
  window.open(url,winName,features);
}

//print page function that opens the print window.
function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

//open a pop up window for email an article
function openPopUpWindow(url,winName,features) {
  window.open(url,winName,features);
}

//email an article function
function emailanarticle()
{
	var url=document.URL; 
	var title=document.title; 
	var city = "Lawyers";
	var script = "sitescript.js";
	var domain = "lawyers-north-america.com";
	var popupwindowurl = "/emailanarticle.php?url="+url+"&city="+city+"&script="+script+"&domain="+domain; 
	openPopUpWindow(popupwindowurl,'','scrollbars=no,resizable=no,width=450,height=275');
}

function validateemailanarticle( form )
{	
	if ( form.sendername.value.length < 1 ) {
		alert( "Please enter your name." );
		form.sendername.focus();
		return false;
	}
	if ( form.receivername.value.length < 1 ) {
		alert( "Please enter receiver's name." );
		form.receivername.focus();
		return false;
	}
	if ( form.receiveremail.value.length < 1 ) {
		alert( "Please enter receiver's email." );
		form.receiveremail.focus();
		return false;
	}

	return true;
}

//bookmark page function
function bookmarkus() 
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
		var url=document.URL;
		var title=document.title;
		
		window.external.AddFavorite(url,title);
	}
	else 
	{
		var msg = "Press CTRL+D to add a bookmark to this site";
		if(navigator.appName == "Netscape")
		{
			alert(msg);
		}
	}
}

//validate city page form
function validate( form ){
  if ( form.contact.value.length < 1 ) {
    alert( "Please enter an email address or phone number so that we can get back to you with a response to your question." );
    return false;
  }
  if ( form.message.value.length < 1 ) {
    alert( "Please enter a message or question.  Our team is pleased to help." );
    return false;
  }
  return true;
}

function validateCaliforniaCity( form ){
  if ( form.contactname.value.length < 1 ) {
    alert( "Please enter your name so that we can get back to you with a response to your question." );
    return false;
  }
  if ( form.contact.value.length < 1 && form.contactphone.value.length < 1) {
    alert( "Please enter an email address or phone number so that we can get back to you with a response to your question." );
    return false;
  }
  if ( form.message.value.length < 1 ) {
    alert( "Please enter a message or question.  Our team is pleased to help." );
    return false;
  }
  return true;
}
function validateblogquestion(form)
{
	if ( form.subject.value.length < 1 ) 
	{
		alert( "Please enter a subject of your question." );
		form.subject.focus();
		return false;
	}
	if ( form.message.value.length < 1 ) 
	{
		alert( "Please enter a question.  Our team is pleased to help." );
		form.message.focus();
		return false;
	}
	return true;
}

//script used on bankruptcy evaluation form
var panes = new Array();

function setupPanes(containerId, defaultTabId) {
		
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    /*if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;*/
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    /*paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";*/
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible  
  switch_tab(activeTab.name);
    for (var con in panes) {
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;    
}

//show / hide image layers
function switch_tab(objname)
{
	if(objname == "panel1submit")
	{
			showLayer('toptab1on');
			hideLayer('toptab1off');
			
			showLayer('toptab2off');
			hideLayer('toptab2on');			
	}
	if(objname == "panel2submit")
	{
			showLayer('toptab1off');
			hideLayer('toptab1on');
			
			showLayer('toptab2on');
			hideLayer('toptab2off');
	}
	if(objname == "panel3submit")
	{
			showLayer('toptab1off');
			hideLayer('toptab1on');
			
			showLayer('toptab2off');
			hideLayer('toptab2on');
	}
	if(objname == "panel4submit")
	{
			showLayer('toptab1off');
			hideLayer('toptab1on');
			
			showLayer('toptab2off');
			hideLayer('toptab2on');
	}
	if(objname == "panel5submit")
	{
			showLayer('toptab1off');
			hideLayer('toptab1on');
			
			showLayer('toptab2off');
			hideLayer('toptab2on');
	}
}

//show hide layers used for panels
function showLayer(layerid)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(layerid).style.visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[layerid].style.visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[layerid].visibility = "visible";
		document.getElementById(layerid).style.display = "block"; 
	}
}

function hideLayer(layerid)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(layerid).style.visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[layerid].style.visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[layerid].visibility = "hidden";
		document.getElementById(layerid).style.display = "none"; 
	}
}

//validate bankruptcy evaluation form
function validateevaluation(form)
{
	if ( form.firstname.value.length < 1 ) {
		alert( "Please enter your first name." );
		form.firstname.focus();
		return false;
	}
	if ( form.lastname.value.length < 1 ) {
		alert( "Please enter your last name." );
		form.lastname.focus();
		return false;
	}
	if ( form.email.value.length < 1 && form.phone.value.length < 1) {
		alert( "Please enter your email or phone number for us to contact you." );
		form.phone.focus();
		return false;
	}
	if ( form.provincesselect.value == "Select a Province")
	{
		alert( "Please select a province" );
		form.provincesselect.focus();
		return false;
	}
	if ( form.citiesselect.value == "Select a City")
	{
		alert( "Please select a city" );
		form.citiesselect.focus();
		return false;
	}
	if ( form.agreeterm.checked == false ) {
		alert( "Please check the terms and condition." );
		form.agreeterm.focus();
		return false;
	}
	return true;
}

function setcities() 
{
	showControl('cityrow');
	hideControl('cityother');
	var province = document.frm.provincesselect.options[document.frm.provincesselect.selectedIndex].value;
	var city = new Array();
	
	if(province == "Select a Province")
	{
		hideControl('cityrow');
		hideControl('cityother');
	}
	
	if (province == "Alberta") 
	{
		var city = new Array("Calgary", "Edmonton")
	}
	if (province == "British Columbia") 
	{
		var city = new Array("Abbotsford", "Burnaby", "Coquitlam", "Kelowna", "Prince George", "Richmond", "Surrey", "Vancouver", "Victoria")
	}
	if (province == "Manitoba") 
	{
		var city = new Array("Brandon", "Dauphin", "Portage", "Winnipeg")
	}
	if (province == "New Brunswick") 
	{
		var city = new Array("Fredericton", "Moncton", "Riverview", "Saint John")
	}
	if (province == "Newfoundland and Labrador") 
	{
		var city = new Array("St. John's")
	}
	if (province == "Nova Scotia") 
	{
		var city = new Array("Dartmouth", "Halifax", "Kentville", "Sackville")
	}
	if (province == "Ontario") 
	{
		var city = new Array("Brampton", "Brantford", "Cambridge", "Chatham", "Guelph", "Hamilton", "Kitchener", "London", "Mississauga", "Ottawa", "Pembroke", "Scarborough", "Thunder Bay", "Toronto", "Windsor")
	}
	if (province == "Quebec") 
	{
		var city = new Array("Montreal")
	}
	if (province == "Saskatchewan") 
	{
		var city = new Array("Regina", "Saskatoon")
	}
	
	var numofcities = city.length;
	
	//clear up city selection list and reload cities
	for (var i = (numofcities-1); i >= 1; i--)
	{
         document.frm.citiesselect.options[i]=null;
     }
	 document.frm.citiesselect.length = numofcities+1;
	 document.frm.citiesselect.options[0].text = "Select a City";
	 document.frm.citiesselect.options[0].value = "Select a City";
	 for (i = 0; i < numofcities; i++) 
	{
	  //document.frm.citiesselect.length = numofcities;
	  document.frm.citiesselect.options[i+1].text = city[i];
	  document.frm.citiesselect.options[i+1].value = city[i];
	  //document.frm.citiesselect.selectedIndex = 0;
	}
	document.frm.citiesselect.selectedIndex = 0;
}

function populate_provinces()
{
	document.writeln("<select name=\"provincesselect\" class=\"quoteselect\" onchange=\"setcities();\">");
	document.writeln("<option value=\"Select a Province\">Select a Province</option>");
	document.writeln("<option value=\"Alberta\">Alberta</option>");
	document.writeln("<option value=\"British Columbia\">British Columbia</option>");
	document.writeln("<option value=\"Manitoba\">Manitoba</option>");
	document.writeln("<option value=\"New Brunswick\">New Brunswick</option>");
	document.writeln("<option value=\"Newfoundland and Labrador\">Newfoundland and Labrador</option>");
	document.writeln("<option value=\"Nova Scotia\">Nova Scotia</option>");
	document.writeln("<option value=\"Ontario\">Ontario</option>");
	document.writeln("<option value=\"Quebec\">Quebec</option>");
	document.writeln("<option value=\"Saskatchewan\">Saskatchewan</option>");
	document.writeln("</select>");
}

/*function populate_cities()
{
	document.writeln("<select class=\"quoteselect\" name=\"citiesselect\">");
	// Netscape doesn't seem to like a SELECT menu without any <OPTION> elements
	document.writeln("<option value=\"Select a City\">Select a City</option>");
	// -->
	document.writeln("</select>");
}

*/
//-->

//show hide other city field
function showControl(divId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(divId).style.visibility = "visible";		
		if(navigator.appName == "Netscape")
		{
			document.getElementById(divId).style.display = "table-row"; 
		}
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			document.getElementById(divId).style.display = "block"; 
		}
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[divId].style.visibility = "visible";		
		document.getElementById(divId).style.display = "table-row"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[divId].visibility = "visible";		 
		document.getElementById(divId).style.display = "table-row"; 
	}
}

function hideControl(divId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(divId).style.visibility = "hidden";
		document.getElementById(divId).style.display = "none"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[divId].style.visibility = "hidden";
		document.getElementById(divId).style.display = "none"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[divId].visibility = "hidden";
		document.getElementById(divId).style.display = "none"; 
	}
}
function exitiframe(self)
{
	if (self != top) top.location = self.location;
}
//check empty fields
function checkemptyfield(form)
{
	if ( form.searchtext.value.length < 1 ) {
		alert( "Please enter a search phrase." );
		form.searchtext.focus();
		return false;
	}
	return true;
}

//check empty search fields
function checksearchbox(form)
{
	if ( form.q.value.length < 1 ) {
		alert( "Please enter a search phrase." );
		form.q.focus();
		return false;
	}
	return true;
}

/* Article Tools */
function choosefontsize(size) 
{
	var el = document.getElementById('sitecontainer');
	el.style.fontSize = size;
}
function ratethispage()
{
	var url=document.URL;
	var popupwindowurl = "/ratethispage.htm?url="+url; 
	openPopUpWindow(popupwindowurl,'','Toolbar = no, status=no,menubar=no,scrollbars=no,resizable=no,width=530,height=260');
}
function validateratepage(form)
{
	ratingselected = "";

	for (i = 0; i <5; i++) 
	{
		if (form.rating[i].checked) 
		{
			ratingselected = form.rating[i].value;
		}
	}
	if ( form.visitfrequency.value == "Please select" && form.features.value.length < 1 && form.recommend.value == "Please choose one" && ratingselected == "")
	{
		alert( "Please answer at least one question before you submit." );
		form.visitfrequency.focus();
		return false;
	}
	
	return true;
}

function testimonials()
{
	var popupwindowurl = "/testimonials-submit.htm"; 
	openPopUpWindow(popupwindowurl,'','Toolbar = no, status=no,menubar=no,scrollbars=no,resizable=no,width=530,height=345');
}
function validatetestimonials( form )
{	
	if ( form.testimonialssubmit.value.length < 1 ) {
		alert( "Please tell us what you think about our site." );
		form.testimonialssubmit.focus();
		return false;
	}
	return true;
}