// JavaScript Document
var preEl ;
var orgBColor;
var orgTColor;
var FORMSENT=false;
var _dynarch_menu_url = "/resources/src/";

//used in the maskedit functions  allowed chars
var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;
var reClipboardChars = /[cvxz]/i;
// global flag
//browser detection
var strUserAgent = navigator.userAgent.toLowerCase(); 
var isIE = strUserAgent.indexOf("msie") > -1; 
var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 
// global request and XML document objects
var req;
var req2;
// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
    if (req2.readyState == 4) {
        // only if "OK"
        if (req2.status == 200) {
 		// Use the XML DOM to unpack the city and state data  
			var xmlDocument = req2.responseXML; 
			var result = xmlDocument.getElementsByTagName('result').item(0).firstChild.data; 
			var msg = xmlDocument.getElementsByTagName('errorText').item(0).firstChild.data; 
      		if (result == "FAILED") {
            	alert(msg);	
			} 
      		if (result == "EXPORT") {
            	window.open("GetFile.po?filename="+msg);	
			} 			
         } else {
            alert("There was a problem retrieving the XML data:\n" + req2.statusText);
         }
    }
}

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDocByPost(url,params) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
		        req.onreadystatechange = processReqChange;
        req.open("POST", url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
        req.send(params);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("POST", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');			
            req.send(params);
        }
    }
}

function exportGrid(table) {
	sendXMLDoc('rpc/ExportGridRPC.po',table);	
	
}


function sendXMLDoc(url,grid) {
	var xml = grid.getXML(); // get ref to XML document object

    // branch for native XMLHttpRequest object
	var n = prompt("Please enter a filename","export");
	var d = new Date(); 	
	url = url + "?time="+d.getTime()+"&fname="+n;
 if (window.XMLHttpRequest) {
        req2 = new XMLHttpRequest();
        req2.open("POST", url, false);
        req2.onreadystatechange = processReqChange;		
		//req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
        req2.send(xml);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
    	try {
            req2 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req2 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                req2 = new XMLHttpRequest();
            }
        }		
        if (req2) {
            req2.open("POST", url, true);
            req2.onreadystatechange = processReqChange;			
			//req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
            req2.send(xml);
        }
    }	
}

function submitForm(value) {
  if(!FORMSENT) value.submit();
}

function markBadFields(fields) {
	for (var i=0; i < fields.length; i++) {
		try {
	    	var field = document.getElementsByName(fields[i]);
			field[0].className  = 'input-text-error';	
		}catch(e){
		}
	}	
}

function submitOnce(){
  if(FORMSENT) return false;
  FORMSENT=true;
  return true;
}

function rightPad(instring,count,pad) {
    var tmp;
    tmp = instring;
    while (tmp.length < count) {
      tmp = tmp+pad;
    }
    return tmp;
  }

function checkValue(instring) {
    var tmp = instring;
    if (instring == "n/a") {
	  tmp = "";
	}
    return tmp;
  }

function HighLightTR(backColor,textColor){
  backColor = '#C8C8C8'; 
  textColor = '#68788F';
  if(typeof(preEl)!='undefined') {
    preEl.bgColor=orgBColor;
    try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
  }
  var el = event.srcElement;
  el = el.parentElement;
  orgBColor = el.bgColor;
  orgTColor = el.style.color;
  el.bgColor=backColor;

  try{ChangeTextColor(el,textColor);}catch(e){;}
  preEl = el;
}

function PreHighLightTR(backColor,textColor,el){
  backColor = '#C8C8C8'; 
  textColor = '#68788F';
  if(typeof(preEl)!='undefined') {
    preEl.bgColor=orgBColor;
    try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
  }
//  var el = event.srcElement;
  orgBColor = el.bgColor;
  orgTColor = el.style.color;
  el.bgColor=backColor;

  try{ChangeTextColor(el,textColor);}catch(e){;}
  preEl = el;
}

function ChangeTextColor(a_obj,a_color){ 
  for (i=0;i<a_obj.cells.length;i++){//put condition before increase!!!!!
    a_obj.cells(i).style.color=a_color;
  }
}

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
win = window.open(mypage, myname, winprops);
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function pausecomp(millis)
{
	date = new Date();
	var curDate = null;
	
	do { var curDate = new Date(); }
	while(curDate-date < millis);
}

function OpenMyProfile()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=410;
	w=706;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('Myprofile.po?event=default','', winprops);
  } else {
    window.showModalDialog('Myprofile.po?event=default','', 'dialogHeight=333px;dialogWidth=706px;status=no;center=yes;');
  }
}


function OpenAddUser()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=425;
	w=556;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminAddUser.po?event=default','', winprops);
  } else {
    window.showModalDialog('AdminAddUser.po?event=default','', 'dialogHeight=312px;dialogWidth=556px;status=no;center=yes;');
//	winprops = 'modal=yes,height='+460px+',width='+556px+',,resizable=no'
//    window.open('AdminAddUser.po?event=default');
  }
}

function OpenAddSignoff(cstid, customerid)
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=425;
	w=556;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminAddSignoff.po?event=default','', winprops);
  } else {
	 window.showModalDialog('AdminAddSignoff.po?event=default&cstid=' + cstid + '&customerid=' + customerid + '&cstnumber=' + cstid + '&customernumber=' + customerid,'', 'dialogHeight=339px;dialogWidth=556px;status=no;center=yes;');
  }
}

function OpenViewSignoff(cstid, customerid, remark)
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=425;
	w=556;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminViewSignoff.po?event=default','', winprops);
  } else {
	 window.showModalDialog('AdminViewSignoff.po?event=default&cstid=' + cstid + '&remark=' + remark + '&customerid=' + customerid + '&cstnumber=' + cstid + '&customernumber=' + customerid,'', 'dialogHeight=312px;dialogWidth=556px;status=no;center=yes;');
  }
}

function OpenCCB(cstid)
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=425;
	w=556;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminCCB.po?event=default&cstid=' + cstid ,'', winprops);
  } else {
	 window.showModalDialog('AdminCCB.po?event=default&cstid=' + cstid ,'', 'dialogHeight=409px;dialogWidth=586px;status=no;center=yes;');
  }
}

function OpenAddCST()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=400;
	w=580;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AddNewCst.po?event=default','', winprops);
  } else {
    window.showModalDialog('AddNewCst.po?event=default','', 'dialogHeight=400px;dialogWidth=580px;status=no;center=yes;');
//	winprops = 'modal=yes,height='+460px+',width='+556px+',,resizable=no'
//    window.open('AdminAddUser.po?event=default');
  }
}

function doAddProductVersion()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=400;
	w=580;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminNewVersion.po?event=default','', winprops);
  } else {
    window.showModalDialog('AdminNewVersion.po?event=default','', 'dialogHeight=400px;dialogWidth=580px;status=no;center=yes;');
  }
}

function OpenStatusLegend()
{
  // Global for browser version branching.
 
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=400;
	w=580;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
	 
    window.open('StatusLegend.po?event=default','', winprops);
  } else {
	   
    window.showModalDialog('StatusLegend.po?event=default','', 'dialogHeight=400px;dialogWidth=580px;status=no;center=yes;');
//	winprops = 'modal=yes,height='+460px+',width='+556px+',,resizable=no'
//    window.open('AdminAddUser.po?event=default');
  }
}

function OpenViewCST(cstid)
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
	h=415;
	w=560;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('ViewCst.po?event=default','', winprops);
  } else {
	window.showModalDialog('ViewCst.po?event=default&cstid=' + cstid,'', 'dialogHeight=505px;dialogWidth=580px;status=no;center=yes;');
  }
}

function OpenAdminCompany()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=170;
	w=558;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminCompany.po?event=default','', winprops);
  } else {
    window.open('AdminCompany.po?event=default');
  }
}

function OpenAddNewDocument()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=300;
	w=590;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AddAddDocument.po?event=default','', winprops);
  } else {
    window.showModalDialog('AdminAddDocument.po?event=default','', 'dialogHeight=300px;dialogWidth=590px;status=no;center=yes;');
  }
}

function OpenEditADocument(docid)
{
   	
	// Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=350;
	w=600;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open("EditADocument.po?docid="+docid,'editdocument','');	
  } else {
    //window.showModalDialog('EditADocument.po?event=default','', 'dialogHeight=270px;dialogWidth=560px;status=no;center=yes;');
	window.showModalDialog('EditADocument.po?event=default&docid='+docid,'editdocument', 'dialogHeight=350px;dialogWidth=600px;status=no;center=yes;');
	}
}
function OpenEditAUser(customerid)
{
   	
	// Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=360;
	w=600;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open("EditAUser.po?customerid="+customerid,'edituser','');	
  } else {
    //window.showModalDialog('EditADocument.po?event=default','', 'dialogHeight=270px;dialogWidth=560px;status=no;center=yes;');
	window.showModalDialog('EditAUser.po?event=default&customerid='+customerid,'editcustomer', 'dialogHeight=360px;dialogWidth=600px;status=no;center=yes;');
	}
}
function OpenAddProduct()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=170;
	w=558;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminAddProduct.po?event=default','', winprops);
  } else {
    window.showModalDialog('AdminAddProduct.po?event=default','', 'dialogHeight=170px;dialogWidth=558px;status=no;center=yes;');
  }
}

function OpenUserEdit(objid)
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=375;
	w=781;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('AdminUsersEdit.po?event=edit&objid=' + objid,'', winprops);
  } else {
    window.showModalDialog('AdminUsersEdit.po?event=edit&objid=' + objid,'', 'dialogHeight=450px;dialogWidth=706px;status=no;center=yes;');
  }
}

function OpenChangePassword()
{
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=277;
	w=408;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('ChangePassword.po?event=default','', winprops);
  } else {
    window.showModalDialog('ChangePassword.po?event=default','', 'dialogHeight=275px;dialogWidth=408px;status=no;center=yes;');
  }
}



function OpenAdminReports(reports)
{
  // Global for browser version branching.
  
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=277;
	w=750;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('ReportParameters.po?event=default&reports=' + reports,'', winprops);
  } else {
    window.showModalDialog('ReportParameters.po?event=default&reports=' + reports,'', 'dialogHeight=275px;dialogWidth=750px;status=no;center=yes;');
  }
}

function OpenReportServer(reportid, reporttype)
{
  // Global for browser version branching.
  
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=277;
	w=750;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
	window.open('ReportServer.po?event=default&reportid=' + reportid + '&reportType=' + reporttype,'', winprops);
  } else {
	window.open('ReportServer.po?event=default&reportid=' + reportid + '&reportType=' + reporttype,'');
  }
}

function OpenCustomerParameters(reportid, reporttype)
{
  // Global for browser version branching.
  
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=250;
	w=760;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('CustomerParameters.po?event=default&reports=' + reportid + '&reportType=' + reporttype,'', winprops);
  } else {
   window.showModalDialog('CustomerParameters.po?event=default&reports=' + reportid + '&reportType=' + reporttype,'', 'dialogHeight=250px;dialogWidth=760px;status=no;center=yes;');
 // window.open('CustomerParameters.po?event=default&reports=' + reportid + '&reportType=' + reporttype,'');
  }
}

function OpenReportsParameter()
{
  // Global for browser version branching.
  
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=277;
	w=750;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('ReportsParameter.po?event=default','', winprops);
  } else {
    window.showModalDialog('ReportsParameter.po?event=default','', 'dialogHeight=275px;dialogWidth=750px;status=no;center=yes;');
  }
}

function SelectProgrammer(programmerid,parentFormIdCtrl,parentFormDisplayCtrl) {
  // Global for browser version branching.
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=375;
	w=781;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('SelectProgrammer.po?event=default&programmerid=' + programmerid+'&parentFormIdCtrl='+parentFormIdCtrl+'&parentFormDisplayCtrl='+parentFormDisplayCtrl,'', winprops);
  } else {
    window.showModalDialog('SelectProgrammer.po?event=default&programmerid=' + programmerid+'&parentFormIdCtrl='+parentFormIdCtrl+'&parentFormDisplayCtrl='+parentFormDisplayCtrl,document.form,'dialogHeight=340px;dialogWidth=456px;status=no;center=yes;');
  }
}

function OpenVaults(objectid, title)
{
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=570;
	w=921;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('VaultDetails.po?event=default&parentobjid=' + objectid + '&title=' + title,document.form, winprops);
  } else {
    window.showModalDialog('VaultDetails.po?event=default&parentobjid=' + objectid + '&title=' + title, document.userform, 'dialogHeight:500px;dialogWidth=956px;status=no;center=yes;');	
  }
}

function OnReports()
{
  var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
  if (Nav4) {
    h=555;
	w=760;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
	winprops = 'modal=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=no'
    window.open('ReportSelection.po?objectiterationid=1', document.form, winprops);
//    window.open('ReportSelection.po?event=default&objectiterationid=' + document.form.objectiterationid, document.form, winprops);	
  } else {
    window.showModalDialog('ReportSelection.po?objectiterationid=1', document.form, 'dialogHeight:555px;dialogWidth=760px;status=no;center=yes;');
  }
}
/*
====================================================================================== */
/* Function to strip leading and trailing spaces from value (similar to Java trim method) */
/*====================================================================================== */
/* Input is string to be trimmed and return value is the result after trimming */

function trim(value) {

  /* Strip leading spaces from input */
  startposn=0;
  while((value.charAt(startposn)==" ")&&(startposn<value.length)) {
    startposn++;
  }
  if(startposn==value.length) {
    value="";
  } else {

    /* If anything left of string after stripping leading spaces strip trailing */
    /* spaces as well */
    value=value.substring(startposn,value.length);
    endposn=(value.length)-1;
    while(value.charAt(endposn)==" ") {
            endposn--;
    }
    value=value.substring(0,endposn+1);
  }
  return(value);
}


// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

			
	
   function isValid(strValue) {
      return reValidString.test(strValue) || 
         strValue.length == 0;
   }

   function checkClipboardCode(objEvent, strKey) {
     if (isNS6)
       return objEvent.ctrlKey &&  
         reClipboardChars.test(strKey);
     else
       return false;
   }

			//mask function
			function maskKeyPress(objEvent) {
				var iKeyCode, strKey;  

				if (isIE) {
				    iKeyCode = window.event.keyCode;
				} else {
				    iKeyCode = window.event.which;
				}
				strKey = String.fromCharCode(iKeyCode);
				
				if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey) && !checkClipboardCode(objEvent, strKey)) {
//					alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
					return false;
				}
			}

   function maskChange(objEvent) {
     var objInput;
            
     if (isIE)
       objInput = objEvent.srcElement; 
     else
       objInput = objEvent.target;
             
     if (!isValid(objInput.value)) {
//       alert("Invalid data");
       objInput.value = objInput.validValue || "";
       objInput.focus();
       objInput.select(); 
     } else {
       objInput.validValue = objInput.value;
     }
   }

   function maskPaste(objEvent) {
     var strPasteData = window.clipboardData.getData("Text");
     var objInput = objEvent.srcElement;
   
     if (!isValid(strPasteData)) {
//       alert("Invalid data");
       objInput.focus();
       return false;
     }
   }



/* Insert/clear message next to form element */
function message(element, classString, errorMessage)
{
	if (element.message != null)
	{
		try
		{
			element.message.className = classString;
			element.message.removeChild(element.message.childNodes[0]);
		}
		catch (error)
		{
		}
	}

	if (errorMessage != null)
	{
		if (element.message == null)
		{
			var messageDiv = document.createElement("div");

			element.message = element.parentNode.insertBefore(messageDiv, element);
			element.message.style.marginLeft = parseInt(element.scrollWidth) + 10 + "px";
		}

		element.message.className = classString;
		element.message.appendChild(document.createTextNode(errorMessage));
	}

	return true;
}

function AddNewIssue(customerid, customername)
{
  showPopWin('AdminIssue.po?event=add&customerid='+customerid+'&customername='+customername, 677, 454, null, false);
}

function EditIssue(issueid,customerid, customername)
{
  showPopWin('AdminIssue.po?event=edit&issueid='+issueid+'&customerid='+customerid+'&customername='+customername, 877, 632, null, false);
}

function SelectCustomer(customerid) {
  showPopWin2('CustomerSelect.po?customerid='+customerid, 422, 339, null, false);
}

function OpenAddNewFile()
{
  showPopWin('AdminAddFile.po?event=default', 550, 166, null, false);
}
function OpenAddNewMiscFile()
{
  showPopWin('AdminAddMiscFile.po?event=default', 550, 166, null, false);
}
