
var selectedPage = -1;
var oldOpera = 0;
var issetFlash = 0;
var checkedForFlash = 0;
var MM_PluginVersion = 0;
var MM_contentVersion = 7; // minimal version required by our content
var flash7Installed = false;
var flash8Installed = false;

// todo: check user agent if: firefox, or if ie on win
// if yes, checkedForFlash should be 1, and proceed to code below
// if not, leave now
if (navigator.userAgent && ((navigator.userAgent.indexOf("Firefox") >=0 ) || 
	(navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.appVersion.indexOf("Win") >= 0)))) {
   	checkedForFlash = 1;
}

if (checkedForFlash) {
	var plugin = (navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i) {
	
			if (isNaN(parseInt(words[i])))
				continue;
			var MM_PluginVersion = words[i]; 
			
	    }
	    
		issetFlash = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.appVersion.indexOf("Win") >= 0)) {
	   	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');	
		document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');	
		document.write('</SCR' + 'IPT\> \n'); 
		
		for (var i = 8; i >= 7; i--) {	
			var value = eval("flash" + i + "Installed");
			if (value) {
				MM_PluginVersion = i;
				break;
			}
		}

		issetFlash = (MM_PluginVersion != 0);
	}
}

/**
 * looks for reference to the old session parameter 'u'
 * if found, replaces its value with the value of newSessionID
 * if not, append &u=<newSessionID> to the url and returns it
 */
function replaceSessionParameter(oldURL, newSessionID) {
	
	var newURL;
	
	var startOfOldUParam = oldURL.indexOf('&u=');
	if (startOfOldUParam == -1) {
		startOfOldUParam = oldURL.indexOf('?u=');
	}
	if (startOfOldUParam == -1) {
		// failed to find the u parameter

		var existanceOfParameters = oldURL.indexOf('?');
		if (existanceOfParameters != -1) {
			newURL = oldURL += '&u=' + newSessionID;
		}
		else {
			newURL = oldURL += '?u=' + newSessionID;
		}					
	}
	else {
		sessionStartsHere = startOfOldUParam + 3; // length of '&u=' or '?u='
		
		// look for the end of the session string value
		var endOfU = oldURL.indexOf('&', sessionStartsHere);
		if (endOfU == -1) {
			// The u parameter was the last parameter
			newURL = oldURL.substr(0, sessionStartsHere) + newSessionID;
		}
		else {
			newURL = oldURL.substr(0, sessionStartsHere) + newSessionID + oldURL.substr(endOfU, oldURL.length);
		}
	}
	
	return newURL;
}

/**
 * extracts the value of a URL parameter from a URL.
 * If the parameter is not found, null is returned 
 */
function extractParameterValueFromURL(url, parameterName) {
	
	var parameterValue = null;
	
	var startOfParam = url.indexOf('&' + parameterName + '=');
	if (startOfParam == -1) {
		startOfParam = url.indexOf('?' + parameterName + '=');
	}
	if (startOfParam != -1) {
		parameterStartsHere = startOfParam + 2 + parameterName.length; // 2 is for &/? and =
		
		// look for the end of the session string value
		var endOfParameter = url.indexOf('&', parameterStartsHere);
		if (endOfParameter == -1) {
			endOfParameter = url.length;
		}
			
		parameterValue = url.substring(parameterStartsHere, endOfParameter);		
	}
	
	return parameterValue;
}

/**
 * disables right click
 */
function disableRightClick() {
	if (event.button == 2) {	
  		return false;
  	}
}

/**
 * invokes a URL from a Flash component
 */
function invokeFlashURL(page, parameters) {
	if (parameters == '') {
		document.location.href = page;
		return;
	}
	
	var paramsArray = parameters.split(',');
	var URL = page;
	var separator = '?';
	for (i=0; i<paramsArray.length; i++) {
		URL += separator;
		URL += paramsArray[i];
		separator = '&';
	}
		
	document.location.href = URL;
}

/**
 * returns an array describing the position and dimensions of an element in the page.
 * The entries in the array are:
 * 'left': left coordinate in pixels
 * 'top': top coordinate in pixels
 * 'width': width of the element in pixels
 * 'height': height of the element in pixels
 *
 * @param element The element whose position and dimensions we want
 */
function getPositionAndDimension(element) {
	
	var left = element.offsetLeft;
	var top = element.offsetTop;
	var width = element.offsetWidth;
	var height = element.offsetHeight;
	
	while (element.offsetParent != null) {
  		elementParent = element.offsetParent;
  		left += elementParent.offsetLeft;
		top += elementParent.offsetTop;
  		element = elementParent;
 	}
	
	var results = new Array(4);
	results['left'] = left;
	results['top'] = top;
	results['width'] = width;
	results['height'] = height;
		
	return results;	
}

/**
 * displays an alert prompt with information about a JavaScript error. 
 */
function showErrorMsg(message, url, line) {

 	var fs = "";
 	if (showErrorMsg.caller) {
 		var content = showErrorMsg.caller.toString();
 		var startIndex = 8;
 		var endIndex = content.indexOf("(");
 		var funcName = content.substring(startIndex, endIndex);
   	fs = funcName;
 	}
 	 	
 	// clean url string 	
 	var startIndex = url.lastIndexOf("/") - 3;
 	var endIndex = url.lastIndexOf("?");
 	if (endIndex == -1) {
 		endIndex = url.length;
 	}
 	var file = url.substring(startIndex, endIndex); 
 	 	
 	var params = "error.php?file=" + file + "&func=" + fs + "&line=" + line + "&msg=" + message;	
 	window.open(params, '', '');

	return true;
}

//window.onerror = showErrorMsg;

function preloadImages() { //v3.0
	var d=document; 
	if (d.images) { 
		d.MM_p = new Array();
    	var i, j = d.MM_p.length, a = preloadImages.arguments;
    	for (i=0; i<a.length; i++)
    		if (a[i].indexOf("#") != 0) { 
    			d.MM_p[j] = new Image; 
    			d.MM_p[j++].src= a[i];
    		}
    }
}


function preloadIcons(imagesArray) {
	for (i=0; i<imagesArray.length; i++) {
		var image = new Image;
		image.src = imagesArray[i];
	}
}

 
/**
 * preloads all the images that are needed for the navigation mechanism
 */
function preLoadNavigationImages(theme) {
	
	var navigationButtonStr = "";

	navigationButtonStr += ' "' + theme + '/NavigationLine/Images/LTR/buttonBack.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonBackDisabled.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonNext.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonNextDisabled.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonBack.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonBackDisabled.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonNext.png" ';
	navigationButtonStr += ', "' + theme + '/NavigationLine/Images/LTR/buttonNextDisabled.png" ';
	
	if (navigationButtonStr){
		navigationButtonStr = 'preloadImages(' + navigationButtonStr + ')';
		eval(navigationButtonStr);
	}
}


function sidebarSuperSearchSubmission(event, form) {

	if (!event) {
		var event = window.event;  //for IE
	}
   
	var code;
	if (event.keyCode) {
		code = event.keyCode; //for IE
	}
	else if (event.which) {
		code = event.which;  //for other browsers
	}
	
	if (code != 13) {
		return true;
	}
	
	performSuperSearch(form);
	return false;
}

function performSuperSearch(form) {
	form.query.value = form.query.value.replace(/^\s*|\s*$/g,'');
	disableButton('SuperSearch');
	form.submit();
	return false;
}

function openCenteredPopup2(url, width, height, name, params, callback) {	
	
	// extract the scrolling parameter
	var scrolling = 'no';	// The default value
	
	var scrollIndex = params.indexOf('scroll');
	if (scrollIndex != -1) {
		var endIndex = params.indexOf(';', scrollIndex);
		if (endIndex == -1) {	// this may have been the last parameter
			scrolling = params.substring(scrollIndex + 7, params.length);	// 7 is the legnth of 'scroll:'
		}
		else {
			scrolling = params.substring(scrollIndex + 7, endIndex);	// 7 is the legnth of 'scroll:'
		}
				
		// all possible "positive" values
		if (scrolling == 'yes' || scrolling == '1' || scrolling == 'on') {
			scrolling = 'auto';
		}
	}
			
	internalDoNotCallThisPopup(url, width, height, scrolling, callback, false);
}


/**
 * checks if the day, month and year supplied constitutes a legal date
 *
 * @param dayValue The day (1-31)
 * @param monthValue The month (1-12)
 * @param yearValue The year
 *
 * @return true if the day, month and year supplied constitutes a legal date, false otherwise
 */
function isDateLegal(dayValue, monthValue, yearValue) {
	
	var day = parseInt(dayValue, 10);
	var day = parseInt(dayValue, 10);
	
	if (day > 30 && (monthValue == 4 || monthValue == 6 || monthValue == 9 || monthValue == 11)) {
		// these months cannot have more than 30 days
		return false;
	}

	if (monthValue == 2)	{			
		// this is February
		// This calculates the basic leap year no matter the format, i.e. 2000 or 00.
						
		var isLeapYear = (((yearValue % 4 == 0) && (yearValue % 100 != 0)) || (yearValue % 400 == 0)) ? true : false;		
		
		if (!isLeapYear && day > 28) {
			return false;
		}
		else if (isLeapYear && day > 29) {
			return false;
		}	
	}

	return true;
}


/**
 * returns a form element object by its name
 */
function getFormGroup(name) {
	return document.getElementsByName(name);
}
		

/**
 * returns the form element with the given name that is checked or null otherwise
 */
function getRadio(name) {
	var elements = getFormGroup(name);
	if (elements) {
		/* loop over all the radio buttons */
		for (i = 0; i < elements.length; i++) {
			if (elements[i].checked) {
				return elements[i];
			}
		}
	}
		/* either no group by that name was foundor none were selected */
	return null;
}

/**
 * returns the value of the checked radio button with the given name, or '' otherwise
 */
function getRadioValue(name) {
	var element = getRadio(name);
	if (element) {
		return element.value;
	}
		
	/* there must not have been a radio buttonselected */
	return '';
}


/**
 * returns a random string of a specific length
 * The string is composed of the letters A-Z
 */
function generateRandomString(length) {
	var randomValue = '';		 		
	for (var i=0; i<length; i++) {			
		var rndNum = Math.random();
		// rndNum from 0 - 1000
		rndNum = parseInt(rndNum * 1000); 
		
		// rndNum from 65 - 90 
		rndNum = (rndNum % 25) + 65;
		randomValue += String.fromCharCode(rndNum); 
	}
	
	return randomValue;
}


function setInnerText(objID, newText) {
	var obj = document.getElementById(objID);
	if (document.all) {
		// IE CODE
		obj.innerText = newText;
	} else {
		// MOZILLA & NETSCAPE CODE
		var nodes = obj.childNodes[0];
		nodes.nodeValue = newText;
	}
}

/**
 * prepares text for JavaScript
 */
function prepareTextForJavascript(stringValue) {
	
	if (typeof stringValue == 'string') {
		var output = "";	
		
		if (stringValue.length == 0) {
			return "!";
		}
		
		for (var i=0; i<stringValue.length; i++) {
			output += "!" + tohex(stringValue.charCodeAt(i)); 
		}
		return output;
	}
	else {
		return "!" + stringValue;
	}
}


/**
 * converts a decimal number to a hexadecimal
 */
function tohex(i) {
	var a2 = ''
	var ihex = hexQuot(i);
	var idiff = eval(i + '-(' + ihex + '*16)')
    a2 = itohex(idiff) + a2;
    while( ihex >= 16) {
    	var itmp = hexQuot(ihex);
         idiff = eval(ihex + '-(' + itmp + '*16)');
         a2 = itohex(idiff) + a2;
         ihex = itmp;
	} 
    var a1 = itohex(ihex);
    return a1 + a2 ;
}


function hexQuot(i) {
	return Math.floor(eval(i +'/16'));
}

function itohex(i) {
	if (i == 0) {
    	aa = '0';
	}
    else { 
    	if (i== 1) {
			aa = '1';
    	}
        else {
        	if (i== 2) {
				aa = '2';
        	}
            else {
            	if (i == 3) {
                	aa = '3';
            	}
               	else {
               		if (i== 4) {
                    	aa = '4';
               		}
                  	else {
                  		if (i == 5) {
                        	aa = '5'; 
                  		}
                     	else {
                     		if (i== 6) {
                            	aa = '6';
                     		}
                        	else {
                        		if (i == 7) {
                                	aa = '7'; 
                        		}
                           		else {
                           			if (i== 8) {
                                    	aa = '8';
                           			}
	                              	else {
	                              		if (i == 9) {
                                        	aa = '9';
	                              		}
	                                 	else {
	                                 		if (i==10) {
                                          		aa = 'A';
	                                 		}
                                    		else {
                                    			if (i==11) {
                                            		aa = 'B';
                                    			}
                                       			else {
                                       				if (i==12) {
                                                		aa = 'C';
                                       				}
                                          			else {
                                          				if (i==13) {
                                                   			aa = 'D';
                                          				}
                                             			else {
                                             				if (i==14) {
                                                      			aa = 'E';
                                             				}
                                                			else {
                                                				if (i==15) {
                                                         			aa = 'F';
                                                				}
                                                			}
                                             			}
                                          			}
                                       			}
                                    		}
                                 		}
                              		}
                           		}
                        	}
                     	}
                  	}
               	}
        	}
    	}
	}
	return aa
}

/**
 * defines the endWidth function for the String object
 */
String.prototype.endsWith = function(sEnd) {
	return (this.substr(this.length-sEnd.length)==sEnd);
}

/*
 * Replace a token in a string
 *  tokenToRemove  token to be found and removed
 *  tokenToAdd  token to be inserted
 *  returns new String
 */
function replace(string, tokenToRemove, tokenToAdd) {
	var index = string.indexOf(tokenToRemove);
  	var result = "";
  	var stringFound = (index != -1);
  	if (!stringFound) {    		 		
  		// special case. If the attempt was to replace a URL parameter
  		// try not just the '&' version but also the '?' version
  		// for example: &test= and ?test=
  		if (tokenToRemove.charAt(0) == '&' && tokenToAdd.indexOf(tokenToRemove) == 0) {
  			
  			tokenToRemove = '?' + tokenToRemove.substring(1);
  			tokenToAdd = '?' + tokenToAdd.substring(1);
  			index = string.indexOf(tokenToRemove);
  			stringFound = (index != -1);
  		}
  		
  		if (!stringFound) {
  			return string;
  		}
  	}
  	
  	result += string.substring(0, index) + tokenToAdd;
  	if (index + tokenToRemove.length < string.length) {
    	result += replace(string.substring(index + tokenToRemove.length, string.length), tokenToRemove, tokenToAdd);
  	}
  	return result;
}

/**
 * returns the extension of a file name
 */
function getExtension(fileName) {
		
	var dotIndex = 	fileName.lastIndexOf('.');
	if (dotIndex == -1) {
		// no dot was found
		return '';
	}
	
	if (dotIndex == (fileName.length - 1)) {
		return '';
	}
	return fileName.substring(dotIndex + 1, fileName.length);
}


function renderHorizontalMenu(browserName, currentPage, dir, pageURLs, pageTitles, currentCategory) {	
				
	selectedPage = currentCategory;
	
	if (currentPage == -1) {
		selectedPage = currentPage;
	}
		
	var path = "/FP";
	
	var h_menu = pageURLs;
	var h_menu_names = pageTitles;
	
	oldOpera = (browserName == 'OP');
	if (dir == 'RTL') {
		dirExtension = '_rtl';
	}
	else {
		dirExtension = '';
	}
	
	var hebrew = null;
			
	if (hebrew == null) hebrew = 0;
		
	if (issetFlash == 1 && oldOpera != 1 && dir != 'RTL') {
				
		var h_menu_flash = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="582" HEIGHT="38" hspace="0" vspace="0"><PARAM NAME=movie VALUE="' + path + '/Flash/h_menu.swf?lang='+hebrew+'&sel_btn='+ selectedPage;
		var pagesValuesFlash = '';
		for (i=0; i<=h_menu.length; i++) { 	
			// there is a bug in the flash which requires us to pass one extra parameter
			// this is why the condition is <= and not < as it should be			
			pagesValuesFlash += '&item'+i+'='+h_menu_names[i];
		}	
						
		for (i=0; i<=h_menu.length; i++) {
			// there is a bug in the flash which requires us to pass one extra parameter
			// this is why the condition is <= and not < as it should be	
			pagesValuesFlash += '&url' + i + '=' + h_menu[i];
		}
				
		h_menu_flash += pagesValuesFlash;		
		h_menu_flash += '"><PARAM NAME=wmode VALUE=opaque><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src="' + path + '/Flash/h_menu.swf?lang='+hebrew+'&sel_btn='+ selectedPage;
		h_menu_flash += pagesValuesFlash; 
		h_menu_flash += '" WIDTH="582" HEIGHT="38" wmode="opaque" hspace="0" vspace="0" quality=high bgcolor=#FFFFFF TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
			
		document.write(h_menu_flash);

		
	} else {
		var h_menu_html = '<table style="margin-top:2px;" width="578" height="34" border="0" cellpadding="0" cellspacing="0" background="' + path + '/Company/img' +dirExtension + '/h_menu/bg.png"><tr><td width="12" background="' + path + '/Company/img' +dirExtension + '/h_menu/left.png"></td>';
		for (i=0; i<h_menu.length; i++) {
			h_menu_html += '<td align="center" valign="top">';
			if (selectedPage == i) {
				h_menu_html += '<span class="h_menu" style="color:#71AD26"><b>'+h_menu_names[i]+'</b></span>';
			} else {
				h_menu_html += '<td align="center" valign="top"><a href="'+h_menu[i]+'" onContextMenu="return false" class="h_menu">'+h_menu_names[i]+'</a></td>';			
			}
									
			h_menu_html += '</td>';
			
			if (i != Number(h_menu.length)-1) {
				h_menu_html += '<td width="1" background="' + path + '/Company/img' +dirExtension + '/h_menu/sep.png"></td>';
			}
		}
		h_menu_html += '<td width="12" background="' + path + '/Company/img' +dirExtension + '/h_menu/right.png"></td></tr></table>';			
		document.write(h_menu_html);			
	}
}


function getRandomNumber(size) {

	var min_random = 0;
	var max_random = size;

	var now = new Date();
	var seed = now.getSeconds();
	var n = Math.floor(Math.random(seed)*max_random);
	return n;
}

function renderHeader(headerTx, headerSize, headerTop, textDirection, width) {
	
	if (textDirection == 'LTR') {			
		if (issetFlash == 1 && oldOpera != 1) {			
			var header = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + width + '" HEIGHT="30" id="text_b"><PARAM NAME=movie VALUE="/FP/Flash/text_b.swf?&tf_text='+headerTx+'&&lang=0&&tf_align=left&&tf_color=0x2C506A&&tf_size='+headerSize+'&&tf_bold=1&&tf_x=0&&tf_y='+headerTop+'&&tf_w=' + width + '&&tf_h=30&&tf_sc=0x000000&&tf_sa=0&&tf_so=0&"><PARAM NAME=quality VALUE=high><PARAM NAME="WMode" VALUE="Transparent"><PARAM NAME=scale VALUE=noscale><PARAM NAME=salign VALUE=LT> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="/FP/Flash/text_b.swf?&tf_text='+headerTx+'&&lang=0&&tf_align=left&&tf_color=0x2C506A&&tf_size='+headerSize+'&&tf_bold=1&&tf_x=0&&tf_y='+headerTop+'&&tf_w=' + width + '&&tf_h=30&&tf_sc=0x000000&&tf_sa=0&&tf_so=0&" quality=high scale=noscale salign=LT bgcolor=#FFFFFF  wmode="transparent" WIDTH="' + width + '" HEIGHT="30" NAME="text_b" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
		} else {
			var topStripCaptionContainer = document.getElementById('topStripCaptionContainer');
			topStripCaptionContainer.style.top = '14px';
			var header = '<span style="width:' + width + 'px; font-family:Arial;font-size:'+(headerSize-1)+'px;color:#2C506A;font-weight:bold;line-height:'+(headerSize-1)+'px;">'+headerTx+'</span>';
		}
	}
	else {
		/*if (issetFlash == 1 && oldOpera != 1) {
			header = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + width + '" HEIGHT="30" id="text_b"><PARAM NAME="salign" value="lt"><PARAM NAME="movie" VALUE="/FP/Flash/text_b.swf?&tf_text='+headerTx+'&&lang=0&&tf_align=right&&tf_color=0x2C506A&&tf_size='+headerSize+'&&tf_bold=1&&tf_x=0&&tf_y='+headerTop+'&&tf_w=' + width + '&&tf_h=30&&tf_sc=0x000000&&tf_sa=0&&tf_so=0&"><PARAM NAME="quality" VALUE="high"><PARAM NAME="WMode" VALUE="Transparent"><PARAM NAME="scale" VALUE="noscale"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><EMBED src="/FP/Flash/text_b.swf?&tf_text='+headerTx+'&&lang=0&&tf_align=right&&tf_color=0x2C506A&&tf_size='+headerSize+'&&tf_bold=1&&tf_x=0&&tf_y='+headerTop+'&&tf_w=' + width + '&&tf_h=30&&tf_sc=0x000000&&tf_sa=0&&tf_so=0&" quality="high" scale="noscale" salign="lt" bgcolor="#FFFFFF" wmode="transparent" WIDTH="' + width + '" HEIGHT="30" NAME="text_b" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
		} else {*/
			var header = '<span style="font-family:Arial;font-size:'+(headerSize-1)+'px;color:#2C506A;font-weight:bold;line-height:'+(headerSize-1)+'px;">'+headerTx+'</span>';
		//}
	}
	
	document.write(header);
}

function renderLMenu(Lmenu, Lsubmenu, LsubmenuUrl, textDirection) {

	if (textDirection == 'LTR') {	
		var imagePath = 'img';
		var flowDirection = 'left';
		var oppositeFlowDirection = 'right';
	}
	else {
		var imagePath = 'img_rtl';
		var flowDirection = 'right';
		var oppositeFlowDirection = 'left';
	}
	
	var newMenu = '';

	for (i=0; i<Lmenu.length; i++) {
		// The major entries in the menu
		
		newMenu += '<table width="174" border="0" cellspacing="0" cellpadding="0" style="display:none;border-top:1px solid #F0F1EE; border-bottom:1px solid #F0F1EE;" id="mh'+i+'_norm"><tr><td height="20" align="' + flowDirection + '" valign="middle" background="/FP/Company/' + imagePath + '/left_menu/line_bg.png" style="background-position:' + flowDirection + ';background-repeat:repeat-y;padding-' + flowDirection + ':14px;"><span class="leftMenuTitle">'+Lmenu[i]+'</span></td></tr></table>';

		// The very top caption above the entries (has green background)
		newMenu += '<table width="174" border="0" cellspacing="0" cellpadding="0" id="mh'+i+'_act" style="display:none;"><tr><td width="11" height="20" align="center" valign="middle" bgcolor="#7DAB40"><img src="/FP/Company/' + imagePath + '/left_menu/wh_arrow.gif" width="9" height="7" hspace="1" style="margin-top:1px;"></td><td background="/FP/Company/' + imagePath + '/left_menu/green_grad.png" bgcolor="#7DAB40" style="background-position:' + oppositeFlowDirection + ';background-repeat:no-repeat;"><span style="font-size:14px;color:#FFFFFF;margin-' + flowDirection + ':3px;"><b>'+Lmenu[i]+'</b></span></td></tr><tr><td height="1" colspan="2" bgcolor="#FFFFFF"><img width="1" height="1"></td></tr></table>';

		newMenu += '<table width="174" border="0" cellspacing="0" cellpadding="0" id="mh'+i+'_menu" style="display:none;">';
		
		for (n=0; n<Lsubmenu[i].length; n++) {
						
		//if (i != 0 || selectedPage != 4 || n != 1 || LMsubactive == 1) {


				if (n!=0) {
					newMenu += '<tr><td colspan="2"><img src="/FP/Company/' + imagePath + '/left_menu/line_sep.png" width="174" height="1"></td></tr>';
				}

				if (LMactive == i && LMsubactive == n) {
					// line behind the currently selected entry
					attributes1 = ' align="' + oppositeFlowDirection + '" valign="middle" style="border-' + flowDirection + ':1px solid #C3CDE1;';
				} else {
					// line behind the currently NON-selected entry
					attributes1 = ' background="/FP/Company/' + imagePath + '/left_menu/line_bg.png" style="border-' + flowDirection + ':1px solid #B2C0DA;';
				}

				if (n==0 && i==LMactive) {
					// top horizontal lines below the top caption (has green background)
					attributes1 += 'border-top:1px solid #CACBC6;"';
					attributes2 = ' style="border-top:1px solid #CACBC6;"';
				} else {
					attributes1 += '"';
					attributes2 = '';
				}

			// the arrow to the left of the selected entry
			newMenu += '<tr><td width="30" height="20"'+attributes1+'>';
			
			
			if (LMactive == i && LMsubactive == n) {
				newMenu += '<img src="/FP/Company/' + imagePath + '/left_menu/green_arrow.gif" width="9" height="7" hspace="1">';
			} else {
				newMenu += '&nbsp;';
			}
			
			// The text in the actual entry (both selected and NON-selcted)
			newMenu += '</td><td'+attributes2+' width="144">';
			
			if (LMactive == i && LMsubactive == n) {
				newMenu += '<span class="leftMenuActive">';
			} else {
				newMenu += '<a href="'+LsubmenuUrl[i][n]+'" onMouseOver="window.status=\''+ replace(Lsubmenu[i][n], "'", "\\'")+'\'; return true" onMouseOut="window.status=\'\'; return true" class="leftMenu">';
			}
				
			newMenu += Lsubmenu[i][n];

			if (LMactive == i && LMsubactive == n) {
				newMenu += '</span>';
			} else {
				newMenu += '</a>';
			}
				
			newMenu += '</td></tr>';

		//}
		}
		newMenu += '</table>';

	}
	
	document.write(newMenu);
	
	leftMenu(LMactive);

}


function leftMenu(id)  {
		
	for (i=0; i<Lmenu.length; i++) {
		if (i != id) {
		document.getElementById('mh'+i+'_norm').style.display = '';
		document.getElementById('mh'+i+'_act').style.display = 'none';
		document.getElementById('mh'+i+'_menu').style.display = '';
		}
	}		
	document.getElementById('mh'+id+'_norm').style.display = 'none';
	document.getElementById('mh'+id+'_act').style.display = '';
	document.getElementById('mh'+id+'_menu').style.display = '';

	LMactive = id;	
}

function closePopup() {
	parent.hidePopWin(true); 
}

function getPopupParent() {
	return parent.doNotCallThisFunctionGetPopupParent();
}

function convertArrayToParameterList(parameterArray) {
	var list = "";
	for (i=0; i<parameterArray.length; i++) {		
		list += "'" + replace("" + parameterArray[i], "'", "\\'") + "'";
		if (i < (parameterArray.length - 1)) {
			list += ", ";
		}
	}
	
	return list;
}

// function to search a string in an array
function in_array(searchString, sourceArray) {
	var i, searchString, returnValue;
	returnValue = false;

	for(i=0; i<(sourceArray.length); i++) {
		if(searchString == sourceArray[i]) {
			return true;
		}
	} 
	return returnValue;
}

function isNaturalNumber(sText) {
	var validChars = "0123456789";
   	var ch;

   	for (i = 0; i < sText.length; i++)  { 
    	ch = sText.charAt(i); 
      	if (validChars.indexOf(ch) == -1) {
         	return false;
		}
	}
   
	return true;  
}

function isDigit(chr) {
	var validChars = "0123456789";
	if (validChars.indexOf(chr) == -1) {
         return false;
	}
	else {
		return true;
	}
}

var profanities = ['fuck','shit','cunt'];

function includeProfanity(stringToTest) {

	for (var i=0; i<profanities.length; i++) {
		if (stringToTest.indexOf(profanities[i]) != -1) {
			return true;
		}
	}
	
	return false;
}

function doesStartWithForbiddenCharacter(string) {
	// make sure the nickname doesn't start with one of the forbidden characters
	var forbiddenStartCharacters = ["!", "'", ",", "."];
	var firstLetter = string.charAt(0);
	for (var i=0; i<forbiddenStartCharacters.length; i++) {
		if (firstLetter == forbiddenStartCharacters[i]) {
			return true;
		}
	}
	
	return false;
}

function trim(string) {
	return string.replace(/^\s*|\s*$/g,'');
}

// this function gets the cookie, if it exists
function getCookie(NameOfCookie) {
	
	var start = document.cookie.indexOf(NameOfCookie + "=");
	var len = start + NameOfCookie.length + 1;
	if ((!start) && (NameOfCookie != document.cookie.substring(0 ,NameOfCookie.length))) {
		// failed to find the cookie
		return null;
	}
	if (start == -1) {
		return null;
	}
	var end = document.cookie.indexOf(";", len);
	if (end == -1) {
		end = document.cookie.length;
	}
	return unescape(document.cookie.substring(len, end));
}

// sets the value of a cookie
function setCookie(NameOfCookie, value, expirationInMillis) {
	
	var ExpireDate = new Date();
	if (expirationInMillis) {
		ExpireDate.setTime(expirationInMillis);
	}
	else {
		// one year from now
		ExpireDate.setTime(ExpireDate.getTime() + (365 * 24 * 3600 * 1000));	
	}
	var expires_date = ExpireDate.toGMTString();
	
	var cookieDomain = getCookieDomain();

	var cookieValue = NameOfCookie + "=" + escape( value ) +
		";expires=" + expires_date +
		";path=/" + 
		( ( cookieDomain != '' ) ? ";domain=" + cookieDomain : "" );
	
	document.cookie = cookieValue;
}

function deleteCookie(NameOfCookie) {
	if (getCookie(NameOfCookie)) {
		
		var cookieDomain = getCookieDomain();
		
		document.cookie = NameOfCookie + "=" + 
		";path=/" + 
		"; expires=Thu, 01-Jan-70 00:00:01 GMT" + 
		( ( cookieDomain != '' ) ? ";domain=" + cookieDomain : "" );	
	}
}

// returns the domain that will be used in managing the cookies
// it is safer to set the domain explicitly as we know what value is used
// and we leave nothing for the browser
function getCookieDomain() {
		
	var host = document.location.host.toLowerCase();
		
	var hostLength = host.length;
	var extensionIndex = host.lastIndexOf('.com');
		
	var cookieDomain = "";
	
	// 4 is the length of the '.com' string
	if (extensionIndex == -1 || (extensionIndex != (hostLength - 4))) {
		
		// did not find .com or the host didn't end with .com
		
		// could be localhost or an IP address
		if (host != 'localhost') {
			// IP address
			cookieDomain = host;
		}
	}
	else {
		// host ends with .com
		
		// skip any subdomain and start with the first .
		// For example, if the host was www.myheritage.com
		// we use the domain myheritage.com
		// this makes the cookie available on all subdomains of myheritage.com 
		var firstPeriod = host.indexOf(".");
		cookieDomain = host.substr(firstPeriod + 1);
	}
		
	return cookieDomain;
}