//Constants
var siteDomain = "http://www.lg-legal.com";


//Functions

function showHide(obj,lev) {
     var parent = obj.parentNode;
     //alert('ff'+parent.tagName+'='+'open_level'+lev);
     if (parent.className=='open_level'+lev) {
          //alert(''+parent.id+'=closed_level'+lev);
          parent.className = 'closed_level'+lev;
          setChildClass(parent,lev++,'hide');
     } else {
          parent.className = 'open_level'+lev;
          setChildClass(parent,lev++,'show');
     }
}

function setChildClass(obj,lev,cl) {

     for( var x = 1; x < obj.childNodes.length; x++ ) {
        // alert(x+'..'+obj.childNodes[x].tagName);

         if (obj.childNodes[x].className==cl+'_level'+lev) {
              obj.childNodes[x].className=cl+'_level'+lev;
         } else {
              obj.childNodes[x].className=cl+'_level'+lev;
         }
     }

}

function addToFavourites()
{
	title = document.title;
	url = location.href;

	if (window.sidebar)
	{
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{
		// IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{
		// Opera Hotlist
		var link = document.createElement('a');
		link.setAttribute('rel','sidebar');
		link.setAttribute('href',url);
		link.setAttribute('title',title);
		link.click();
		// return true;
	} else {
                  // Safari and others
                  alert('This function is not supported in your web browser. Please press Ctrl-D/Command-D to bookmark this page.');
         }

}

function setLocation(myURL) {
         //Moves browser to new location
	document.location = myURL;
}

function encodeURL(myStr) {
         //Returns a suitable version of string that can be used as a parameter in URL
	var returnStr = escape(myStr);
	returnStr = replaceAll(returnStr, "+", "%2B");
	returnStr = replaceAll(returnStr, "/", "%2F");
	returnStr = replaceAll(returnStr, "'", "%27");  
	return returnStr;
}

function decodeURL(myStr) {
         //Returns a URL encoded string back to normal
	var returnStr = replaceAll(myStr, "%2F", "/"); 
	returnStr = replaceAll(returnStr, "%2B", "+");
	returnStr = replaceAll(returnStr, "%27", "'"); 
         returnStr = unescape(returnStr);
	return returnStr;
}

function setFormField(myFormFieldID, myStr) {
    //Sets a form element to be 
    var x = document.getElementById(myFormFieldID);
    x.value=decodeURL(myStr);
}

function setInnerHTML(myElementID, myStr) {
    //Sets a form element to be 
    var x = document.getElementById(myElementID);
    x.innerHTML = myStr;
}


function getQueryVariable(searchStr) {
    var qryStr = window.location.href.substr(window.location.href.indexOf('?')+1);
    var returnStr = '';
    if (searchStr != '') {
         returnStr = qryStr.substr(qryStr.indexOf(searchStr)+searchStr.length+1);
         //basic URL encoding clean up
         returnStr = decodeURL(returnStr);
    }
    return returnStr;
}


function replaceAll(myStr, searchStr, replaceStr) {
	//Replaces all instances of searchStr with replaceStr in myStr (ensure search/replace not the same)
	if (myStr.indexOf(searchStr) != -1 && searchStr != replaceStr) {
		//found, so replace and recurse to remove further instances
		return replaceAll(myStr.replace(searchStr, replaceStr), searchStr, replaceStr);
	} else {
		//not found, so just return original
		return myStr;
	}
}


// SEARCH BOX VALIDATION FUNCTIONS

function checkTextEnteredRight() {
 return checkTextEntered('right_search_box');
}

function checkTextEnteredTop() {
 return checkTextEntered('search_box');
}

function checkTextEntered(id) {
 var e  = document.getElementById(id);
 var result = true;
 
 if(e.value == '') {
  alert('Please enter a search keyword');
  e.focus();
  result = false;
 }
 return result;
}


// MAIN NAVIGATION FUNCTIONS

function highlightMainNavigation(maxItem) {

// JavaScript Document

var sectionid;
var styleObject;

if(document.getElementById('section') != null) {
	sectionid 		= parseInt(document.getElementById('section').value);
	
	// Get the child nodes of the menu
	var nav 		= document.getElementById('nav');
	
	if(sectionid > 0 && sectionid <= maxItem) {
		
                  // Go back one node
                  sectionid--;			
		
		styleObject = nav.childNodes[sectionid].childNodes[0].style;
		styleObject.background = 'url(http://preview-lg.pepperio.net/assets/css/lg_style/button_active.gif) no-repeat top right';
		styleObject.color	= '#4a9f0b';

                  // Make sure all ok for next node (important for Firefox/Safari)
                  styleObject_next = nav.childNodes[sectionid+1].childNodes[0].style;
                  styleObject_next.color	= '#333333';
                  styleObject_next.background = 'none';

	}

}

}



// PAGE RESIZE FUNCTIONS

function resizePage(mySubNavLoc, myRightColLoc) {

//Resize page depth dynamically
var h_browserHeight_bottommargin = 36;
var browserHeight;

if(BrowserDetect.browser == 'Firefox' || BrowserDetect.browser == 'Safari') {
		browserHeight = window.innerHeight;
} else if(BrowserDetect.browser == 'Explorer') {
		browserHeight = document.documentElement.clientHeight;
}

//if (page_height < browserHeight) {
	page_height = browserHeight - h_browserHeight_bottommargin;
//}

//Adjust height
//alert("sub_nav:"+h_sub_nav+"; right_column:"+h_right_column+"; main_column:"+h_main_column+";");

document.getElementById("page").style.height = page_height + "px";

}


function resizePage2(mySubNavLoc, myRightColLoc) {

//Resize page depth dynamically
var h_browserHeight_bottommargin = 36;
var browserHeight;

if(BrowserDetect.browser == 'Firefox' || BrowserDetect.browser == 'Safari') {
		browserHeight = window.innerHeight;
} else if(BrowserDetect.browser == 'Explorer') {
		browserHeight = document.body.clientHeight;
}

//if (page_height < browserHeight) {
	page_height = browserHeight - h_browserHeight_bottommargin;
//}

//Adjust height
//alert("sub_nav:"+h_sub_nav+"; right_column:"+h_right_column+"; main_column:"+h_main_column+";");

document.getElementById("page").style.height = page_height + "px";

}

// ADJUST TEXT SIZE FUNCTIONS AND INITIALISATION

var SMALL_SHEET 	= 'screen_small.css';
var NORMAL_SHEET	= 'screen_normal.css';
var LARGE_SHEET	= 'screen_large.css';
var HUGE_SHEET	= 'screen_huge.css';

function initTextResize() {

// When the page loads, we need to check cookies to see if the user has changed the stylesheet
if(getCookieValue('lg_stylesheet') == '') {
	// cookie doesn't exist so set to the default sheet
	setCookieValue('lg_stylesheet', NORMAL_SHEET, 100);
} else {
	// Set the current stylesheet to the one in the cookie	
	var curSheetPath	= document.getElementById('textSize').href;
	var newSheet		= '';
	var index			= curSheetPath.lastIndexOf('/');
	
	if(index >= 0) {
		curSheetPath	= curSheetPath.slice(0,index+1);
	}
	
	newSheet 			= getCookieValue('lg_stylesheet');
//alert(curSheetPath + newSheet);
	if(newSheet != '') {
		document.getElementById('textSize').href = curSheetPath + newSheet;
                  //Resize the page
//alert('loc:'+curLoc);
                  resizePage(curLoc);	
         }
}
}

function changeTextSize(dir) {
	var curSheetOrig	= document.getElementById('textSize').href;
	var curSheet		= '';
	var curSheetPath	= '';
	var newSheet		= '';
	var index			= curSheetOrig.lastIndexOf('/');
	
	if(index >= 0) {
		curSheet		= curSheetOrig.slice(index+1);
		curSheetPath	= curSheetOrig.slice(0,index+1);
	}
		
	switch(curSheet) {
		case SMALL_SHEET:
			if(dir == 'up') newSheet = NORMAL_SHEET;
			break;
		case NORMAL_SHEET:
			if(dir == 'up') newSheet = LARGE_SHEET; else newSheet = SMALL_SHEET;
			break;
		case LARGE_SHEET:
			if(dir == 'up') newSheet = HUGE_SHEET; else newSheet = NORMAL_SHEET;
			break;
		case HUGE_SHEET:
			if(dir == 'down') newSheet = LARGE_SHEET;
			break;
		default:
			newSheet = NORMAL_SHEET;
			break;
	}
	
	if(newSheet != '') {
                  document.getElementById('textSize').href = curSheetPath + newSheet;
//alert('setting cookie:'+newSheet);		
		setCookieValue('lg_stylesheet', newSheet, 100);

                  //Resize the page again
                  resizePage(curLoc);
	}
}


// COOKIE HANDLING FUNCTIONS

function getCookieValue(c_name) {
	if (document.cookie.length>0) {
		c_start			= document.cookie.indexOf(c_name + "=");
		
		if (c_start!=-1) { 
			c_start		= c_start + c_name.length+1;
			c_end		= document.cookie.indexOf(";",c_start);
			
			if (c_end == -1) 
				c_end	= document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	
	return ""
}

function setCookieValue(c_name, value, expiredays) {
	var exdate		= new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie	= c_name+ "=" + escape(value)+
		((expiredays==null) ? "" : ";expires=" + exdate.toUTCString());
}



// FLASH EMBEDDING

function writeFlashBanner() {

if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
	alert("This page requires AC_RunActiveContent.js.");
} else {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion) {  // if we've detected an acceptable version
		// embed the flash movie
		AC_FL_RunContent(					                  'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
			'width','595',
			'height','160',
			'align','middle',
			'src','/assets/Picture/page1-15520',
			'quality','high',
			'bgcolor','#4a9f0b',
			'allowscriptaccess','sameDomain',
			'pluginspage','http://www.macromedia.com/go/getflashplayer',
			'movie','/assets/Picture/page1-15520'
			); //end AC code
	} else {  // flash is too old or we can't detect the plugin
		var alternateContent = '<img src="/assets/Picture/banner_noflash.jpg" width="595" height="160"/>';
		document.write(alternateContent);  // insert non-flash content
	}
}

}


function writeFlashBanner_bh() {

if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
	alert("This page requires AC_RunActiveContent.js.");
} else {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion) {  // if we've detected an acceptable version
		// embed the flash movie
		AC_FL_RunContent(					                  'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0',
			'width','595',
			'height','160',
			'align','middle',
			'src','/assets/Picture/banner_bh-16613',
			'quality','high',
			'bgcolor','#4a9f0b',
			'allowscriptaccess','sameDomain',
			'pluginspage','http://www.macromedia.com/go/getflashplayer',
			'movie','/assets/Picture/banner_bh-16613'
			); //end AC code
	} else {  // flash is too old or we can't detect the plugin
		var alternateContent = '<img src="/assets/Picture/banner_noflash.jpg" width="595" height="160"/>';
		document.write(alternateContent);  // insert non-flash content
	}
}

}


function writeBlankBanner() {

document.write('<table width="595" height="160" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="#4a9f0b">&nbsp;</td></tr></table>');

}

















































































































































