 <!--  Copyright (c) 2002-2008 Northstar Technologies, Inc. All rights reserved.   -->
<!--  This material is the confidential property of Northstar Technologies, Inc.  -->
<!--  or its subsidiaries or licensors and may be used, reproduced, stored        -->
<!--  or transmitted only in accordance with a valid Northstar license or         -->
<!--  sublicense agreement.                                                       -->



//check/uncheck all checkboxes
//when boolean is true, all checkboxes are checked.
//when boolean is false, all checkboxes are unchecked.
function toggleCheckBox(field, boolean) {
	if (boolean == true) {
		checkAll(field);
	}
	else { //if (boolean == false) 
		uncheckAll(field);
	}
}

function checkAll(field) {
	if (field == null) {
		return;
	}
	if (field[0]) { //if the checkbox is an array. a single checkbox is not an array
		for (i = 0; i < field.length; i++)
			field[i].checked = true ;
	}
	else {
		field.checked = true;
	}
}

function uncheckAll(field) {
	if (field == null) {
		return;
	}
	if (field[0]) { //if the checkbox is an array. a single checkbox is not an array
		for (i = 0; i < field.length; i++)
			field[i].checked = false ;
	}
	else {
		field.checked = false;
	}
}


//format a price
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if(buttonGroup == null) return retArr;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

//hammad: getUnselectedCheckBox
function getUnselectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are NOT selected (their position numbers). if ALL boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (!buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (!buttonGroup.checked) { // if the one check box is NOT checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getUnselectedCheckbox" function


function getUnselectedCheckboxValue(buttonGroup) {
   // return an array of values not selected in the check box group. if all boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var unselectedItems = getUnselectedCheckbox(buttonGroup);
   if (unselectedItems.length != 0) { // if there was something unselected
      retArr.length = unselectedItems.length;
      for (var i=0; i<unselectedItems.length; i++) {
         if (buttonGroup[unselectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[unselectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's unselected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getUnselectedCheckBoxValue" function


//get the selected index in a given selectBox
function getSelectedIndices (select) {
 var r = new Array();
 for (var i = 0; i < select.options.length; i++)
   if (select.options[i].selected)
     r[r.length] = i;
 return r;
}


//get the selected text
function getSelectedTexts (select) {
 var r = new Array();
 for (var i = 0; i < select.options.length; i++)
   if (select.options[i].selected)
     r[r.length] = select.options[i].text;
 return r;
}



//get the selected value
function getSelectedValues (select) {
 var r = new Array();
 for (var i = 0; i < select.options.length; i++)
   if (select.options[i].selected)
     r[r.length] = select.options[i].value;
 return r;
}

//set a particular value as selected
function setSelectedValue (select, valueToSelect) {
	 for (var i = 0; i < select.options.length; i++) {
		if (select.options[i].value == valueToSelect) {
			select.options[i].selected = true;
			return;	
		}
	 }
	 select.options.selectedIndex = -1;	
}

//*********************************HASHTABLE CODE BEGINS**********************************************//
function MyTable(){
	this.a = new Array();
	this.b = new Array();
	this.size = 0;
	this.put = put;
	this.get = get;
	this.keys = this.a;
	this.values = this.b;
	this.remove = remove;
	this.removeAll = removeAll;	
}
function removeAll(){
	with(this){
		a = new Array();
		b = new Array();
		size = this.a.length
		keys = this.a
		values = this.b
	}	
}

function remove(x){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i])
			break;
	}
	if(i == n)
		return;
	tKeys = new Array();
	tValues = new Array();
	count = 0
	for(j=0;j<n;j++){		
		if(j!= i){
			tKeys[count] = this.a[j]
			tValues[count] = this.b[j]
			count++;
		}
	}	
	this.a = tKeys
	this.b = tValues
	this.size = this.a.length
}

function get(x){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i])
			return this.b[i];
	}
	return null;
}
function put(x,y){
	n = this.size;
	for(i=0;i<n;i++){
		if(x == this.a[i]){
			this.b[i] = y;
			return;
		}
	}
	this.a[this.a.length] = x
	this.b[this.b.length] = y
	this.size = this.a.length;
}


//*********************************HASHTABLE CODE ENDS***********************************************//

//parses the form element (textbox) to replace all non digits by spaces. useful if need multiple int values from form, such
//as multiple ids.
	function parseMultipleIds(formElement) {
		tempStr = formElement.value;
		tempStr = tempStr.replace(/\D+/g, ' ');
		tempStr = tempStr.replace(/\s+/g, ' ');
		formElement.value = tempStr;
	}

//returns true if enter was pressed
function wasEnterPressed(event) { 
	NS4 = (document.layers) ? true : false;
	var code = 0;

	if (NS4)
		code = event.which;
	else
		code = event.keyCode;
	if (code==13){
		return true;
	}
	return false;
}


// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// -------------------------------------------------------------------
// autoComplete (text_input, select_input, ["text"|"value"], [true|false])
//   Use this function when you have a SELECT box of values and a text
//   input box with a fill-in value. Often, onChange of the SELECT box
//   will fill in the selected value into the text input (working like
//   a Windows combo box). Using this function, typing into the text
//   box will auto-select the best match in the SELECT box and do
//   auto-complete in supported browsers.
//   Arguments:
//      field = text input field object
//      select = select list object containing valid values
//      property = either "text" or "value". This chooses which of the
//                 SELECT properties gets filled into the text box -
//                 the 'value' or 'text' of the selected option
//      forcematch = true or false. Set to 'true' to not allow any text
//                 in the text box that does not match an option. Only
//                 supported in IE (possible future Netscape).
// -------------------------------------------------------------------
function autoComplete (field, select, property, forcematch) {
	var found = false;
	if(typeof options != 'unDefined'){
		return;
	}
	if(select.options != null && select.options.length!= null){
	for (var i = 0; i < select.options.length; i++) {
	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
		}
	 }
	}
	
	
	if (found) { select.selectedIndex = i; }
	else { 
		select.selectedIndex = -1;
	 }
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
		}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;";
		//alert(" keycode is: " + event.keyCode);
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			//alert("r1 is " + r1);
			var oldValue = r1.text;
			//alert("oldValue is: " + oldValue);
			var newValue = found ? select.options[i][property] : oldValue;
			//alert("newValue is: " + newValue + " and field.value is: " + field.value);
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				//alert("rNew is : " + rNew);
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}

	//returns a value from various types of form objects
	function getValueFromVariousObjectTypes(myObj) {
		var objectValue = null;
		if (myObj != null) {
			if (myObj.type == "select-one") {
				 objectValue = getSelectedValues(myObj)[0];
			}
			else if (myObj.type == "text" || myObj.type == "hidden") {
				objectValue = myObj.value;
			}
		}
		return objectValue;
	}


//-------------------------------------
// Disable all the buttons on current form.
	function disableButtonsGlobal( elements ){
		if( elements != null && elements.length > 0 ){
			for(i = 0; i < elements.length; i++){
				var element = elements[i];
				if( element.type == "button" ){
					disableButton(element);
				}
			}		
		}
	}	
	
	
	function disableButton(buttonName){
		if( buttonName != null ){
			buttonName.disabled=true;
		}
	}
	
//-------------------------------------
// Global functions for transferring focus to next component on Enter.

function transferFocusOnEnter(event,eventSource, next, eventSourceCanNotBeEmpty,SELECT ){ 
	if( eventSource == null ){
		return;
	}
	if( eventSourceCanNotBeEmpty && eventSource.value.length <= 0 ){
		return;
	}
	if (wasEnterPressed(event)){
			focusObject(next);
	}		
}

function focusCursorOnLast(event,ctrl){	
	var pos = ctrl.value.length;	
	
	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();		
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}

}

function selectObject(objectName){
	// objectName is the string name of a UI component
	if( objectName != null ){
		var obj = objectName;
		if(typeof objectName =="string" && objectName.length > 0){
		 obj = document.getElementById(objectName);
		}
		if(obj != null){
			try{
			obj.focus();
			obj.select();
			}catch(e){}
		}
	}
}
function focusObject(objectName){
	// objectName is the string name of a UI component
	if( objectName != null ){
		var obj = objectName;
		if(typeof objectName =="string" && objectName.length > 0){
		 obj = document.getElementById(objectName);
		}
		if(obj != null){
			try{
			obj.focus();
			obj.select();
			}catch(e){}
		}
	}
}
//---------------------------------------------
function getBigDecimal(obj){
	if( obj == null ){
		return 0.00;
	}
	var str = obj.value;
	if( str == '' ){
		return 0.00;
	}
	var d = parseFloat(str);
	var bigDecimal = Math.round(d * 100) / 100 ;
	return bigDecimal;
}
//---------------------------------------------
function disableButtons(){
	disableButtonsGlobal( document.forms[0].elements );
}
function selectOnFocus( textField ){
   batchWarning = true;
   mostRecentInvoiceTotal = textField.value;
   if(parseFloat(textField.value) == 0.00){
       textField.value = "";
   }
   textField.select();
}


//Written by Tariq Khanani
//On 26 Jan 2007
//To limit No. of characters displayed in innerText in td and add a delimiter "..." at the end of text
//and to add a tooltip on the td to display complete text.
//Display length of text will be provided by developer for a particular td
//To use it, simply assign id value of "summarize" to target td and define an attribute of displayLength (No. of chars)
//and call below method on onload of body. 
//Example : <td id="summarize" displayLength="15">Some Long Text</td>

function summarize(showDots) {

    var summarize = document.all.summarize;
    var obj;
    var charLength = 13;
    var showDotsInTheEnd = false;
    var appendToTitle;
    var truncatedText="";
    if(typeof showDots != "undefined"){
    	showDotsInTheEnd = showDots;
    }
    if (summarize) {
        if (!summarize.length) {            //If only one cell with id=summarize, convert summarize to array with single cell object
            obj = summarize;                //at location 0
            summarize = new Array();
            summarize[0] = new Object();
            summarize[0] = obj;
        }
        for (i = 0; i < summarize.length; i++) {
            obj = summarize[i];
            if(typeof obj.appendToTitle == "undefined"){
		    	appendToTitle = false;
		    } else {
		    	appendToTitle = obj.appendToTitle * 1;
		    }
            var text = obj.innerText;
            text=text.replace(/^\s+/g, '').replace(/\s+$/g, '');	//trim
            if(appendToTitle||summarize[i].title==""){
	            summarize[i].title += text;
	        }
            if (summarize[i].displayLength) {
                charLength = summarize[i].displayLength;
            }
            if (text.length > charLength) {
                truncatedText = text.substring(0, charLength) 
                if(showDotsInTheEnd){
	                truncatedText += "...";
                }
                
				obj.innerHTML = obj.innerHTML.replace(text.replace(/&/g,'&amp;'),truncatedText.replace(/&/g,'&amp;'));
            }
        }  
        for (i = 0; i < summarize.length; i++) {
            obj = summarize[i];
            obj.setAttribute("id","summarizePerformed");		//so that if summarize is called again, they dont get summarize again
        }
    }
}



/*This method will go through all options in the select box and will check for the existance of value in select box*/
function containsValue(selectBox,value){
    if(selectBox==null || value==null)
        return;
    for(var i=0;i<selectBox.length;i++){
        if(parseInt(selectBox.options[i].value)==parseInt(value)){
            return true;
        }
    }
    return false;
}


//Written by Tariq Khanani
//On 28 Feb 2007
//To control input characters in a textbox, purpose was to only allow numbers in a textbox and deny 0 as first character
//Just call this method on onkeydown event of textfield
//like this onkeydown="event.returnValue=validDataInField(this,event,false,false)"

function validDataInField(obj, event, forceNumbersOnly, /*forceAlphabetsOnly,*/ zeroAllowedAtFirstPosition,allowDecimal, allowNegative) {
    var returnValue = true;
    var isNumber=false;
    var keyCode = event.keyCode;
    var shiftKey=event.shiftKey;
    allowDecimal=typeof allowDecimal!="undefined"?allowDecimal:false;
    /*Finding current cursor position*/
    if (typeof obj.selectionStart == "number") {
        i = obj.selectionStart;
    } else if (document.selection && obj.createTextRange) {
        sel = document.selection;
        if (sel) {
            r2 = sel.createRange();
            rng = obj.createTextRange();
            rng.setEndPoint("EndToStart", r2);
            i = rng.text.length;
        }
    }
    /*variable i holds the current cursor position starting from 0*/
    if (forceNumbersOnly) {            /*Only Numeric input required*/
        returnValue = ((keyCode < 58 && keyCode > 47) || (keyCode < 106 && keyCode > 95));
        //keyCode 48 to 57 && 96 to 105 are for numbers

        if (returnValue) {                                    //If input is a number
            returnValue = returnValue && !event.shiftKey;    //Make sure user is not pressing shift key along with number
                                                            //to avoid characters like '!@#$%^&*()'
        }
        returnValue = returnValue || (keyCode < 47 && keyCode != 32);   //keys like arrows and Delete,Insert are allowed but not space (keyCode 32)
    }
    if ((keyCode == 48 || keyCode == 96) && !zeroAllowedAtFirstPosition &&  !event.shiftKey) {      //If number is 0 and zeroNotAllowedAtFirstPosition
            returnValue = !(i == 0);                //If current cursor position is 0 (first position) Dont allow it
    }
    if((keyCode==110||keyCode==190)&&allowDecimal){             //keycodes 110 and 190 are for decimal
        returnValue = !(i == 0)&&(obj.value.indexOf(".")<0);    //dont allow if cursor is at first position or there is already a decimal in field value
    }
    if((keyCode==109||keyCode==189)&&allowNegative){             //keycodes 110 and 190 are for decimal
        returnValue = (i == 0)&&(obj.value.indexOf("-")<0);    //dont allow if cursor is at first position or there is already a decimal in field value
    }
    /*if (forceAlphabetsOnly) {
        returnValue = ((keyCode < 91 && keyCode > 64) || keyCode < 47);
    }*/
    return returnValue;
}

function formatTimeDBToUI(time){
    var timeArray = time.split(":");
    var hour, min, ampm;
    if(timeArray[0]>=12){
        ampm="PM";
        if(timeArray[0]!=12){
            hour = timeArray[0]-12;
        }else{
            hour = timeArray[0];
        }
    } else {
        ampm="AM";
        hour = timeArray[0];
        if(parseInt(hour,10)==0){
        	hour="12";
        }
    }
    if (parseInt(hour,10) < 10) {
        hour = "0" + parseInt(hour,10);
    }
    min = timeArray[1];
    return hour+":"+min+" "+ampm;
}


/*
   General purpose method for copying options of one drop-down (referenced by collection) to
   another drop-down (referenced by targetDropDown). startIndex and endIndex denote range of options from collection
   to be copied.
   Added By: Tariq Khanani
   On: June 28, 2007
*/

function copyDropDownOptions(sourceDropDown, targetDropDown,startIndex,endIndex) {
    var sourceOptions = sourceDropDown.options;
    for (l = startIndex; l < endIndex; l++) {
        var option = document.createElement("OPTION");
        targetDropDown.add(option);
        option.text = sourceOptions[l].text;
        option.value = sourceOptions[l].value;
        if(sourceOptions[l].style.backgroundColor){
	        option.style.backgroundColor = sourceOptions[l].style.backgroundColor;
        }
    }
}
/**
	This method for general pupose of confirm messages with N number of buttons
	return value would be as you defined in argument "buttonsWithValue"
	for example buttonsWithValue = "Button1:1, Button2:2, Button3:3, Button4:4"
	"Button1" is Button text and "1" button value which would be return if clicked
	if no any buttons define then cancel button will show with 0 value 
**/
function showConfirmPopup(title, message, buttonsWithValue, widthValue, heightValue, imagePath, showButtonAsList){

	
	var height = typeof heightValue != 'undefined' ? heightValue : 200;
	var width =  typeof widthValue != 'undefined' ? widthValue : 400;
	var image =  typeof imagePath != 'undefined' ? imagePath : "" ;
	if(typeof(showButtonAsList) == "undefined"){showButtonAsList = false;}
	
	var url =  "../Common/confirmPopupMessage.jsp";
		url += "?title="+title;
		url += "&message="+message;
		if(typeof buttonsWithValue != 'undefined')
			url += "&buttons="+buttonsWithValue;
		if(typeof(showButtonAsList) != "undefined"){
			url += "&showButtonAsList="+showButtonAsList;
		}
	var returnValue = showModalDialog(url, window, 'scroll:no;status:no;help:no;dialogHeight:'+height+'px;dialogWidth:'+width+'px;');
	if(typeof returnValue != 'undefined'){
		return  returnValue;
	}
	else{
		return -1;
	}
	

}


function getNextDate(sourceDate , noOfDays) {     
	var nextDate = new Date(parseInt(sourceDate.valueOf() + (86400000 * (parseInt(noOfDays)))));
    if(nextDate.getHours()!=0 && nextDate.getHours()!=sourceDate.getHours()){
	  	nextDate = new Date(parseInt(nextDate.valueOf() + ((sourceDate.getHours()-nextDate.getHours())*3600000)));
	}
	return nextDate;
}

function checkCountry(obj) 
{
    if (obj.value != 'United States' && obj.value != 'Canada') {
       document.getElementById("state").selectedIndex = 0;
        document.getElementById("state").disabled = true;
    }
    else {
            if(!document.getElementById("country").disabled){
              document.getElementById("state").disabled = false;
        }
        var obj2 = eval(document.getElementById("state"));
        var stateTemp = obj2.value;
        if (obj.value == 'United States') {
            obj2.options.length = 0;
            obj2.options[0] = new Option("--Select--", "");
            obj2.options[1] = new Option("Alabama", "AL");
            obj2.options[2] = new Option("Alaska", "AK");
            obj2.options[3] = new Option("Arizona", "AZ");
            obj2.options[4] = new Option("Arkansas", "AR");
            obj2.options[5] = new Option("California", "CA");
            obj2.options[6] = new Option("Colorado", "CO");
            obj2.options[7] = new Option("Connecticut", "CT");
            obj2.options[8] = new Option("Delaware", "DE");
            obj2.options[9] = new Option("District of Columbia", "DC");
            obj2.options[10] = new Option("Florida", "FL");
            obj2.options[11] = new Option("Georgia", "GA");
            obj2.options[12] = new Option("Hawaii", "HI");
            obj2.options[13] = new Option("Idaho", "ID");
            obj2.options[14] = new Option("Illinois", "IL");
            obj2.options[15] = new Option("Indiana", "IN");
            obj2.options[16] = new Option("Iowa", "IA");
            obj2.options[17] = new Option("Kansas", "KS");
            obj2.options[18] = new Option("Kentucky", "KY");
            obj2.options[19] = new Option("Louisiana", "LA");
            obj2.options[20] = new Option("Maine", "ME");
            obj2.options[21] = new Option("Maryland", "MD");
            obj2.options[22] = new Option("Massachusetts", "MA");
            obj2.options[23] = new Option("Michigan", "MI");
            obj2.options[24] = new Option("Minnesota", "MN");
            obj2.options[25] = new Option("Mississippi", "MS");
            obj2.options[26] = new Option("Missouri", "MO");
            obj2.options[27] = new Option("Montana", "MT");
            obj2.options[28] = new Option("Nebraska", "NE");
            obj2.options[29] = new Option("Nevada", "NV");
            obj2.options[30] = new Option("New Hampshire", "NH");
            obj2.options[31] = new Option("New Jersey", "NJ");
            obj2.options[32] = new Option("New Mexico", "NM");
            obj2.options[33] = new Option("New York", "NY");
            obj2.options[34] = new Option("North Carolina", "NC");
            obj2.options[35] = new Option("North Dakota", "ND");
            obj2.options[36] = new Option("Ohio", "OH");
            obj2.options[37] = new Option("Oklahoma", "OK");
            obj2.options[38] = new Option("Oregon", "OR");
            obj2.options[39] = new Option("Pennsylvania", "PA");
            obj2.options[40] = new Option("Rhode Island", "RI");
            obj2.options[41] = new Option("South Carolina", "SC");
            obj2.options[42] = new Option("South Dakota", "SD");
            obj2.options[43] = new Option("Tennessee", "TN");
            obj2.options[44] = new Option("Texas", "TX");
            obj2.options[45] = new Option("Utah", "UT");
            obj2.options[46] = new Option("Vermont", "VT");
            obj2.options[47] = new Option("Virginia", "VA");
            obj2.options[48] = new Option("Washington", "WA");
            obj2.options[49] = new Option("West Virginia", "WV");
            obj2.options[50] = new Option("Wisconsin", "WI");
            obj2.options[51] = new Option("Wyoming", "WY");
        }
        else {
            obj2.options.length = 0;
            obj2.options.length = 0;
            obj2.options[0] = new Option("--Select--", "");
            obj2.options[1] = new Option("Alberta", "AB");
            obj2.options[2] = new Option("British Columbia", "BC");
            obj2.options[3] = new Option("Manitoba", "MB");
            obj2.options[4] = new Option("New Brunswick", "NB");
            obj2.options[5] = new Option("Newfoundland", "NL");
            obj2.options[6] = new Option("Northwest Territories", "NT");
            obj2.options[7] = new Option("Nova Scotia", "NS");
            obj2.options[8] = new Option("Nunavut", "NU");
            obj2.options[9] = new Option("Ontario", "ON");
            obj2.options[10] = new Option("Prince Edward Island", "PE");
            obj2.options[11] = new Option("Quebec", "QC");
            obj2.options[12] = new Option("Saskatchewan", "SK");
            obj2.options[13] = new Option("Yukon", "YT");
        }
        if(document.getElementById("state").value=="") {
           document.getElementById("state").value=stateTemp;
        }
    }
}


function hideLeftPanel(){
	var searchWindow; 
	if (navigator.userAgent.toLowerCase().indexOf("msie") > 0 ){ 
	  searchWindow = window.parent.parent.frames[2].frm.flag.value;
	}else{
	  searchWindow = window.parent.parent.frames[2].frameElement.contentWindow.document.forms[0].flag.value;
	} 
    if(searchWindow==1){
            window.parent.parent.frames[2].hidetoc();
    }
}

function showLeftPanel(){
	var searchWindow; 
	if (navigator.userAgent.toLowerCase().indexOf("msie") > 0 ){ 
	  searchWindow = window.parent.parent.frames[2].frm.flag.value;
	}else{
	  searchWindow = window.parent.parent.frames[2].frameElement.contentWindow.document.forms[0].flag.value;
	} 
    if(searchWindow==0){
        window.parent.parent.frames[2].hidetoc();
    }
}


/**
	compareStringFormatTime 
**/
function compareStringFormatTime(aa, bb) {

    dt1 = new Date();
    dt1.setHours(aa.substring(0,2));
    dt1.setMinutes(aa.substring(3,5));
    if(aa.substring(6,8).toLowerCase() == "pm"){
    	dt1.setSeconds(0);
    	if(dt1.getHours() < 12){
    		dt1.setHours(dt1.getHours()+12);
   		}
    }else if(aa.substring(6,8).toLowerCase() != "am"){
    	dt1.setSeconds(aa.substring(6,8));    	
    }else{
    	dt1.setSeconds(0);
    }
    
    
    dt2 = new Date();
    dt2.setHours(bb.substring(0,2));
    dt2.setMinutes(bb.substring(3,5));
    if(bb.substring(6,8).toLowerCase() == "pm"){
    	dt2.setSeconds(0);
    	if(dt2.getHours() < 12){
    		dt2.setHours(dt2.getHours()+12);
   		}
    }else if(bb.substring(6,8).toLowerCase() != "am"){
    	dt2.setSeconds(bb.substring(6,8));    	
    }else{
    	dt2.setSeconds(0);
    }
    

    if (dt1.toString()=="NaN" && dt2.toString()=="NaN") return 0;
    else if (dt1.toString()=="NaN" && dt2.toString()!="NaN") return -1;
    else if (dt1.toString()!="NaN" && dt2.toString()=="NaN") return 1;
    else if (dt1.valueOf()==dt2.valueOf()) return 0;
    else if (dt1.valueOf() < dt2.valueOf()) return -1;
    	
    return 1;
}


function setFocusOn(formIndex, elementName) {

   if(elementName != null && elementName.length > 0 && document.forms != null &&
      formIndex >= 0 && formIndex < document.forms.length) {
  
  	   var formObj = document.forms[formIndex];	
  	   
  	   if(formObj != null && formObj.elements != null && formObj.elements.length > 0){
  	   
	   	  var elementObj = formObj.elements[elementName];
	   	  
	   	  if(elementObj != null){
	   	  
	   	  	 elementObj.focus();
	   	  
	   	  }
	   	
	   }
	
   }
   	  
}

	var _bigTextAreaPanel = null;
	var _bigTextAreaPanel_txtArea = new Array();
	var _bigTextAreaPanel_closeButton = null;
	var _bigTextAreaPanel_cancelButton = null;
	
	/**
		must include yahoo.js, container.js and css
		sample method calling showBigTextAreaPanel("test", "test", "50", "10","hiddenField" "showGuestCountDialog", "1,2,3,4");
	**/
	function showBigTextAreaPanel(headerTitle, title, value, columns, rows, hiddenField, closeTrigger, triggerParams, buttonValue, cancelButtonValue){
		var arr = new Array();
		arr[0] = new Array();
		arr[0][0] = title;
		arr[0][1] = value == null ? hiddenField.value : value;
		arr[0][2] = hiddenField;
		arr[0][3] = columns;
		arr[0][4] = rows;
		
		
		showMultiBigTextAreaPanel(headerTitle, arr, closeTrigger, triggerParams, buttonValue, cancelButtonValue);
		
	}
	
	/**
	
		sample method calling showBigTextAreaPanel(
			array[textAreaLength][0] = title
			array[textAreaLength][1] = value
			array[textAreaLength][2] = hiddenField
			array[textAreaLength][3] = columns
			array[textAreaLength][4] = rows
			
		"test", "test", "50", "10", "showGuestCountDialog", "1,2,3,4");
	
	**/

	function showMultiBigTextAreaPanel(headerTitle, txtAreaArray, closeTrigger, triggerParams, buttonValue, cancelButtonValue){

		if(_bigTextAreaPanel == null){
		_bigTextAreaPanel = new YAHOO.widget.Panel("_bigTextAreaPanel",   
	            {   
	              fixedcenter:true,						                
	              close:true,  
	              draggable:true,  
	              zIndex:1002,  
	              visible:false,
	              modal: true,
	              constraintoviewport:true  
	               
	            }  
	        	); 
	        	
			
	        
	        var table = document.createElement("table");
	        table.id = "_bigTextAreaPanel_txtArea_main_table";
	        
	        
	        
			var buttonTable = document.createElement("table");
			var btd = buttonTable.insertRow().insertCell();
			
			_bigTextAreaPanel_closeButton = document.createElement("<input type='button' id='_bigTextAreaPanel_closeButton' class='button' value='" + (typeof(buttonValue) == "undefined" ? "Ok" : buttonValue) + "'>");
			btd.insertAdjacentElement("BeforeEnd", _bigTextAreaPanel_closeButton);
			
			btd.insertAdjacentHTML("BeforeEnd", "&nbsp;&nbsp;");
			
			_bigTextAreaPanel_cancelButton = document.createElement("<input type='button' id='_bigTextAreaPanel_cancelButton' class='button' value='" + (typeof(cancelButtonValue) == "undefined" ? "Cancel" : cancelButtonValue) + "'>");
			btd.insertAdjacentElement("BeforeEnd", _bigTextAreaPanel_cancelButton);
			
			_bigTextAreaPanel.setHeader("<span class='content' style='color: white;'>" + headerTitle + "</span>");
			_bigTextAreaPanel.setBody(table);
			
			_bigTextAreaPanel.setFooter(buttonTable);
			
			_bigTextAreaPanel.render(document.body);
			//_bigTextAreaPanel.hideEvent.subscribe( function(){_bigTextAreaPanel_closeButton.click();} );
			
			_bigTextAreaPanel_cancelButton.onclick =  function(){
				_bigTextAreaPanel.hide();
			}
			
 		 }else{
 		 
 		 	if(typeof(buttonValue) != "undefined"){
				_bigTextAreaPanel_closeButton.value = buttonValue; 		 	
 		 	}
 		 
 		 }
 		 
        var table = document.getElementById("_bigTextAreaPanel_txtArea_main_table");
 		 	 
 		  
 		 for(var i=0 ; i<txtAreaArray.length; i++){

			var columns = 70;
			var rows = 8;
			
			if(typeof(txtAreaArray[i][3]) != "undefined"){
				columns = txtAreaArray[i][3];
			}
			
			if(typeof(txtAreaArray[i][4]) != "undefined"){
				rows = txtAreaArray[i][4];
			} 

			if( document.getElementById("_bigTextArea"+i) == null ){

				_bigTextAreaPanel_txtArea[i] = new Array();
				_bigTextAreaPanel_txtArea[i][0] = document.createElement("table");
				_bigTextAreaPanel_txtArea[i][0].id = ("_bigTextAreaPanel_txtArea_inner_table"+i);	
				
				
				
				var title = _bigTextAreaPanel_txtArea[i][0].insertRow().insertCell();
				title.className = "heading";
				title.innerHTML = txtAreaArray[i][0];
				
				var td = _bigTextAreaPanel_txtArea[i][0].insertRow().insertCell();
				
				
				_bigTextAreaPanel_txtArea[i][1] = document.createElement("<textarea id='_bigTextArea"+i+"' name='_bigTextArea"+i+"' cols='"+columns+"' rows='"+rows+"' class='editarea' style='text-align: left;' ></textarea>");
				
				td.insertAdjacentElement("BeforeEnd", _bigTextAreaPanel_txtArea[i][1]);
				
				_bigTextAreaPanel_txtArea[i][1].innerText = txtAreaArray[i][1];
				
				var tableRow = table.insertRow();
				tableRow.id = ("_bigTextAreaPanel_txtArea_inner_table_tr"+i);
				tableRow.insertCell().insertAdjacentElement("BeforeEnd", _bigTextAreaPanel_txtArea[i][0]);
				
				
			}else{
				var addedTable = _bigTextAreaPanel_txtArea[i][0];
				addedTable.rows[0].childNodes[0].innerHTML = txtAreaArray[i][0];
				addedTable.rows[1].childNodes[0].childNodes[0].innerText = txtAreaArray[i][1];
				addedTable.rows[1].childNodes[0].childNodes[0].cols = columns;
				addedTable.rows[1].childNodes[0].childNodes[0].rows = rows;
				addedTable.parentNode.parentNode.style.display = "";
				
			}
 		 	
 		 }
 		 
 		 for(var i=txtAreaArray.length ; _bigTextAreaPanel_txtArea.length > i; i++){
 		 	document.getElementById("_bigTextAreaPanel_txtArea_inner_table_tr"+i).style.display="none";
		 }
	    
	 		 
		_bigTextAreaPanel_cancelButton.value = (typeof(cancelButtonValue) == "undefined" ? "Cancel" : cancelButtonValue);

		_bigTextAreaPanel_closeButton.onclick =  function(){
					
			for(var i=0; i<txtAreaArray.length; i++){		
				if(typeof(txtAreaArray[i][2]) != "undefined" && txtAreaArray[i][2] != null){
				
					if(_bigTextAreaPanel != null){
		 				txtAreaArray[i][2].value = _bigTextAreaPanel_txtArea[i][1].innerText;
		 			}else{
		 				txtAreaArray[i][2].value = "";
		 			}
		 		
				}
			}

			if(typeof(closeTrigger) != "undefined" && closeTrigger != null){
			
				if(triggerParams == null || typeof(triggerParams) == "undefined" || triggerParams == null){
					triggerParams = "";
				}else{
					triggerParams += ",";
				}
				closeTrigger += "(" + triggerParams;
				
				for(var i=0; i<txtAreaArray.length; i++){		
				
					closeTrigger += "'"+escape(_bigTextAreaPanel_txtArea[i][1].innerText) +"'";
					if( (i+1) < txtAreaArray.length ){
						closeTrigger += ", ";
					}
				
				}
				
				closeTrigger += ")";
				
				
				eval(closeTrigger);
			
				closeTrigger = null;
				triggerParams = null;

			}
			
			_bigTextAreaPanel.hide();
			
		};
		_bigTextAreaPanel.show();
		 
	 }
	 
	 function getBigTextAreaPanelValue(position){
	 	
	 	if(_bigTextAreaPanel != null){
	 		
	 		if(typeof(position) == "undefined"){
	 			return _bigTextAreaPanel_txtArea[0][1].innerText;
	 		}else{
	 			return _bigTextAreaPanel_txtArea[position][1].innerText;
	 		}
	 		
	 	}else{
	 		return "";
	 	}
	 	
	 }

	 
	 /*Method for adding an option in drop-down*/
function addOption(obj, value, text) {
	if(!obj || typeof obj != "object"){
		return;
	}
    var oOption = document.createElement("OPTION");
    obj.options.add(oOption);
    oOption.innerText = text;
    oOption.value = value;
}

function addDefaultOption(obj, id, label) {
    var oOption = document.createElement("OPTION");
    obj.options.add(oOption);
    var optionValue="0";
    if (id != null) {
        oOption.innerText = label;
        oOption.value = id;
    }else {
        oOption.innerText = "--Select--";
        oOption.value = optionValue;
    }
}

function disableFields(elements)
{
       if( elements != null && elements.length > 0 ){
			for(i = 0; i < elements.length; i++){
				var element = elements[i];
				   if( element.type == "text" ){
					disableTextField(element);
					}
					if( element.className == "textinput" ){
						disableSelectBox(element);
					}
					if( element.type == "checkbox" ){
						disableCheckBox(element);
					}
				    if( element.type == "button" ){
					   disableButton(element);
				   }
				}
			}    
}

function disableTextField(fieldName){
		if( fieldName != null ){
			fieldName.className=" textinputDisabled";		
		}
	}
	
function disableSelectBox(fieldName){
    if( fieldName != null ){
		fieldName.disabled=true;
	}
}

function disableCheckBox(fieldName){
		if( fieldName != null ){
			fieldName.disabled=true;	
		}
}

function disableButton(fieldName){
		if( fieldName != null ){
			fieldName.style.visibility='hidden';
		}
}

function datesOverLap(sourceFromDate,sourceToDate,targetFromDate,targetToDate,excludeToDate){
	if(typeof sourceFromDate=="string") sourceFromDate = new Date(sourceFromDate);
	if(typeof sourceToDate=="string") sourceToDate = new Date(sourceToDate);
	if(typeof targetFromDate=="string") targetFromDate = new Date(targetFromDate);
	if(typeof targetToDate=="string") targetToDate = new Date(targetToDate);
	if(isNaN(sourceFromDate) || isNaN(sourceToDate)|| isNaN(targetToDate)|| isNaN(targetToDate)){
		alert("Invalid parameters");
		return true;
	}
	if(sourceFromDate!=sourceToDate && targetFromDate != targetToDate){
		if(excludeToDate){
			if (!(sourceFromDate>=targetToDate || sourceToDate<=targetFromDate)) {
			   return true;
		    }
	    } else {
		    if (!(sourceFromDate>targetToDate || sourceToDate<targetFromDate)) {
			   return true;
		    }	
	    }
	} else {
		if(!(sourceFromDate > targetToDate || sourceToDate < targetFromDate)){
		   return true;
		}
	}
	return false;
}

//alert(datesOverLap("09/09/2008","09/15/2008","09/11/2008","09/13/2008",true))

function addTimer(containerId, assignedMinutes, interval){
	 
	 	if(typeof(interval) == "undefined"){
	 		interval = 1000;
	 	}
	 
	 	var hours = (assignedMinutes > 60 ? assignedMinutes/60 : 0);
	 	var minutes = (assignedMinutes > 60 ? assignedMinutes%60 : assignedMinutes);
		
		var container = document.getElementById(containerId);
	 	
		var timeStr = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : (minutes == 60 ? "00" : minutes)) + ":00";
		
		if(typeof(container) == "input"){
			container.value = timeStr;
		}else{
			if(container.innerText){
				container.innerText = timeStr;
			}else{
				container.innerHTML = timeStr;
			}		
		}

	 	container.setAttribute("_hours", hours);
	 	container.setAttribute("_minutes", minutes ); 
	 	container.setAttribute("_seconds", 60);
	 	
	 	setInterval("_callTimer('" + containerId + "');", interval);
	 }
	 
	 function _callTimer(containerId, interval){
		var container = document.getElementById(containerId);
		
		var seconds = container.getAttribute("_seconds");
		var minutes = container.getAttribute("_minutes");
		var hours = container.getAttribute("_hours");
		
		if(seconds == 60){
			minutes --;
			if(minutes < 0){
				hours --;
				minutes = 60;
			}
			
		}
		
		seconds--;
		
		if(seconds == 0){			
			seconds = 60;
		}
		
		
				
		var timeStr = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : (minutes == 60 ? "00" : minutes)) + ":" + (seconds < 10 ? "0" + seconds : (seconds == 60 ? "00" : seconds));
		
		if(typeof(container) == "input"){
			container.value = timeStr;
		}else{
			if(container.innerText){
				container.innerText = timeStr;
			}else{
				container.innerHTML = timeStr;
			}		
		}
		
	 	container.setAttribute("_hours", hours);
	 	container.setAttribute("_minutes", minutes); 
	 	container.setAttribute("_seconds", seconds);

	 }

	 
	 function getRadioValue(radioName){
		var radio = eval("document.forms[0]."+radioName);
		if(typeof(radio.length) == "undefined"){
		   if(radio.checked){
			 return radio.value;
			}
		}else{
		for(var i=0;i<radio.length;i++){
			if(radio[i].checked){
				return radio[i].value;
			}
		}
	 }
	}
	function addOptions(combo,values,defaultSelected,selected)
	{
		for(var j=0;j<values.length;j++)
		{
			/*new Option([text], [value], [defaultSelected], [selected])
			text: String that sets the text of the option 
			value: String that sets the value attribute of the option 
			defaultSelected: Boolean that sets whether this option should be the default selected option (same effect as setting the defaultSelected attribute). 
			selected: Boolean that sets whether this option should be selected (same effect as setting the selected attribute). 
			*/		
			combo.options[j]=new Option(values[j].value,values[j].id,defaultSelected,selected);
		}
		return combo;
	}
	
	// Array.contains(obj) - Return true/false based on presence/absence of given obj/value in the array
	Array.prototype.contains = function(obj) {
  		var i = this.length;
		while (i--) {
			if (this[i] == obj) {
			    return true;
		    }
	    }
		return false;
	}
	
	// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
	Array.prototype.indexOf = function( v, b, s ) {
		for( var i = +b || 0, l = this.length; i < l; i++ ) {
			if( this[i]===v || s && this[i]==v ) { return i; }
		}
		return -1;
	};
	
	
	function addTime(inputTime, minutesToAdd){	//inputTime e.g 01:55 AM

		var min = inputTime.split(":")[1].split(" ")[0]*1;
		var hour = inputTime.split(":")[0]*1;
		var ampm = inputTime.split(":")[1].split(" ")[1];
		
		if((min+minutesToAdd)>=60) {
		  if(hour==12) hour=1;
		  else hour+=1;
		  
		  min=min+minutesToAdd-60; 
		} else {
			min+=minutesToAdd;
		}
		
		if(hour==12) {
			if(ampm=="AM") ampm = "PM"; 
			else ampm = "AM";
		}
		if(hour<10) hour="0"+hour;
		if(min<10) min="0"+min;
		     				
		return hour+":"+min+" "+ampm;
	}
	
	
	function disableAnchors(){
		document.getElementsByTagName("a");
		for(var i=0;i<document.getElementsByTagName("a").length;i++){
			var anch = document.getElementsByTagName("a")[i];
			anch.hrefBk = anch.href;
			anch.onclickBk = anch.onclick;
			anch.href = "javascript:void(0)";
			anch.onclick = null;
		}
	}
	
	function enableAnchors(){
		document.getElementsByTagName("a");
		for(var i=0;i<document.getElementsByTagName("a").length;i++){
			var anch = document.getElementsByTagName("a")[i];
			if(anch.hrefBk){
				anch.href = anch.hrefBk;
				anch.onclick = anch.onclickBk;
			}
		}
	}