// General.js

//************************
// Miscellaneous Functions
//************************

	var VehicleConfig = new Array(10);
	for(i = 0; i < VehicleConfig.length; ++ i){
		VehicleConfig [i] = new Array(2);	
	}

	VehicleConfig[0][0] = 'Front Seating' ;VehicleConfig[0][1] = 'FRONTSEATING';
	VehicleConfig[1][0] = 'Driver Front' ;VehicleConfig[1][1] = 'DRIVERFRONT';
	VehicleConfig[2][0] = 'Passenger Center' ;VehicleConfig[2][1] = 'PASSCENTER';
	VehicleConfig[3][0] = 'Passenger Front' ;VehicleConfig[3][1] = 'PASSFRONT';
	VehicleConfig[4][0] = 'Center Right Rear' ;VehicleConfig[4][1] = 'CENTERRIGHTREAR';

	VehicleConfig[5][0] = 'Center Rear Center' ;VehicleConfig[5][1] = 'CENTERREARCENTER';					
	VehicleConfig[6][0] = 'Center Left Rear' ;VehicleConfig[6][1] = 'CENTERLEFTREAR';
	VehicleConfig[7][0] = 'Right Rear' ;VehicleConfig[7][1] = 'RIGHTREAR';
	VehicleConfig[8][0] = 'Center Rear' ;VehicleConfig[8][1] = 'CENTERREAR';						
	VehicleConfig[9][0] = 'Left Rear' ;VehicleConfig[9][1] = 'LEFTREAR';
	
//Nothing - prevents reload on pages when calling
//other javascript
function doNothing(){return;}

//Determines if object exists on the document
function isObject(obj) {
	if (typeof(obj) == "undefined" || obj == null)  {
		return false;
	} else {
		return true;
	}
}

function getElement(id) {
  return document.getElementById ? document.getElementById(id): document.all ? document.all[id] : null;
}

//************************
// String Functions
//************************

// trim - Function simliar to @Trim in @Functions
function trim ( inputStringTrim ) {
	fixedTrim = "";
	lastCh = " ";
	for (x=0; x < inputStringTrim.length; x++) {
		ch = inputStringTrim.charAt(x);
		if ((ch != " ") || (lastCh != " ")) { 
			fixedTrim += ch; 
		}
		lastCh = ch;
	}
	if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
		fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); 
	}
	return fixedTrim;
}

// Removes spaces (i.e. thousands seperator) from a string
function removeSpaces( inputStringTrim) {
	fixedTrim = "";
	for (x = 0; x < inputStringTrim.length; x++) {
		ch = inputStringTrim.charAt(x);
		if (ch != " ") {
			fixedTrim += ch;
		}
	}
	
	if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
		fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1);
	}
	
	return fixedTrim;
}

// Word - Similiar to @Word in @Functions
function Word(string, character, num) {
var temp = "";
string = character + string;
splitstring = string.split(character);
for(i = 0; i < splitstring.length; i++) {
	if (num == i)
		 return splitstring[i];
}
return temp;
}

// WordArr - Similar to @Word in @Functions only works on an array, need Word function too
function WordArr(string, character, num) {
var temp = "";
var arr = string.split(";");
var tempstr;

for (index = 0; index < arr.length; index++) {
	tempstr = Word(arr[index], character, num);
	if (temp == "") {
		temp = tempstr;
	}
	else {
		temp = temp + ";" + tempstr;
	}
}

return temp;
}

//Determines if value is on list
function isOnList(myarr, value, sep) {
	var temp;
	var index;
	
	temp = myarr.split(sep);
	for (index = 0; index < temp.length; index++) {
		if (trim(temp[index]) == trim(value)) {
			return true;
		}
	}

	return false;
}

function isInArray( searchS, arraySA ) {
 var i = 0;
 var min = 0;
 var max = arraySA.length - 1;
 var s = "";
 var foundB = false;

 i = min - 1;
 while ( ( i <= max ) && ( !( foundB ) ) ) {
  i = i + 1;
  s = arraySA[ i ];
  foundB = ( searchS == s );
  }
 if ( foundB ) {
  return( i ); //first instance
 }
 else {
  return( -1000 ); // some negative number indicating not found
 }
}

//************************
// Number Functions
//************************

//rounds number to specified # of decimals
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals);
    var result2 = Math.round(result1);
    var result3 = result2 / Math.pow(10, decimals);
    return pad_with_zeros(result3, decimals);
}

//pads rounded # with zeros
function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString();
    var decimal_location = value_string.indexOf(".");

    // Is there a decimal point?
    if (decimal_location == -1) {
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0;
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : "";
    } else {
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1;
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length;
    
    if (pad_total > 0) {
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) {
            value_string += "0";
        }
	}
    return value_string;
}

//************************
// Field Functions
//************************
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[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

// getSelectedDD - find out which item is selected, reutnrs a number; for drop-down
function getSelectedDD(buttonGroup) {
	for (var i = 0; i < buttonGroup.length; i++) {
		if (buttonGroup[i].selected) {
			return i;
		}
	}
	return -1;
}

function getSelectedDDText(buttonGroup, retval) {
	index = getSelectedDD(buttonGroup);
	if(index != -1){
		return buttonGroup[index].text;
	}else{
		return retval;
	}
}

// getIndexDD - Find out which number an entry is on a drop down list
function getIndexDD(buttonGroup, newVal) {
	if (isObject(buttonGroup)) {
		for (var i = 0; i < buttonGroup.length; i++) {
			if (buttonGroup.options[i].value == newVal) {
				return i;
			}
		}
	}
	return -1;
}

// getSelected - find out which item is selected, returns a number; For radio button
//		>> use getSelectedRadio instead.
function getSelected(buttonGroup) {
	getSelectedRadio(buttonGroup);
}

//clearChecked - clear all options that have been checked
function clearChecked(buttonGroup) {
	for (var i = 0; i < buttonGroup.length; i++) {
		buttonGroup[i].checked = false;
	}
}

//setChecked - mark radio button / checkbox with specified value
function setChecked(buttonGroup, newVal) {
	for (var i = 0; i < buttonGroup.length; i++) {
		if (buttonGroup[i].value == newVal) {
			buttonGroup[i].checked = true;
		}
	}
}

//setCheckedMulti - mark radio button / checkbox with specified values
function setCheckedMulti(buttonGroup, newVals, sep) {
	for (var i = 0; i < buttonGroup.length; i++) {
		if (isOnList(newVals, buttonGroup[i].value, sep)) {
			buttonGroup[i].checked = true;
		}
	}
}

//clearSelectedDD - clear all values from drop-down
function clearSelectedDD(buttonGroup) {
	for (var i = 0; i < buttonGroup.length; i++) {
		buttonGroup[i].selected = false;
	}
}

//setSelectedDD - set specified value on drop down
function setSelectedDD(buttonGroup, newVal) {
	var index = getIndexDD(buttonGroup, newVal);
	if (index > -1) {
		buttonGroup.options[index].selected = true;
	}
}

//setSelectedDDMulti - set specified values on drop down
function setSelectedDDMulti(buttonGroup, newVals, sep) {
	tmparr = newVals.split(sep);
	for (var i = 0; i < tmparr.length; i++) {
		setSelectedDD(buttonGroup, tmparr[i]);
	}
}

//Concatenates multi-valued fields into single valued field (drop-downs)
function updateDVFArray(obj, objtoset) {
        var note = window.document.forms[0];
        var sep = '|';
        var newstr = '';
        for (index = 0; index < obj.length; index++) {
        		if(obj[index].checked != undefined && obj[index].checked){			
                   newstr = newstr + obj[index].value + sep;
                }else if(obj[index].selected != undefined && obj[index].selected){
                   newstr = newstr + obj.options[index].value + sep;
                }
        }
        objtoset.value = newstr;        
}

//Concatenates multi-valued fields into single valued field (drop-downs)
function updateDVFArrayAll(obj, objtoset) {
        var note = window.document.forms[0];
        var sep = '|';
        var newstr = '';
        for (index = 0; index < obj.length; index++) {
			newstr = newstr + obj.options[index].value + sep;
        }
        objtoset.value = newstr;        
}

//Concatenates multi-valued fields into single valued field (radio buttons)
function updateDVFArrayRadio(obj, objtoset) {
        var note = window.document.forms[0];
        var sep = '|';
        var newstr = '';
        for (index = 0; index < obj.length; index++) {
                if(obj[index].checked == true){
                        newstr = newstr + obj[index].value + sep;
                }
        }
        objtoset.value = newstr;        
}

//************************
// Form Functions
//************************

function showtab(url) {
	var note = document.forms[0];
   	note.RedirectURL.value = url;
   	note.action = "ServTabRedirect";
   	note.submit();
}

//************************
// LAYER SUPPORT FUNCTIONS
//************************

function toggleStaticLayer(id) {
  var openedID = id+"openedDivID";
  var closedID = id+"closedDivID";
  var openedDiv = getElement(openedID);
  var closedDiv = getElement(closedID);

  if (openedDiv.style.display == "none") {
    // we're currently CLOSED, so OPEN
    openedDiv.style.display = "inline";
    closedDiv.style.display = "none";
    layerStates[id] = 1;
  } else {
    // we're currently OPENED, so CLOSE
    closedDiv.style.display = "inline";
    openedDiv.style.display = "none";
    layerStates[id] = 0;
  }
  notifyParentOfHeightChange();
  return false;
}

function expandStaticLayer(id) {
  var openedID = id+"openedDivID";
  var closedID = id+"closedDivID";
  var openedDiv = getElement(openedID);
  var closedDiv = getElement(closedID);

    // we're currently CLOSED, so OPEN
    openedDiv.style.display = "inline";
    closedDiv.style.display = "none";
    layerStates[id] = 1;
}

function collapseStaticLayer(id) {
  var openedID = id+"openedDivID";
  var closedID = id+"closedDivID";
  var openedDiv = getElement(openedID);
  var closedDiv = getElement(closedID);

    // we're currently OPENED, so CLOSE
    closedDiv.style.display = "inline";
    openedDiv.style.display = "none";
    layerStates[id] = 0;
}

function toggleDynamicLayer(id, jspSource) {
  var openedID = id+"openedDivID";
  var closedID = id+"closedDivID";
  var openedDiv = getElement(openedID);
  var closedDiv = getElement(closedID);
  if (openedDiv.style.display == "none") {
    // we're currently CLOSED, so OPEN
    var div = document.getElementById(id+"DivID");
    div.innerHTML = "";
    openedDiv.style.display = "inline";
    closedDiv.style.display = "none";
    startProxyLoading(id, jspSource);
    layerStates[id] = 1;
  } else {
    // we're currently OPENED, so CLOSE
    closedDiv.style.display = "inline";
    openedDiv.style.display = "none";
    layerStates[id] = 0;
    notifyParentOfHeightChange();
  }
  return false;
}

function toggleEmbeddedLayer(id, jspSource) {
  var bufferid = id+"Buffer";
  var buffer = getIFrame(bufferid);
  if (buffer) {
    var openedID = id+"openedDivID";
    var closedID = id+"closedDivID";
    var openedDiv = getElement(openedID);
    var closedDiv = getElement(closedID);
    if (openedDiv.style.display == "none") {
      // we're currently CLOSED, so OPEN
      openedDiv.style.display = "inline";
      closedDiv.style.display = "none";
      if (isSafari) {
        setTimeout("loadMacIFrame(\"" + bufferid + "\",\"" + jspSource + "\");", 1);
      } else {
        if (!buffer.document.location.href || buffer.document.location.href.indexOf(jspSource) == -1) {
          buffer.document.location.href = jspSource;
        } else {
          notifyParentOfHeightChange();
        }
      }
      layerStates[id] = 1;
    } else {
      // we're currently OPENED, so CLOSE
      closedDiv.style.display = "inline";
      openedDiv.style.display = "none";
      layerStates[id] = 0;
      notifyParentOfHeightChange();
    }
  }
  return false;
}

function toggleStaticTableRowLayer(id, columns, classTranslationMapping) {
  toggleTableCellClasses(id, columns, classTranslationMapping);
  toggleTableRowLayer(id);
  return toggleStaticLayer(id);
}

function toggleDynamicTableRowLayer(id, columns, jspSource, classTranslationMapping) {
  toggleTableCellClasses(id, columns, classTranslationMapping);
  toggleTableRowLayer(id);

  var openedID = id+"openedDivID";
  var closedID = id+"closedDivID";
  var openedDiv = getElement(openedID);
  var closedDiv = getElement(closedID);
  if (openedDiv.style.display == "none") {
    // we're currently CLOSED, so OPEN
    var div = getElement(id+"DivID");
    div.innerHTML = "";
    openedDiv.style.display = "inline";
    closedDiv.style.display = "none";
    startProxyLoading(id, jspSource);
    layerStates[id] = 1;
  } else {
    // we're currently OPENED, so CLOSE
    closedDiv.style.display = "inline";
    openedDiv.style.display = "none";
    layerStates[id] = 0;
    notifyParentOfHeightChange();
  }
  return false;
}

function toggleEmbeddedTableRowLayer(id, columns, jspSource, classTranslationMapping) {
  toggleTableCellClasses(id, columns, classTranslationMapping);
  toggleTableRowLayer(id);
  return toggleEmbeddedLayer(id, jspSource);
}

function toggleTableCellClasses(id, columns, classTranslationMapping) {
  // figure out the class translation mapping
  var ctmArray = new String(classTranslationMapping).split(";");
  var ctMap = new Object();
  for (var i=0; i<ctmArray.length; i++) {
    var pair = ctmArray[i].split("=");
    ctMap[pair[0]] = pair[1];
    ctMap[pair[1]] = pair[0]; // for reversibility
  }

  // set all styles in the row to special style or revert to original using translation map
  for (var i=0; i<columns; i++) {
    var cellID = id + "row_" + i;
    var e = getElement(cellID);
    e.className = ctMap[e.className];
  }
}

function toggleTableRowLayer(id) {
  var dataRowID = id + "row_data";
  var dataRow = getElement(dataRowID);
  if (dataRow.style.display == "none") {
    dataRow.style.display = "";
  } else {
    dataRow.style.display = "none";
  }
}

// the loadingLayers object is used to track which [dynamic] layers are in the *process* of loading
// loadingLayers[id] == 1 if loading, 0 or undefined if done loading or not loaded respectively
var loadingLayers = new Object();
function startProxyLoading(id, src) {
  var proxy = window.frames[id+"Proxy"];
  if (proxy) {
    loadingLayers[id] = 1;
    proxy.location.href = src;
    setTimeout("waitForProxyLoad('" + id + "')", 100);
  }
}

function waitForProxyLoad(id) {
  // we could do something here like display "loading..." if we wanted
  if (loadingLayers[id] == 1) {
    var div = getElement(id+"DivID");
    if (div) div.innerHTML = "Loading...";
  }
}

function notifyProxyLoadCompletion(id) {
  // proxy layer has loaded - copy html
  loadingLayers[id] = 0;
  var proxy = window.frames[id+"Proxy"];
  if (proxy) {
    var proxyDiv = proxy.document.getElementById(id);
    if (proxyDiv) {
      var divID = id+"DivID";
      var dest = getElement(divID);
      if (dest && typeof dest.innerHTML != "undefined") dest.innerHTML = proxyDiv.innerHTML;
      notifyParentOfHeightChange();
    }
  }
}

// if a layer (static/dynamic/embedded) changes in some way so as to affect its height (e.g. layer toggled, loaded, page changed),
// it should call this method.
// it essentially means that the CURRENT WINDOW has a layer that has changed height, and any containing iframes need
// to be resized accordingly.
// there are two possible containing iframe types: embedded window layer iframe, detail iframe
function notifyParentOfHeightChange() {
  // detail support
  if (isDetailWindow) setParentDetailWindowToDetailContentHeight();

  // layer support
//  if (_currentLayerID != null && window.parent && window.parent.setIframeHeight) {
//    if (isSafari) {
//      setTimeout("window.parent.setIframeHeight('" + _currentLayerID + "');", 1);
//    } else {
//      window.parent.setIframeHeight(_currentLayerID);
//    }
//  }
  if (window.parent && window.parent != window && window.parent.notifyParentOfHeightChange) {
    window.parent.notifyParentOfHeightChange();
  }
}
//************************
// Popup Functions
//************************

//Popup Window Code

//Display mouseover popup
//Add following code to page: <DIV ID=linkText STYLE="position:absolute; visibility:hidden; left:200; top:200; width:300; z-index:1"></DIV>
var theWindowSize = document.body.scrollHeight; 
function popup(text) {
    document.all.linkText.innerHTML='<TABLE BGCOLOR="#FEFD99" WIDTH=100% BORDER=0 ID="theTable"><TR><TD>' + text + '</TD></TR></TABLE>';
 	var theHeight=(window.event.clientY + document.body.scrollTop + 60);
	theHeight=theHeight -40;
	//var difference = document.body.clientWidth - window.event.clientX;
	linkText.style.posTop=theHeight;
	linkText.style.posLeft=100;
	linkText.style.visibility="visible"; 
	   
}
function closerr(){
	linkText.style.visibility="hidden";
}
//end mouseover popup

//Display dialog box for given link
var wtitle = 'dialog';
function showDialog(link, wwidth, wheight) {
	var doc = document.forms[0];
	var scommon = 'status=yes,resizable=yes,scrollbars=yes,menubar=no,directories=no,location=no';
	
	if (navigator.appVersion.indexOf('X11') != -1)  {
		dlgWin = window.open(link, wtitle, scommon + ',screenX=100,screenY=100,width=' + wwidth + ',height=' + wheight);
	} else {
		if (navigator.appName =='Netscape') {
			dlgWin = window.open(link, wtitle, scommon + ',screenX=120,screenY=100,width=' + wwidth + ',height=' + wheight);
		} else {
			dlgWin = window.open(link, wtitle, scommon + ',top=120,left=100,width=' + wwidth + ',height=' + wheight);
		}
	}

	return (dlgWin);
}

function showDialogGernic(link, wwidth, wheight, wstatus, wresizable, wscrollbars, wmenubar, wdirectories, wlocation, wscreenX, wscreenY, wtop, wleft) {
	var doc = document.forms[0];
	var scommon = 'status=' + wstatus + ',resizable=' + wresizable + ',scrollbars=' + wscrollbars + ',menubar=' + wmenubar + ',directories=' + wdirectories + ',location=' + wlocation;
	dlgWin = window.open(link, wtitle, scommon + ',top=' + wtop + ',left=' + wleft + ',width=' + wwidth + ',height=' + wheight);
}

function helpPopup(bookmark) {
	var url = "help.html";
	if (bookmark != '') {
		url = url + "#" + bookmark;
	}
	
	showDialogGernic('Sys_WebHelp.html', 500, 500, 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 100, 100, 100, 100);
}

function deleteItems() {
	var note = window.document.forms[0]; 
	note.Action.value = 'Delete'; 
	note.submit();
}

function copyItems() {
	var note = window.document.forms[0]; 
	note.Action.value = 'Copy'; 
	note.submit();
}

//Redirect assignment window
function redirectAssign(url) {
	var parenturl;
	
	if (isObject(opener.location)) {
		parenturl = opener.location.href;	
		
		var index = parenturl.indexOf('Sys_Assign.jsp');
		if (index == -1) {
			location.href = url;
		} else {
			opener.location.href = url;
			window.close()
		}
	} else {
		location.href = url;
	}
}

//Redirect assignment window
function redirectAssign(url) {
	var parenturl = opener.location.href;

	if (isObject(opener.location)) {
		opener.location.href = url;
		window.close()
	}
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	moveObject(objectId, newXCoordinate, newYCoordinate)
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate;
	styleObject.top = newYCoordinate;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject

var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
	if(pos=="random"){
		myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;
	}else if((pos!='center' && pos!="random") || pos==null){
		myleft=0;mytop=20
	}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes";
	win=window.open(mypage,myname,settings);
	win.focus();
}

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 formatNumberFromCurrency(curr) {
	return ('' + curr).toString().replace(/\$|\,/g,'');
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

function textGrow(field, rows, cols, rowsunit, colsunit) {
	newlines = newLineCount(field.value, '\n');
	if (field.value.length + newlines*colsunit> rows*cols){
		field.rows = (field.value.length/(rowsunit*colsunit)) + newlines + 1;
	}else if(field.value.length + newlines*colsunit< (rows*cols-rowsunit*colsunit)){
		field.rows = (field.value.length/(rowsunit*colsunit)) + newlines + 1;
	}
}

function newLineCount(textstr, chartosearch){
	countchar = 0;	
	for (x=0; x < textstr.length; x++) {
		ch = textstr.charAt(x);
		if (ch == chartosearch) { 
			countchar++; 
		}
	}
	return countchar;
}

function clock(){
	document.forms[0].TimeTicker.value = document.forms[0].TimeTicker.value + 1;
}
	
	var timeelapsed = 1800;
	var minutes="";
	var seconds=1;
	var secondDisplay="";
	var vchange = 0;
	
	function settimeelapsed(change){
		vchange=change;
	}

	function clock2(note){
		if(vchange == 0){
			toMinutes(timeelapsed--);
		}else{
		    timeelapsed=timeelapsed-vchange;
			toMinutes(timeelapsed);		
			vchange=0;
		}
		
		note.TimeTicker2.value = minutes + ":" + secondDisplay;

		if (timeelapsed < 0) {
			note.TimeTicker2.style.color = "red";
			note.TimeTicker2.style.fontWeight = "bold";
		}
		
		setTimeout("clock2(document.forms[0])" , 1000);
	}
	
	function toMinutes(sec){
		minutes=Math.floor(parseFloat(sec)/60);
		seconds=(sec-minutes*60);
		if(seconds == -1)
		{
			seconds=59;
		}
		secondDisplay=seconds;
		if(parseFloat(seconds) < 10)
		{
			secondDisplay="0"+seconds;
		}
	}
	
	function resetTimer(){
		timeelapsed	= 1800;
		minutes="";
		seconds=1;
		secondDisplay="";
		vchange = 0;		
	}	
	
	function printpage() {
		window.print();  
	}
	
	function callScrollCheck(){setInterval("ScrollCheck()",1000)}

	function ScrollCheck(){
		if (navigator.appName == "Microsoft Internet Explorer"){document.forms[0].lastScrollTop.value = document.body.scrollTop;}
		else {document.forms[0].lastScrollTop.value = window.pageYOffset;}
		return true;
	}
	
	function DisableEnableLinks(xHow){
	  objLinks = document.links;
	  for(i=0;i<objLinks.length;i++){
	    objLinks[i].disabled = xHow;
	    //link with onclick
	    if(objLinks[i].onclick && xHow){  
	        objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
	    }
	    //link without onclick
	    else if(xHow){  
	      objLinks[i].onclick = function(){return false;}
	    }
	    //remove return false with link without onclick
	    else if(!xHow && objLinks[i].onclick && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){            
	      objLinks[i].onclick = null;
	    }
	    //remove return false link with onclick
	    else if(!xHow && objLinks[i].onclick && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
	      strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
	      objLinks[i].onclick = new Function(strClick);
	    }
	  }
	}
	
	String.prototype.getFuncBody = function(){ 
	  var str=this.toString(); 
	  str=str.replace(/[^{]+{/,"");
	  str=str.substring(0,str.length-1);   
	  str = str.replace(/\n/gi,"");
	  //if(!str.match(/\(.*\)/gi))str += ")";
	  return str; 
	} 

	function CreateTable(rootnode, makeval, modelval, srcHolder)
	{
		srcHolder.innerHTML = "";		
		/*htmlelement.length = rootnode.childNodes.length;
		for(i = 0; i < rootnode.childNodes.length; i++){
			htmlelement.options[i].text = rootnode.childNodes[i].getElementsByTagName(xmlname)[0].childNodes[0].nodeValue;
			htmlelement.options[i].value = rootnode.childNodes[i].getElementsByTagName(xmlvalue)[0].childNodes[0].nodeValue;
		}*/
				
		for(i=0; i<rootnode.childNodes.length; i++)
		{
			srcTable = document.createElement("table");
			srcTable.className = 'VehicleConfigTable';
			srcHolder.appendChild(srcTable);
			tmpRow = AppendRow(srcTable, 0);
			tmpRow.className = 'TRHeaderVehicleConfig';
			tmpCell = createCellForVehicleConfigTable(tmpRow, 0);
			tmpCell.innerHTML = 'Make : ' + makeval;
			tmpCell = createCellForVehicleConfigTable(tmpRow, 1);
			//tmpCell.innerHTML = 'Model : ' + getNodeTextValue(rootnode, 'MODEL', '');			
			tmpCell.innerHTML = 'Model : ' + rootnode.childNodes[i].getElementsByTagName("MODEL")[0].childNodes[0].nodeValue;		
			tmpCell = createCellForVehicleConfigTable(tmpRow, 2);
			tmpCell.innerHTML = 'Year : ' + rootnode.childNodes[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue;			
			tmpCell = createCellForVehicleConfigTable(tmpRow, 3);
			tmpCell.innerHTML = 'Config : ' + rootnode.childNodes[i].getElementsByTagName("VEHICLECONFIG")[0].childNodes[0].nodeValue;			
			tmpCell = null;
			tmpRow = null;
			
			srcTable = document.createElement("table");
			srcTable.className = 'SeatbeltGuideTable';
			srcHolder.appendChild(srcTable);			
			
			tmpRow = AppendRow(srcTable, 0)
			tmpRow.className = 'TRHeaderSeatbelt';	
			for(j = 0; j < VehicleConfig.length; j++){		
				tmpCell = createCellForSeatbeltTable(tmpRow, j);			
				tmpCell.innerHTML = VehicleConfig[j][0];
			}									
			tmpCell = null;
			tmpRow = null;					
			
			tmpRow = AppendRow(srcTable, 1)
			tmpRow.className = 'TRDataSeatbelt';
			for(j = 0; j < VehicleConfig.length; j++){		
				tmpCell = createCellForSeatbeltTable(tmpRow, j);			
				tmpCell.innerHTML = getNodeTextValue(rootnode, i, VehicleConfig[j][1], '');				
			}									
			tmpCell = null;
			tmpRow = null;			
					
				
			/*tmpRow = AppendRow(srcTable)	
			DataTable = document.createElement("table");		
			tmpRow = null;			
			
			for(j=0; j<colCount; j++)
			{
				tmpCell = AppendCell(tmpRow);
				tmpCell.innerHTML = j;
				tmpCell = null;
			}
			tmpRow = null;*/
		}
	}

	function createCellForVehicleConfigTable(tmpRow, index){
		return createCellWithClassName(tmpRow, 'TDHeaderVehicleConfig', index);
	}
	
	function createCellForSeatbeltTable(tmpRow, index){
		return createCellWithClassName(tmpRow, 'TDSeatbelt', index);
	}	
	
	function createCellWithClassName(tmpRow, classNamePass, index){
		tmpCell = AppendCell(tmpRow, index);
		tmpCell.className = classNamePass;
		return tmpCell;
	}

	function AppendRow(srcTable, index)
	{
		if(srcTable != null)
		{
			return srcTable.insertRow(index);
		}
		else
		{
			alert("Error while creating table. Cause: Container Table is null!");
		}
	}

	function AppendCell(srcRow, index)
	{
		if(srcRow != null)
		{
			return srcRow.insertCell(index);
		}
		else
		{
			alert("Error while creating table. Cause: Container row is null!");
		}
	}
