﻿var nav = window.Event ? true : false; 
if (nav) { 
    //window.captureEvents(Event.KEYDOWN); 
    window.onkeydown = NetscapeEventHandler_KeyDown; 
} else { 
    document.onkeydown = MicrosoftEventHandler_KeyDown; 
}

function NetscapeEventHandler_KeyDown(e) { 
    if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit' && e.target.type != 'image'){ 
        return false; 
    } else {
        return true;
    }
} 

function MicrosoftEventHandler_KeyDown() { 
    if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit' && event.srcElement.type != 'image'){ 
        return false;
    } else { 
        return true;
    } 
} 

function ieSecurityWorkAround(){
    // Prevents the message 'Click to activate this control' from displaying
    objects = document.getElementsByTagName("object"); 
    for (var i = 0; i < objects.length; i++) { 
	    objects[i].outerHTML = objects[i].outerHTML; 
    }
}

function addToFavorites(strURL, strTitle){
   if(navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('Opera') < 0){
       window.external.AddFavorite(strURL, strTitle);
   }else{
       document.body.innerHTML += '<'+'a href="'+strURL+'" title="'+strTitle+'" rel="sidebar" style="display: none;" id="addbookmark">click<'+'/a>';
       document.getElementById('addbookmark').click();
       document.getElementById('addbookmark').outerHTML = '';
   }
}

function ToolTip(strText, blnStatus) {
    var intWidth;
    var strStatusBar;
    intWidth = parseInt(strText.length * 5.6) + 20;
    if(intWidth > 240){
        intWidth = 240;
    }
    if(blnStatus == 0){
        strStatusBar = ''; 
    }else{
        strStatusBar = AUTOSTATUS; 
    }
    return overlib(strText,FGCOLOR,'#FFFFFF',BGCOLOR,'#999999',TEXTCOLOR,'#626469',WIDTH,intWidth,strStatusBar,DELAY,100);
}

function Trim(STRING){
    STRING = LTrim(STRING);
    return RTrim(STRING);
}

function RTrim(STRING){
    while(STRING.charAt((STRING.length -1))==" "){
        STRING = STRING.substring(0,STRING.length-1);
    }
return STRING;
}

function LTrim(STRING){
    while(STRING.charAt(0)==" "){
        STRING = STRING.replace(STRING.charAt(0),"");
    }
return STRING;
}

// * * * * dialog window * * * * //
function DialogWindow(strURL, lngImgWidth, lngImgHeight, blnScrollbars) {
	var lngLeftMargin;
	var lngTopMargin;
	var lngScrHeight = screen.height;
	var lngScrWidth = screen.width;
	var lngWinHeight;
	var lngWinWidth;
	var returnValue;
	if(((lngScrWidth-40)/lngImgWidth) <= ((lngScrHeight-55)/lngImgHeight)){
		// Width is leading
		if((lngScrWidth-40) < lngImgWidth){
			//Image width is larger than the screen width, change the image size
			lngImgHeight = Math.round(lngImgHeight*(lngScrWidth - 40)/lngImgWidth);
			lngImgWidth = lngScrWidth - 40;
		}
	}else{
		// Height is leading
		if((lngScrHeight-55) < lngImgHeight){
			//Image height is larger than the screen height, change the image size
			lngImgWidth = Math.round(lngImgWidth*(lngScrHeight - 55)/lngImgHeight);
			lngImgHeight = lngScrHeight - 55;
		}
	}
	lngWinWidth = lngImgWidth + 40;
	if(lngWinWidth < 420){
		lngWinWidth = 420;
	}
	lngWinHeight = lngImgHeight + 100;
	lngLeftMargin = (lngScrWidth - lngWinWidth) / 2;
	lngTopMargin = (lngScrHeight - lngWinHeight) / 2;
	if(!nav){
	    window.showModalDialog(strURL+"&intWidth="+lngImgWidth+"&intHeight="+lngImgHeight, "ValentNet", 
		"dialogWidth:"+lngWinWidth+"px;dialogHeight="+lngWinHeight+"px;dialogLeft:"+lngLeftMargin+"px;dialogTop:"+lngTopMargin+"px;edge:sunken;scroll:"+blnScrollbars+";status:1;help:0;resizable:1");
	}else{
	    window.open(strURL+'&intWidth='+lngImgWidth+'&intHeight='+lngImgHeight, 'ValentNet',
        'height='+lngWinHeight+',width='+lngWinWidth+',toolbar=no,directories=no,status=yes,menubar=no,scrollbars='+blnScrollbars+',resizable=yes ,modal=yes,left='+lngLeftMargin+',top='+lngTopMargin);
	}
}
// * * * * popup window * * * * //
function PopupWindow(strURL, lngImgWidth, lngImgHeight, blnScrollbars) {
	var lngWinWidth, lngWinHeight, lngLeftMargin, lngTopMargin;
	var lngScrWidth = screen.width;
	var lngScrHeight = screen.height;
	if(((lngScrWidth-40)/lngImgWidth) <= ((lngScrHeight-55)/lngImgHeight)){
		// Width is leading
		if((lngScrWidth-40) < lngImgWidth){
			//Image width is larger than the screen width, change the image size
			lngImgHeight = Math.round(lngImgHeight*(lngScrWidth - 40)/lngImgWidth);
			lngImgWidth = lngScrWidth - 40;
		}
	}else{
		// Height is leading
		if((lngScrHeight-55) < lngImgHeight){
			//Image height is larger than the screen height, change the image size
			lngImgWidth = Math.round(lngImgWidth*(lngScrHeight - 55)/lngImgHeight);
			lngImgHeight = lngScrHeight - 55;
		}
	}
	lngWinWidth = lngImgWidth + 40;
	if(lngWinWidth < 200){
		lngWinWidth = 200;
	}
	lngWinHeight = lngImgHeight + 55;
	lngLeftMargin = (lngScrWidth - lngWinWidth) / 2;
	lngTopMargin = (lngScrHeight - lngWinHeight) / 2;
	myWin= open(strURL+"&intWidth="+lngImgWidth+"&intHeight="+lngImgHeight, "ValentNet", 
		"width="+lngWinWidth+",height="+lngWinHeight+",status=no,toolbar=no,menubar=no,resizable=no,scrollbars="+blnScrollbars+",left="+lngLeftMargin+",top="+lngTopMargin);
	myWin.focus();
}

// * * * * Window Resize * * * * //
function setWinSize(intHeight, intWidth){
    if(window.outerWidth){
        window.outerWidth = intWidth;
        window.outerHeight = intHeight;
    } else if(window.resizeTo){
        window.resizeTo(intWidth,intHeight);
    }
}

// * * * * AJAX * * * * //
// * AJAX version 1 *//
var id;
var obj;
function getResponse(strUrl, strFunction, strID){
    obj = GetXmlHttpObject();
    if(obj!=null){
        if(strID != undefined && strID != null){
            if(strID.length > 0){
                id = strID;    
            }
        }
        obj.onreadystatechange = strFunction;
        obj.open("GET", strUrl+'&'+Math.random(),  true);
        obj.send(null);
    }else{
        alert('No AJAX-support!/nPlease use FireFox or Internet Explorer.');
    }
}
function GetXmlHttpObject(){ 
    var objXMLHttp = null;
    if (window.XMLHttpRequest){
        objXMLHttp=new XMLHttpRequest();
    }else if (window.ActiveXObject){
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}
// * AJAX version 2 *//
var fAJAXResponse;
var objAJAX;

function getAJAXResponse(strURL)
{
    objAJAX = GetXmlHttpObject();
    if(objAJAX!=null)
    {
        objAJAX.onreadystatechange = showAJAXResponse;
        objAJAX.open("GET", strURL+'&'+Math.random(),  true);
        objAJAX.send(null);
    }else{
        alert('No AJAX-support!/nPlease use FireFox or Internet Explorer.');
    }
}
function showAJAXResponse()
{
    if(objAJAX.readyState == 4)
    {        
        if(objAJAX.status == 200)
        {
            fAJAXResponse();
        }
    }
}

// * * * * alerts * * * * //
function ValentNetAlert(strText,strFunction){
    var intHeight;
    var intWidth;
    var strPre;
    var strPost;
    
    if (nav) { 
      intWidth = window.innerWidth;
      intHeight = window.innerHeight;
    }else{
      intWidth = document.body.offsetWidth;
      intHeight = document.body.offsetHeight;
    }
    
    strPre = '<div class="alert"><table class="alert"><tr><td class="alertText">';
    strPost = '</td></tr>';
    strPost += '<tr class="alertFooter"><td colspan="2" style="text-align:center;">';
    strPost += '<input type="button" id="cmdAlertOk" class="button" style="width:80px;" value="Ok" onclick="javascript:cClick();'+strFunction+';">';
    strPost += '</td></tr>';
    strPost += '</table></div>';


    return overlib(strPre + strText + strPost,FULLHTML,STICKY,RELX,(intWidth/2)-160,RELY,(intHeight/2)-200);
}

function ValentNetAlertAuto(strText,strFunction){

    ValentNetAlertTimeout(strText, strFunction, 5);
    
}

function ValentNetAlertTimeout(strText, strFunction, intSeconds){
    var intMilliseconds = intSeconds * 1000;
    
    setTimeout("cClick();" + strFunction + ";",intMilliseconds);

    ValentNetAlert(strText,strFunction);   
    
}

function ValentNetConfirm(strText,strFunctionOk,strFunctionCancel, strOk, strCancel){
    var intHeight;
    var intWidth;
    var strPre;
    var strPost;
    
    if (nav) { 
      intWidth = window.innerWidth;
      intHeight = window.innerHeight;
    }else{
      intWidth = document.body.offsetWidth;
      intHeight = document.body.offsetHeight;
    }
    
    strPre = '<div class="alert"><table class="alert"><tr><td class="alertText">';
    strPost = '</td></tr>';
    strPost += '<tr class="alertFooter"><td colspan="2" style="text-align:center;">';
    strPost += '<input type="button" id="cmdAlertOk" class="button" style="width:80px;" value="'+strOk+'" onclick="javascript:cClick();'+strFunctionOk+';">';
    strPost += ' <input type="button" id="cmdAlertCancel" class="button" style="width:80px;" value="'+strCancel+'" onclick="javascript:cClick();'+strFunctionCancel+';">';
    strPost += '</td></tr>';
    strPost += '</table></div>';

    return overlib(strPre + strText + strPost,FULLHTML,STICKY,RELX,(intWidth/2)-160,RELY,(intHeight/2)-200);
}

// * * * * DTPicker *  * * * //
function clearPicker(strBase, blnTime)
{
    document.getElementById(strBase + 'txtDisplayDate').value = '';
    if(blnTime == true){
        document.getElementById(strBase + 'cboHours_cbo1').selectedIndex = 0;
        document.getElementById(strBase + 'cboMinutes_cbo1').selectedIndex = 0;
    }
    closePicker(strBase);
    document.getElementById(strBase + 'txtDisplayDate').focus();
}

function closePicker(strBase){
    document.getElementById(strBase + 'pnlPicker').style.display = 'none';
}

function getPickerDateSelected(strBase){
    return document.getElementById(strBase + 'txtDisplayDate').value;
}

function getPickerResponse(strBase, strLanguage, strBaseDate, strSelDate){
    
    fAJAXResponse = new Function('showPicker(\'' + strBase + '\',\'' + strLanguage + '\');');
        
    getAJAXResponse('/controls/DateTime/DTPickerCallbacks.aspx?lan=' + strLanguage + '&dtm=' + strBaseDate + '&dtmSel=' + strSelDate);
}

function loadPicker(strBase, strLanguage)
{
    var oDivs = document.getElementsByTagName('div');
    var strDate = getPickerDateSelected(strBase);
    var n;    
    
    // Close any other calendar popups
    for(n = 0; n < oDivs.length; n++){
        if(oDivs[n].id != null){
            if(oDivs[n].id.indexOf('pnlPicker') > 0){
                if(oDivs[n].id.indexOf(strBase) < 0){
                    oDivs[n].style.display = 'none';
                }
            }
        }
    }
    
    getPickerResponse(strBase, strLanguage, strDate, strDate);
}

function navigatePicker(strBase, strLanguage, strBaseDate){
    var strDateSelected = getPickerDateSelected(strBase);
    
    getPickerResponse(strBase, strLanguage, strBaseDate, strDateSelected);
}

function setPickerDate(strBase, strDate){
    document.getElementById(strBase + 'txtDisplayDate').value = strDate;
    document.getElementById(strBase + 'pnlPicker').style.display = 'none';
    document.getElementById(strBase + 'txtDisplayDate').focus();
}

function showPicker(strBase, strLanguage)
{   
//    alert(objAJAX.responseText);
    var intCss = 7;
    var intDay = 3;
    var intDisplay = 0;
    var intMainButtons = 5;
    var intMainDates = 0;
    var intMainMonth = 2;
    var intMainWeek = 3;
    var intMainWeekDays = 4;
    var intMainYear = 1;
    var intMonth = 4;
    var intMonthName = 5;
    var intYear = 6;
    var intWeek = 1;
    var intWeekday = 2;
    var n;
    var oButton;
    var oButtons;
    var oDate;
    var oDates;
    var oPicker = document.getElementById(strBase + 'pnlPicker');
    var oWeekDays;
    var strMonth;
    var strResult = '';
    var strWeek;
    var strYear;
    var tbCal = document.getElementById(strBase + 'tbCalendar');
    var td;
    var tr;
    var x = 0;
    var xmlDates = LoadXMLText(objAJAX.responseText);
    var y = 0;
    
    for(n = tbCal.rows.length - 1; n > 3; n--){
        tbCal.deleteRow(n);
    }
    //alert(xmlDates.childNodes[0].childNodes.length);
    oButtons = xmlDates.childNodes[0].childNodes[intMainButtons].childNodes;
    oDates = xmlDates.childNodes[0].childNodes[intMainDates].childNodes;
    oWeekDays = xmlDates.childNodes[0].childNodes[intMainWeekDays].childNodes;
    strYear = xmlDates.childNodes[0].childNodes[intMainYear].childNodes[0].nodeValue;
    strMonth = xmlDates.childNodes[0].childNodes[intMainMonth].childNodes[0].nodeValue;
    strWeek = xmlDates.childNodes[0].childNodes[intMainWeek].childNodes[0].nodeValue;
    
    //Years
    // -1
    td = tbCal.rows[1].cells[0]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[0].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[0].childNodes[0].childNodes[0].nodeValue
    // -10
    td = tbCal.rows[1].cells[1]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[1].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[1].childNodes[0].childNodes[0].nodeValue
    // current year
    tbCal.rows[1].cells[2].innerHTML = strYear;
    // +1
    td = tbCal.rows[1].cells[3]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[3].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[3].childNodes[0].childNodes[0].nodeValue
    // +10
    td = tbCal.rows[1].cells[4]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[2].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[2].childNodes[0].childNodes[0].nodeValue
    
    //Months
    // -1
    td = tbCal.rows[2].cells[0]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[4].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[4].childNodes[0].childNodes[0].nodeValue
    // current month
    tbCal.rows[2].cells[1].innerHTML = strMonth;
    // +1
    td = tbCal.rows[2].cells[2]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[5].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[5].childNodes[0].childNodes[0].nodeValue
    
    for(n = 0; n < 7; n++){
        tbCal.rows[3].cells[n + 1].innerHTML = oWeekDays[n].childNodes[0].nodeValue.substring(0,1);
        tbCal.rows[3].cells[n + 1].title = oWeekDays[n].childNodes[0].nodeValue;
    }
    
    for(n = 0; n < oDates.length; n++){
        oDate = oDates[n];
        if(oDate.childNodes[intWeekday].childNodes[0].nodeValue == '1'){
            tbCal.insertRow(tbCal.rows.length);
            tr = tbCal.rows[tbCal.rows.length - 1];
            tr.insertCell(tr.cells.length);
            td = tr.cells[tr.cells.length - 1];
            td.className = 'DPWeekNr';
            td.innerHTML = oDate.childNodes[intWeek].childNodes[0].nodeValue;
            td.title = strWeek + ' ' + oDate.childNodes[intWeek].childNodes[0].nodeValue;
        }
        tr.insertCell(tr.cells.length);
        td = tr.cells[tr.cells.length - 1];
        td.className = oDate.childNodes[intCss].childNodes[0].nodeValue;
        td.innerHTML = oDate.childNodes[intDay].childNodes[0].nodeValue;
        td.onclick = new Function('setPickerDate(\'' + strBase + '\', \'' + oDate.childNodes[intDisplay].childNodes[0].nodeValue + '\');');
        td.title = oWeekDays[parseInt(oDate.childNodes[intWeekday].childNodes[0].nodeValue) - 1].childNodes[0].nodeValue + ' ' + oDate.childNodes[intDay].childNodes[0].nodeValue + ' ' + oDate.childNodes[intMonthName].childNodes[0].nodeValue + ' ' + oDate.childNodes[intYear].childNodes[0].nodeValue;
    }
    x = Sys.UI.DomElement.getLocation(document.getElementById(strBase + 'txtDisplayDate')).x;
    y = Sys.UI.DomElement.getLocation(document.getElementById(strBase + 'txtDisplayDate')).y;
    
    Sys.UI.DomElement.setLocation(oPicker, x, y + 20);
    oPicker.style.display = 'block';
}

// * * * * Menu Tree * * * * //
function MT_AppendChilds(id, pid, mt, cmdID)
{
    var intID = 0;
    var intName = 1;
    var intTimer;
    var intURL = 2;
    var intChilds = 3;
    var t;
    var tbId;
    var n;
    var xmlItem;
    var xmlMenu = LoadXMLText(objAJAX.responseText);
    
    tbId = cmdID.replace('cmd' + pid, 'tb' + pid);
    
    for(n = 0; n < xmlMenu.childNodes[0].childNodes.length; n++)
    {
        intTimer = (n + 1) * 25;
        //MT_AppendItem(id, mt, tbId, xmlMenu.childNodes[0].childNodes[n].childNodes[intID].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intName].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intURL].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intChilds].childNodes[0].nodeValue);
        xmlItem = xmlMenu.childNodes[0].childNodes[n];
        setTimeout("MT_AppendItem('" + id + "', '" + mt + "', '" + tbId + "', '" + xmlItem.childNodes[intID].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intName].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intURL].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intChilds].childNodes[0].nodeValue + "')", intTimer);
    }
    
    document.getElementById(cmdID).src = '/icons/darkArrowDown.gif';
}

function MT_AppendItem(id, mt, tbId, intMenuID, strName, strURL, intHasChilds)
{
    var img;
    var tb;
    var tbParent;
    var td;
    var tr;
    
    tbParent = document.getElementById(tbId);
    tbParent.insertRow(tbParent.rows.length);
    tr = tbParent.rows[tbParent.rows.length - 1];
    
    tr.insertCell(tr.cells.length);
    td = tr.cells[tr.cells.length - 1];
    td.innerHTML = '<img src=\'/icons/empty.gif\' />';
    
    tr.insertCell(tr.cells.length);
    td = tr.cells[tr.cells.length - 1];
    td.innerHTML = '<table id=\'tb' + intMenuID + '\' class=\'mainMenu\'></table>';
    
    tb = document.getElementById('tb' + intMenuID);
    tb.insertRow(tb.rows.length);
    tr = tb.rows[tb.rows.length - 1];
    
    tr.insertCell(tr.cells.length);
    td = tr.cells[tr.cells.length - 1];
    if(intHasChilds == '0')
    {
        td.innerHTML = '<img src=\'/icons/empty.gif\' />';
    }
    else
    {
        td.innerHTML = '<img id=\'cmd' + intMenuID + '\' src=\'/icons/darkArrowRight.gif\' />';
        img = document.getElementById('cmd' + intMenuID);
        img.id = 'cmd' + intMenuID;
        img.onclick = new Function('MT_ToggleChilds(\'' + id + '\', \'' + intMenuID + '\', \'' + mt + '\', this.id);');
        img.style.cursor = 'pointer';
    }
    
    tr.insertCell(tr.cells.length);
    td = tr.cells[tr.cells.length - 1];    
    td.innerHTML = '<a href=\'' + strURL + '?ID=' + intMenuID + '\' target=\'_self\' class=\'mainMenu\'>' + strName + '</a>';
}

function MT_GetChilds(id, pid, mt, cmdID)
{    
    fAJAXResponse = new Function('MT_AppendChilds(\'' + id + '\', \'' + pid + '\', \'' + mt + '\', \'' + cmdID + '\');');
        
    getAJAXResponse('/controls/MenuTree/MenuTreeCallbacks.aspx?ID=' + id + '&pID=' + pid + '&mt=' + mt);
}

function MT_HideChilds(tb, cmdID){
    var intTimer;
    var n;
    
    for(n = tb.rows.length - 1; n > 0; n--)
    {
        intTimer = (n + 1) * 10;
        setTimeout("document.getElementById('" + tb.id + "').rows[" + n + "].style.display = 'none'", intTimer);
    }
    document.getElementById(cmdID).src = '/icons/darkArrowRight.gif';
}

function MT_ShowChilds(tb, cmdID){
    var intTimer;
    var n;
    
    for(n = 1; n < tb.rows.length; n++)
    {
        intTimer = (n + 1) * 25;
        setTimeout("document.getElementById('" + tb.id + "').rows[" + n + "].style.display = ''", intTimer);
    }
    document.getElementById(cmdID).src = '/icons/darkArrowDown.gif';
}

function MT_ToggleChilds(id, pid, mt, cmdID)
{
    var tb;

    tb = document.getElementById(cmdID.replace('cmd' + pid, 'tb' + pid));
    if(tb.rows.length > 1){
        if(tb.rows[1].style.display == 'none')
        {
            MT_ShowChilds(tb, cmdID);
        }
        else
        {
            MT_HideChilds(tb, cmdID);
        }
    }
    else
    {
        MT_GetChilds(id, pid, mt, cmdID);
    }
}

// * * * * Email Validation * * * * //
function CheckEmail(strUrl, strFunction, id)
{
    if (id != null && id != '')
    {
        //alert(o);
        var value = document.getElementById(id).value;
        // alert(value);
        var strImgId = id.replace('txt1', 'imgStatus');
        //alert(strImgId);
        
	    imgStatus = document.getElementById(strImgId);
    	    
	    if (value==''){
	        imgStatus.src='/icons/cancel.gif';
	        return
	    }
    	    
	    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    	
	    if (filter.test(value)){
    	
	        // disable the textbox
	        document.getElementById(id).disabled = true;
    	    
	        var strHdnId = id.replace('txt1', 'hdnEmailCheckStatus');
	        hdnStatus = document.getElementById(strHdnId);
	        hdnStatus.value='0';

            imgStatus.src='/icons/loading.gif';
            //alert(strUrl);   
	        getResponse(strUrl, strFunction, id);   
	        //alert('called');          
       
        }
	    else{
    	
	        imgStatus.src='/icons/cancel.gif';
	        return    
	    }
	 }
}

// * * * * Printing * * * * //
function printSpecial(blnAuto)
{
	if (document.getElementById != null){
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null){
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0){
				html += headTags[0].innerHTML;
			}
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null){
				html += printReadyElem.innerHTML;
		}else{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (blnAuto){
			printWin.print();
		}
	}else{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

// * * * * Validation * * * * //
var Page_Validators_Copy;
function addValidator(id){
    var n;
    for(n=0; n < Page_Validators_Copy.length; n++){
        if(Page_Validators_Copy[n].id.indexOf(id) >= 0){
            Page_Validators.push(Page_Validators_Copy[n]);
        }
    }
}

function disableFileUpload(){
    //alert('dis');
    var arrInput = document.getElementsByTagName('input');
    var n = 0;
    for(n = 0; n < arrInput.length; n++){
        //alert(arrInput[n].id);
        if(arrInput[n].type == 'file'){
            arrInput[n].disabled = true;
        }
    }
}

// * * * * XML * * * * //
function LoadXMLText(strText){
    var xmlDoc;

    if (window.ActiveXObject){
        // code for IE
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(strText);
    }else if (document.implementation && document.implementation.createDocument){
        // code for Mozilla, Firefox, Opera, etc.
        var parser = new DOMParser();
        //xmlDoc.async = false;
        xmlDoc = parser.parseFromString(strText,"text/xml");
    }else{
        alert('Your browser cannot handle this script');
    }
    
    return(xmlDoc);
}

function FillFormByXML(oXML){
    var n;
    var oField;
    var oNode;
    
    if(oXML){
        if(oXML.firstChild.childNodes.length > 0){
            for(n = 0; n < oXML.firstChild.childNodes.length; n++){
                oNode= oXML.firstChild.childNodes[n];
                oField = document.getElementById(oNode.childNodes[0].firstChild.nodeValue);
                if(oField.type.toLowerCase() == 'radio'){
                    if(oNode.childNodes[1].childNodes.length > 0){;
                        if(oNode.childNodes[1].firstChild.nodeValue == '1'){
                            oField.checked = true;
                            document.getElementById(oNode.childNodes[0].firstChild.nodeValue.replace('Yes', 'No')).checked = false;
                        }else{
                            oField.checked = false;
                            document.getElementById(oNode.childNodes[0].firstChild.nodeValue.replace('Yes', 'No')).checked = true;
                        }
                    }
                }else{
                    if(oNode.childNodes[1].childNodes.length > 0){;
                        oField.value = oNode.childNodes[1].firstChild.nodeValue;
                    }else{
                        oField.value = '';
                    }
                }
            }
        }
    }
}

function ClearList(listID){
    var lb;
    var n;
    
    lb = document.getElementById(listID);
    
    for(n = lb.options.length - 1; n > -1; n--){
		lb.options[n] = null;
	}
}

function FillListByXML(listID, oXML){
    var lb;
    var li;
    var n;
    var oNode;
    
    if(oXML){
        if(oXML.firstChild.childNodes.length > 0){
            
            lb = document.getElementById(listID);
            
            for(n = 0; n < oXML.firstChild.childNodes.length; n++){
		        oNode = oXML.firstChild.childNodes[n];
		        li = new Option(oNode.childNodes[1].firstChild.nodeValue, oNode.childNodes[0].firstChild.nodeValue, false, false);
		        lb.options[lb.length] = li;
            }
        }
    }
}

function GetWindowHeight()
{
    if (nav){ 
        return window.innerHeight;
    }else{
    }
}

// * * * * MaxLangth function for textarea * * * * //
function ismaxlength(obj){
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
    if(obj.getAttribute && obj.value.length>mlength){
        obj.value = obj.value.substring(0,mlength);
    }
}