
function HiLiteMenu(menu_keyword) {
	// commented out because this was creating problems for the browsers "back" functionality
	//window.top.frm_top_menu.location.href='../top_nav.asp?m='+menu_keyword;
	return;
}

function fullstory(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=yes,width=550,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

// retrieves a definition for the passed skillname using WHATIS.COM
function skillspopup(SkillName) {

	//var theURL = "http://www.whatis.com/api-shl/findterm.cfm?search=YES&thisterm=" + SkillName;
	//var theURL = "http://www.whatis.com/WhatIs_Search_Results_Exact/?query=" + SkillName;
	//var theURL = "http://whatis.techtarget.com/wsearchResults/1,290214,sid9,00.html?query=" + SkillName;
	var theURL = "http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?action=Search&query=" + SkillName;
	//http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=visual%20basic&action=Search
	//msgWindow=window.open(theURL,'_blank','toolbar=no,width=500,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes');
	display_pop_window('IE',theURL,"SkillInfo",1,1,500,400);
}

function loginhistorypopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=350,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function popup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=500,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function mediumpopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=350,height=250,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function addreminderpopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=500,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function smallpopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=300,height=200,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function wizardpopup(theURL) {
	WizardWindow=window.open(theURL,'_blank','toolbar=no,width=680,height=400,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function chatpopup(theURL) {
	WizardWindow=window.open(theURL,'_blank','toolbar=no,width=680,height=450,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function imessagepopup(theURL) {
	msgWindow=window.open(theURL,'_blank','left=320,top=200,toolbar=no,width=340,height=200,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,alwaysRaised=yes')
}

function addnotepopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=350,height=300,directories=no,status=no,scrollbars=no,resizable=yes,menubar=yes,alwaysRaised=yes')
}

function grouppopup(theURL) {
	msgWindow=window.open(theURL,'_blank','toolbar=no,width=350,height=300,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,alwaysRaised=yes')
}

function changebackground(src,color) { 
	src.style.background = color;
	return;
} 


function mOvr(src,clrOver) { 
	if (!src.contains(event.fromElement)) { 
		src.style.cursor = 'hand'; 
		src.style.color = clrOver; 
		status = src.title;
	}
}

function mOut(src,clrIn) { 
	if (!src.contains(event.toElement)) { 
		src.style.cursor = 'default'; 
		src.style.color = clrIn; 
		status = "";
	}
} 


function mOvrCell(src,clrOver) { 
	if (!src.contains(event.fromElement)) { 
		src.style.cursor = 'hand'; 
		src.style.background = clrOver; 
	}
}

function mOutCell(src,clrIn) { 
	if (!src.contains(event.toElement)) { 
		src.style.cursor = 'default'; 
		src.style.background = clrIn; 
	}
} 

// sets checkbox checked state to the passed state
function setchecked(src,state) { 
	if (!src.contains(event.toElement)) { 
		if (state == "true") {
			src.checked = true;
		} else {
			src.checked = false;
		}
	}
} 

function setOptionChecked(items, itemValue) {
    if (!items || !items.length) { return; }
    for (var i = 0; i < items.length; ++i) {
        if (items[i].value == itemValue) {
            items[i].checked = true;
        }
    }
}

function isAnyOptionChecked(items) {
    if (!items || !items.length) { return false; }
    var result = false;
    for (var i = 0; i < items.length; ++i) {
        if (items[i].checked) {
            return true;
        }
    }
    return result;
}

function wizardcancel() {
	if (confirm('Are you sure you want to close? The data in this window will be lost.')) {
		self.close();
	}
}

function wizardgoback() {
	if (confirm('Going back will lose changes made in the current page.')) {
		window.history.go(-1);
	}
}


function goback() {
		window.history.go(-1);
}

function completeword(el) {
	var endchar = ".."
	var keyword = el.value;
	if (keyword == "to" + endchar) {
		el.value = "Toronto";
		return;
	}

	if (keyword == "dt" + endchar) {
		el.value = "Downtown Toronto";
		return;
	}

	if (keyword == "miss" + endchar) {
		el.value = "Mississauga";
		return;
	}

	if (keyword == "ny" + endchar) {
		el.value = "New York";
		return;
	}

return;
}


function IsNumeric(checkString,AllowSpecialChars)
{
    newString = "";
	if(checkString==null) return false
    if(checkString.length==0) return false;
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);

		//special chars are comas and dots
		if ((AllowSpecialChars) && (AllowSpecialChars.toUpperCase() == "YES")) {
			if (ch >= "0" && ch <= "9" || ch == "." || ch == ",") {
			    newString += ch;
			}
		} else { // no special characters
			if (ch >= "0" && ch <= "9") {
			    newString += ch;
			}
		}
    }

    if (checkString != newString) {
		return false;
    } else {
	    return true
    }
}


function Flip_Color(x_obj,x_action){
	switch(x_action){
	case "onfocus":
		x_obj.style.backgroundColor="white";
		break;
	case "onblur":
		x_obj.style.backgroundColor="white";
		break;
	}
}

function display_pop_window(BrowserType,url_to_display,window_name,ScrollB,MenuB,h_size,v_size){
	// BrowserType => NN or IE
	var window_options = "";
	var new_window;	
	var new_window_top = 0;
	var new_window_left = 0;
	new_window_top = (screen.availHeight - v_size) / 2;
	new_window_left = (screen.availWidth - h_size) / 2; 
	window_options = "toolbar=0,status=0,menubar=" + MenuB + ",scrollbars=" + ScrollB + ",resizable=1,width=" + h_size + ",height=" + v_size + ",";
	if(BrowserType=="NN"){
		window_options = window_options + "screenY=" + new_window_top + ",screenX=" + new_window_left ;
	}
	else{
		window_options = window_options + "top=" + new_window_top + ", left=" + new_window_left ;
	}
	new_window=window.open(url_to_display,window_name,window_options);
}

function openEmployeeDetails(theID) {
	display_pop_window('IE','../directory/employeedet.asp?id='+theID,'UserDetails',0,0,250,150);
	//msgWindow=window.open('../directory/employeedet.asp?id='+theID,'_blank','toolbar=no, menu=no,width=450,height=360,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,alwaysRaised=yes')
}

function GetUserDetails(URLtoPopup){
	display_pop_window('IE',URLtoPopup,'UserDetails',0,0,250,150);
}

function Trim_String(x_str){
	if((x_str!=null) && (x_str.length>0)) {
		var rgxLeadTrailSpaces = new RegExp("^\x20{1,}|\x20{1,}$","gi");
		x_str = x_str.replace(rgxLeadTrailSpaces,"");
		// --- remove CR and LF id present at the last character ---
		if ((x_str.charCodeAt(x_str.length-1) == 10) || (x_str.charCodeAt(x_str.length-1) == 13)){
			x_str = x_str.substring(0, x_str.length - 2);
		}
		if ((x_str.charCodeAt(x_str.length-1) == 10) || (x_str.charCodeAt(x_str.length-1) == 13)){
			x_str = x_str.substring(0, x_str.length - 2);
		}
	}
	return x_str;
}

function isEmail(string)
{
	var new_string = "";
	// --- Trim the email on left and right.
	string = Trim_String(string);
	// if there were any white space then the email must be wrong
	new_string = string.replace(/ /g,""); // removes all white space
	if (new_string != string) { 
		return false;
	}
	
	// if there are no @s then the email is wrong
	new_string = string.replace(/@/g,""); // removes all @s
	if (new_string == string) { 
		return false;
	}
	
	// if there are no "."s then the email is wrong
	new_string = string.replace(/\./g,""); // removes all .s (dots)
	if (new_string == string) { 
		return false;
	}

	return true;
}

    function isSet(value) {
        return ((value !== undefined) && (value !== null));
    }

    function isEmpty(value) {
        return (!isSet(value) || (value == ""));
    }

    function trimValue(value) {
        if (!isSet(value)) {
            return "";
        }
        var re=/^\s*|\s*$/ig;
        return value.replace(re, "");
    }

    function isEmailValid(value) {
        value = trimValue(value);
        if (isEmpty(value)) {
            return false;
        }
        var re=/^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.(\d{1,3}|[A-Za-z]{2,3}|(arpa|aero|name|coop|info|museum))$/ig;
        return isSet(value.match(re));
    }

//returns part of the 'str' string with 'n' number of characters from the character number 'start' 
function mid(str,start,len){
	strlen=str.length
	var s=str.substring(start-1,strlen)
	s=s.substring(0,len)
	return s
}

function IsDateValidated(strDate){
	var strMessage;
	//var strDate = document.forms[0].interview_date.value;
	//var strDate = DateTextBox.value;
	var day=mid(strDate,1,2);
	var month=mid(strDate,4,2);
	var year=mid(strDate,7,4);

	if (strDate.length < 10){
		alert("Please enter date in the following format: dd/mm/yyyy");
		return false;
		}
	
	if ((isNaN(day)) || (isNaN(month)) || (isNaN(year))){ 
		alert("Please enter numbers for day, month and year (dd/mm/yyyy).");
		return false;
		}
	if ((month > 12) || (month < 0)) {
		alert ("Please enter valid month number (dd/mm/yyyy).");
		return false;
		}
	if ( year< 1000)  {
		alert ("Please enter 4-digits number for the year (dd/mm/yyyy).");
		return false;
		}
	if ((mid(strDate,3,1)!= '/') || (mid(strDate,6,1)!='/')){
		alert ("Please enter '/' delimiters between day, month and year (dd/mm/yyyy).");
		return false;
		}

	var today=new Date();
	
	year=((!year)? today.getYear() + 1900:year);
	month=((!month) ? today.getMonth():month-1);
	
	if (!day) { 
		alert ("Please enter a valid day number for the date being entered (dd/mm/yyyy).");  
		return false;
		}

	var test=new Date(year,month,day);

	if ((parseInt(year) > 1899) && (parseInt(year) < 2000)){
		year = mid(year,3,2)
	}

	if  ((test.getYear()==year) && (month==test.getMonth()) && (day==test.getDate()) ) 
		return true;
		
	else {
		alert("Please enter a valid date (dd/mm/yyyy).");
		return false;
		}
}

// function isEmpty(string)
// This functions returns True if the passed string is empty or
// contains only blank spaces. Otherwise it returns False.
function isEmpty(string)
{
	var new_string = "";
	new_string = string.replace(/ /g,""); // removes all white space
	if (new_string == "") { 
		return true;
	} else {
		return false;
	}
}

function SetFocusTo(objForm,strElementName){
	var x = 0;
	for (x=0;x<objForm.elements.length;x++){
		if (objForm.elements[x].name==strElementName){
			objForm.elements[x].focus();
			return;
		}
	}
}	

function TrimAllTextFields(form){
	var reLeadTrailSpaces = new RegExp("^\x20{1,}|\x20{1,}$","gi");
	for(var x=0;x<form.elements.length;x++){
		if ( (form.elements[x].type=="textarea") || (form.elements[x].type=="text") ){
			form.elements[x].value = form.elements[x].value.replace(reLeadTrailSpaces,"");  
			//form.elements[x].value = Trim_String(form.elements[x].value);
		}
	}
}

function IsJobOrderNumber(sJob){
	sJob = Trim_String(sJob);
	var p1 = new RegExp("[J,j]\[0-9]\[0-9]\[0-9]\[0-9]\[-]\[0-9]\[0-9]\[0-9]\[0-9]","i");
	if (p1.test(sJob)) return true;
	return false;
}

function ValidateNumericParameter(){
	if(((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode!=46)) event.returnValue = false;
}

function FormatCurrency(sNumber){
	if(sNumber.indexOf(".",0)==-1) return sNumber + ".00";
	else{
		var sLeft = sNumber.substring(0,sNumber.indexOf("."));
		var sRight = sNumber.substr(sNumber.indexOf(".")+1,2);
		if(sRight.length==1) sRight = sRight + "0";
		if(sRight.length==0) sRight = sRight + "00";
		return sLeft + "." + sRight;
	}
}


function PopupNjoynCalendar(sDialogURL, sPresetDate){
	var PopupX = 0;
	var PopupY = 0;
	var CalendarWidth = 290;
	var CalendarHeight = 270;
	if((screen.height!=480) && (screen.height!=600) && (screen.height!=768) && (screen.height!=1024) && (screen.height!=1200))
	CalendarHeight = CalendarHeight + 50;
	var ScreenMaxX = screen.availWidth - 1;
	var ScreenMaxY = screen.availHeight - 1;
	if( (ScreenMaxX - window.event.screenX)>=CalendarWidth ) PopupX = window.event.screenX;
	else PopupX = ScreenMaxX - CalendarWidth;
	if( (ScreenMaxY - window.event.screenY)>=CalendarHeight ) PopupY = window.event.screenY;
	else PopupY = ScreenMaxY - CalendarHeight;
	return window.showModalDialog(sDialogURL, sPresetDate, "status:0;help:0;scroll:0;center:0;dialogHeight:" + CalendarHeight + "px;dialogWidth=" + CalendarWidth + "px;dialogLeft:" + PopupX + "px;dialogTop=" + PopupY + "px;");
}


// --- Display general purpose Njoyn data picker ...
function PopupNjoynDataPicker(sDialogURL,sDialogData,nDialogWidth,nDialogHeight){
	var PopupX = 0;
	var PopupY = 0;
	var CalendarWidth = nDialogWidth + (navigator.appVersion.indexOf("MSIE 4.")>-1 ? 30 : 0); 	// 290px
	var CalendarHeight = nDialogHeight + (navigator.appVersion.indexOf("MSIE 4.")>-1 ? 30 : 0); // 245px
	if((screen.height!=480) && (screen.height!=600) && (screen.height!=768) && (screen.height!=1024) && (screen.height!=1200))
	CalendarHeight = CalendarHeight + 50;
	var ScreenMaxX = screen.availWidth - 1;
	var ScreenMaxY = screen.availHeight - 1;
	if( (ScreenMaxX - window.event.screenX)>=CalendarWidth ) PopupX = window.event.screenX;
	else PopupX = ScreenMaxX - CalendarWidth;
	if( (ScreenMaxY - window.event.screenY)>=CalendarHeight ) PopupY = window.event.screenY;
	else PopupY = ScreenMaxY - CalendarHeight;
	return window.showModalDialog(sDialogURL, sDialogData, "status:0;help:0;scroll:0;center:0;dialogHeight:" + CalendarHeight + "px;dialogWidth=" + CalendarWidth + "px;dialogLeft:" + PopupX + "px;dialogTop=" + PopupY + "px;");
}

// --- General purpose routine to capture user's selection within Njoyn ...
function PickNjoynDataParameter(sDataTextTarget, sDataValueTarget, f, sClearActionText, sClearActionValue, xDialogWidth, xDialogHeight){
	var NextItemValue = ""; var NextItemText = ""; var CurrentParameterValue = ""; var NewParameterValue = "";
	if ((f.elements(sDataTextTarget)==null) || (f.elements(sDataValueTarget)==null)) return;
	if (f.elements(sDataValueTarget).DataSourceURL=="undefined") return;

	// --- determine type of control to receive parameter selection ...
	switch (f.elements(sDataTextTarget).type){
	case "text":
	case "textarea":
		CurrentParameterValue = f.elements(sDataValueTarget).value + "~" + f.elements(sDataTextTarget).value;
		NewParameterValue = PopupNjoynDataPicker(f.elements(sDataValueTarget).DataSourceURL,CurrentParameterValue,xDialogWidth,xDialogHeight);
		if(NewParameterValue=="CLEAR"){
			f.elements(sDataTextTarget).value = sClearActionText; //All
			f.elements(sDataValueTarget).value = sClearActionValue;
			return;
		}
		if(NewParameterValue=="CANCEL") return;
		if(NewParameterValue.length>0){
			if(NewParameterValue.indexOf("^")==-1) NextItemValue = NewParameterValue;
			NextItemValue = NewParameterValue.slice(0, NewParameterValue.indexOf("~"));
			NextItemText = NewParameterValue.slice(NewParameterValue.indexOf("~")+1, NewParameterValue.length);
			f.elements(sDataTextTarget).value = NextItemText;
			f.elements(sDataValueTarget).value = NextItemValue;
		}
		else{
			f.elements(sDataTextTarget).value = sClearActionText; //All
			f.elements(sDataValueTarget).value = sClearActionValue;
		}
		break;
	case "select-multiple":
	case "select-one":
		for(var x=0;x<f.elements(sDataTextTarget).length;x++) 
		CurrentParameterValue = CurrentParameterValue + f.elements(sDataTextTarget).options[x].value + "^";
		CurrentParameterValue = CurrentParameterValue.substr(0, CurrentParameterValue.length - 1);
		NewParameterValue = PopupNjoynDataPicker(f.elements(sDataValueTarget).DataSourceURL,CurrentParameterValue,xDialogWidth,xDialogHeight);
		if(NewParameterValue=="CLEAR"){f.elements(sDataTextTarget).length=0;return;}
		if(NewParameterValue=="CANCEL") return;
		while(NewParameterValue.length>0){
			if(NewParameterValue.indexOf("^")==-1) NextItemValue = NewParameterValue;
			else NextItemValue = NewParameterValue.slice(0, NewParameterValue.indexOf("^"));
			NextItemText = NextItemValue.slice(NextItemValue.indexOf("~")+1, NextItemValue.length);
			if(NewParameterValue.indexOf("^")==-1) NewParameterValue="";
			else NewParameterValue = NewParameterValue.slice(NewParameterValue.indexOf("^")+1);
			if((NextItemValue.length>0) && (NextItemText.length>0)){
				var el = new Option;
				el.text = NextItemText;
				el.value = NextItemValue;
				f.elements(sDataTextTarget)[f.elements(sDataTextTarget).length] = el;
			}
		}
		break;		
	default:
		break;
	}
}

// --- Reset search parameter to value specified ...
function ResetParameter(sTargetFiledValue, sValueData, sTargetFiledText, sTextData){
	var f = document.forms[0];
	if (f.elements(sTargetFiledText)==null) return;
	switch (f.elements(sTargetFiledText).type){
		case "text":
		case "textarea":
			if(f.elements(sTargetFiledValue)!=null) f.elements(sTargetFiledValue).value = sValueData;
			if(f.elements(sTargetFiledText)!=null) f.elements(sTargetFiledText).value = sTextData;
			return;
		case "select-multiple":
		case "select-one":
			for(var x=0;x<f.elements(sTargetFiledText).length;x++){
				if(f.elements(sTargetFiledText).options[x].value == sValueData){
					f.elements(sTargetFiledText).selectedIndex=x;
					return;
				}
			}
			return;
		default:
			return;
	}
}


// --- Determine IE version. For IE 4.x need to manually hide SELECT lists. Just hiding divs doesn't work ...
function isBrowserSupported() {
  //Njoyn supports IE 5.0 and greater
  //Njoyn supports Netscape 4.7x and greater
  return isIEBrowser(5) || isNSBrowser(4.7);
}

// Check if the browser is Microsoft Internet Explorer compatible
function isIEBrowser(nBuild) {
  // if parameter was not passed, use default value
  if (isNaN(nBuild)){
   nBuild = parseFloat("5.0");       //Njoyn supports IE 5.0 and greater
  }
  var BrowserOK = false;
  var VersionOK = false;
  var iVersion = parseFloat(navigator.appVersion);
  var sBrowserName = (navigator.appName);
  var isBrowser = (sBrowserName == "Microsoft Internet Explorer");
  var IEmajor = '';

  if (isBrowser) {
  // IE Returns 4, even if it's 5. Gets the real version from the headers.
  
    if (navigator.appVersion.indexOf("MSIE") != -1) {
      IEmajorStart = navigator.appVersion.indexOf("MSIE") + 4;
      IEmajorEnd = (IEmajorStart + 5);
      theMajor = navigator.appVersion.substring(IEmajorStart, IEmajorEnd);
      (iVersion = theMajor); 
    }
    if (isNaN(iVersion)) {
      (iVersion = (iVersion.substring(0, (iVersion.length - 1))));
    }
  }

  if (isBrowser && (iVersion >= nBuild)) {
   BrowserOK = true;
   VersionOK = true;
  }
  return BrowserOK && VersionOK;
}

// Check if the browser is Netscape compatible
function isNSBrowser(nBuild) {
  // if parameter was not passed, use default value
  if (isNaN(nBuild)){
   nBuild = parseFloat("4.7");       //Njoyn supports Netscape 4.7x and greater
  }
 
  var BrowserOK = false;
  var VersionOK = false;
  var iVersion = parseFloat(navigator.appVersion);
  var sBrowserName = (navigator.appName);
  var isBrowser = (sBrowserName == "Netscape");

  //document.write('iVersion: ' + iVersion + '<br>');
  //document.write('isBrowser: ' + isBrowser + '<br>');

  if (isBrowser && (iVersion >= nBuild)) {
   BrowserOK = true;
   VersionOK = true;
  }

  return BrowserOK && VersionOK;
}

/**
 * Creates and inserts option item into SELECT HTML object.
 * selObj         - SELECT HTML object to insert a new item.
 * optionValue    - Text for value of a new item.
 * optionText     - Text for item description.
 * index          - Number that represents index where a new item
 *               should be placed.
 * resetSelection - True if selection should be reset (the first
 *               item in tyhe list should be selected), otherwise
 *               selected item is not changed.
 */
function insertOptionInToSelect(selObj, optionValue, optionText, index, resetSelection) {
    var selectedIndex = -1;
    if (!resetSelection) {
        var selectedAttributes = selObj.options[selObj.selectedIndex].attributes;
        for (var i = 0; i < selectedAttributes.length; ++i) {
            if (selectedAttributes[i].nodeName.toLowerCase() == "selected") {
                selectedIndex = selObj.selectedIndex;
                break;
            }
        }
        if ((selectedIndex < 0) && document.all) {
            selectedIndex = selObj.selectedIndex;
        }
    }
	selObj.options.add(new Option(optionText, optionValue), index);
	selObj.selectedIndex = selectedIndex + 1;
}

