function subscribe(ofn,tty,tid) {
    ajaxcall(8, tty, tid, ofn,0);
}

function togglewallsel(ajaxid,ctrl,ttid)
{
    var ofn = 'of_' + ajaxid;
    if (ctrl.checked)
        ajaxcall(ajaxid,'tton',ttid,ofn,1);
    else
        ajaxcall(ajaxid,'ttoff',ttid,ofn,1);
}
function getwall(ajaxid,p1)
{
}
function SwitchComm(ToComm)
{
	document.Form1.txtSwitchComm.value = ToComm;
	document.Form1.submit();
}
function NextStep()
{
	document.Form1.wa1_sGotoStep.value = document.Form1.wa1_sNextStep.value;
	document.Form1.wa1_sAction.value = 'N';
	document.Form1.submit();
}
function PrevStep()
{
	document.Form1.wa1_sGotoStep.value = document.Form1.wa1_sPrevStep.value;
	document.Form1.wa1_sAction.value = 'P';
	document.Form1.submit();
}
function CancelStep()
{
	document.Form1.wa1_sThisStep.value = '0';
	document.Form1.wa1_sGotoStep.value = '0';
	document.Form1.wa1_sAction.value = 'C';
	document.Form1.submit();
}
//function SetSortCol(sTemplate,iColNo)
//{
//	document.Form1.SortTemplate.value = sTemplate;
//	document.Form1.SortColNo.value = iColNo;
//	document.Form1.submit();
//}
function SetSortSpec(sTemplate,sSortSpec)
{
	document.Form1.SortTemplate.value = sTemplate;
	document.Form1.SortColNo.value = sSortSpec;
    document.getElementById('btnExecSort').click();
}
function saveformdata()
{
    document.getElementById('btnSaveFormData').click();
}
function togglediv(div1)
{
    if (document.getElementById(div1).style.display == 'block')
       document.getElementById(div1).style.display = 'none';
    else
       document.getElementById(div1).style.display = 'block';
 }
// view notification
function vnote(nid)
{
	window.open('notifications.aspx?mode=10&nid='+nid,'','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1');
}
function ButtonWait(fld)
{
	var ofld = eval("document.Form1."+fld);
	ofld.value = 'Please wait...';
	ofld.disabled = true;
//	document.Form1.submit();
//	return true;
}

function vibmi(fid,iid)
{
	var fld = eval("document.Form1.all."+fid);
	if (fld.src.indexOf('-pw.jpg') >= 0) return false;
	fld.src = 'usercontrols/images/vib-' + iid + '-mi.jpg';
}
function vibmo(fid,iid)
{
	var fld = eval("document.Form1.all."+fid);
	if (fld.src.indexOf('-pw.jpg') >= 0) return false;
	fld.src = 'usercontrols/images/vib-' + iid + '-mo.jpg';
}
function vibpw(fid)
{
	var fld = eval("document.Form1.all."+fid);
	fld.src = "usercontrols/images/vib-pw.jpg";
}
function PreloadImages()
{
	alert('preloading');
}
function SetEvent(eid,iPost)
{
	document.getElementById('EventID').value = eid;
//	document.Form1.all.EventID.value = eid;
	if (iPost == 1) document.Form1.submit();
	return true;
}
function infopopup(sMode,sItem)
{
	window.open('info.aspx?mode='+sMode+'&item='+encodeURI(sItem),'','toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=50,top=50,width=400,height=450');
}
function downloadpopup(sMode,sSessKey)
{
	window.open('downloadpopup.aspx?mode='+sMode+'&ttsk='+sSessKey,'','toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=50,top=50,width=400,height=450');
}
function editformpopup(fmid) {
    window.open('forms.aspx?fmid='+fmid, '', 'toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1');
}
function helpmovie(sID)
{
	window.open('https://www.viiscrm.net/helpmovie.aspx?id='+sID,'','toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=0,top=0');
}
function helper(tagtype,tag1,tag2,tag3)
{
	window.open('help2.aspx?et='+tagtype+'&t1='+tag1+'&t2='+tag2+'&t3='+tag3,'','toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=20,top=20,width=950,height=650');
}
function findertrigger(sHTMLFieldID,iRowNo,iColNo)
{
    if (window.showModalDialog)
	{
		var opener = window.dialogArguments;
		opener.document.getElementById(sHTMLFieldID).value = document.getElementById('r'+iRowNo+'_'+iColNo).value;
	}
	else
	{
		window.opener.document.getElementById(sHTMLFieldID).value = document.getElementById('r'+iRowNo+'_'+iColNo).value;
	}
}
function finderclick(sHTMLFieldIDList,iRowNo,sPostBack,sFromUserControl,sNameFormat,iCodeColNo,iNameColNo)
{

    var sHTMLFieldID;

    iCodeColNo = iCodeColNo - 1;

    //SR2607 - ShowModalDialog and dialogArguments is only properly supported in IE.  Upon refresh of the child the dialogarguments are lost in other browsers.
	if (window.showModalDialog && window.navigator.appName == 'Microsoft Internet Explorer')
	{
		var opener = window.dialogArguments;
        var arrFieldID = sHTMLFieldIDList.split(";");
        for (var f0 = 0; f0 < arrFieldID.length; f0++)
        {
            sHTMLFieldID = arrFieldID[f0];
            iCodeColNo = iCodeColNo + 1;

            var setfld = opener.document.getElementById(sHTMLFieldID)
            if (setfld == null) {
                alert('No such HTML field: '+sHTMLFieldID)
            }
            else {
                setfld.value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value;
                if (sNameFormat == 'LCO1' || arrFieldID.length > 1) {
                    // Copy code
                    opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value;
                }
                if (sNameFormat == 'LDO1') {
                    // Copy name
                    opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iNameColNo).value;
                }
                if (sNameFormat == 'LCD1') {
                    // Copy code and name
                    opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value + ' - ' + document.getElementById('r' + iRowNo + '_' + iNameColNo).value;
                }
            }
        }

        sHTMLFieldID = arrFieldID[0];

		if (sPostBack == '1')
		{

		    var fld = opener.document.getElementById('ChangesMade')
		    if (fld != null) {
		        fld.value = '0';
		    }

		    if (sFromUserControl == '1')
		        opener.document.getElementById(sHTMLFieldID+'_FinderChange').click();
		    else 
  		    {
    			opener.document.getElementById('txtCustomPostBack').value = sHTMLFieldID;
		        opener.document.getElementById('btnCustomPostBack').click();
		    } 
		 }
		window.close();
	}
	else
	{
        var arrFieldID = sHTMLFieldIDList.split(";");
        for (var f0 = 0; f0 < arrFieldID.length; f0++)
        {
            sHTMLFieldID = arrFieldID[f0];
            iCodeColNo = iCodeColNo + 1;

            var setfld = window.opener.document.getElementById(sHTMLFieldID)
            if (setfld == null) {
                alert('No such HTML field: ' + sHTMLFieldID)
            }
            else {
                setfld.value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value;
                if (sNameFormat == 'LCO1' || arrFieldID.length > 1) {
                    // Copy code
                    window.opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value;
                }
                if (sNameFormat == 'LDO1') {
                    // Copy name
                    window.opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iNameColNo).value;
                }
                if (sNameFormat == 'LCD1') {
                    // Copy code and name
                    window.opener.document.getElementById(sHTMLFieldID + ':Name').value = document.getElementById('r' + iRowNo + '_' + iCodeColNo).value + ' - ' + document.getElementById('r' + iRowNo + '_' + iNameColNo).value;
                }
            }
        }

        sHTMLFieldID = arrFieldID[0];

        if (sPostBack == '1')
		{
		    if (sFromUserControl == '1')
		    {
    		      window.opener.document.getElementById(sHTMLFieldID+'_FCEX').value = 'Y';
    		      window.opener.document.forms[0].submit();
//    		      window.opener.document.getElementById(sHTMLFieldID+'_FinderChange').click();
		     }
		    else 
		    {
    			window.opener.document.getElementById('txtCustomPostBack').value = sHTMLFieldID;
		        window.opener.document.getElementById('btnCustomPostBack').click();
		    } 
		}
		window.close();
	}

}

function ifaction(ttype,fieldid,fname,action,defaultstr)
{
    var fvalue = document.getElementById(fname).value;
	var sURL = "enquiry1.aspx?tty="+ttype;
	if (fvalue == '')
	{
	    if (defaultstr == '')
	        sURL = sURL+"&fld"+ttype+'.'+fieldid+"="+encodeURI(fvalue)+"&ssrd=1";
        else
        	sURL = sURL+"&"+defaultstr+"&ssrd=1";
	}
	else
	{
	    sURL = sURL+"&fld"+ttype+'.'+fieldid+"="+encodeURI(fvalue)+"&ssrd=1";
	}
	top.location.href = sURL;
}

function listclick(sHTMLFieldID)
{
    document.getElementById('txtCustomPostBack').value = sHTMLFieldID;
    document.getElementById('btnCustomPostBack').click();
}

function disabledreport()
{
    alert("We're sorry - this report is not currently available")
} 


function getreport(sName,sValue)
{
    document.getElementById('rptParamName').value = sName;
    document.getElementById('rptParamValue').value = sValue;
    document.getElementById('btnGetReport2').click();
}

function getreport2(ctl,direction)
{
    var fld = document.getElementById(ctl)
    var oldidx = fld.selectedIndex;
    if (fld.length != 0)
    {
        var newidx;
        if (direction == 'N')
        {
            newidx = fld.selectedIndex + 1;
            if (newidx > (fld.length-1)) newidx = 0;
         }
         else
         {
            newidx = fld.selectedIndex - 1;
            if (newidx < 0) newidx = fld.length-1;
         }
        fld.selectedIndex = newidx;
        document.getElementById('btnGetReport2').click();
    }
}

function startfinder(sFieldname,sFieldID,sOtherFieldnames,sOtherFieldIDs,sHeight,sWidth)
{

	var sURL = "finderpopup.aspx?hffn="+sFieldname+"&hfid="+sFieldID+"&hfvc="+encodeURI(document.getElementById(sFieldname).value)+"&hfvn="+encodeURI(document.getElementById(sFieldname+':Name').value)

	if (sOtherFieldnames != '')
	{
        var arrfldid = sOtherFieldIDs.split(";");
        var arrfldnm = sOtherFieldnames.split(";");
        for (var i0 = 0; i0 < arrfldid.length; i0++)
        {
            var fldid = arrfldid[i0];
            var fldnm = arrfldnm[i0];
            var ofld = document.getElementById(fldnm);
            if (ofld != null)
            {
                sURL = sURL + '&fld' + fldid + '=' + encodeURI(ofld.value);
            }
        }
    }
	
	if (window.showModalDialog)
	{
		window.showModalDialog(sURL, self, "dialogHeight:"+sHeight+"px;dialogWidth:"+sWidth+"px;help:no;status:no");
	}
	else
	{
		window.top.captureEvents(Event.CLICK|Event.FOCUS);
		window.top.onclick=IgnoreEvents;
		window.top.onfocus=HandleFocus;
		winModalWindow = window.open(sURL,"ModalChild","dependent=yes,width="+sWidth+",height="+sHeight);
		winModalWindow.opener = self;
		winModalWindow.focus();
	}
}

var winModalWindow

function IgnoreEvents(e)
{
	return false
}

function HandleFocus()
{
	if (winModalWindow)
	{
		if (!winModalWindow.closed)
		{
			winModalWindow.focus()
		}
		else
		{
			window.top.releaseEvents(Event.CLICK|Event.FOCUS)
			window.top.onclick="";
		}
	}
	
	return false
}

function slideshow(i)
{
    var url = "slideshow.aspx?csi="+i
    window.open(url,'_blank','menubar=0,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resizable=1,top=0,left=0,width=842,height=651');
  } 

function previewreport()
{
    var url = "reports.aspx?mode=14";
    win1 = window.open(url,'_blank','menubar=0,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resizable=1');
    win1.focus(); 
} 
function viewreport1(mid,rid,fid,tty,tid)
{
    var url = "reports.aspx?mode=4&mid="+mid+"&rid="+rid+"&fid="+fid+"&tty="+tty+"&tid="+tid+"&prmTransactionID="+tid;
    win1 = window.open(url,'_blank','menubar=1,toolbar=1,location=0,directories=0,status=1,scrollbars=1,resizable=1');
    win1.focus(); 
}
function metadatabrowser(sMode)
{
    var url = "metadatabrowser.aspx?mode="+sMode
    win1 = window.open(url,'_metadatabrowser','menubar=0,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resizable=1');
    win1.focus(); 
} 

function fullscreenrep(marketid,reportid)
{
    var url = "reports.aspx?mode=1&mid="+marketid+"&fs=1&rid="+reportid
//    window.open(url,'_blank','left=0,top=0, height=540,width=780,scrollbars=yes,fullscreen=yes');
   win3 = window.open(url,'_fsreport','scrollbars=yes,fullscreen=yes');
   win3.focus();  
} 

function search()
{
	var sURL = "search.aspx?s="+encodeURI(document.getElementById('txtBannerSearch').value);
	top.location.href = sURL;
//	window.open(sURL,'search','toolbar=1,location=1,directories=0,status=0,scrollbars=1,resizable=1');
	return false;
}
function gosearch(btn,elemid)
{
    btn.disabled = true;
    btn.value = 'Searching, please wait...';
    if (elemid != '')
    {
        document.getElementById('hidSearchElementID').value = elemid;
    }
    document.getElementById('btnGoSearch').click();
}

function startlinking(tid,childtype,sHeight,sWidth)
{

	var sURL = "linkpopup.aspx?tid="+tid+"&tty="+childtype

	window.open(sURL,'linking','toolbar=1,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=20,top=20,width=780,height=580');

}

function linkingclick(tid,onoff)
{
		window.opener.document.getElementById('txtAttachTransactionID').value = tid;
		if (onoff == true)
		{
    		window.opener.document.getElementById('txtAttachAction').value = '1';
    	}
    	else
		{
    		window.opener.document.getElementById('txtAttachAction').value = '0';
    	}
        window.opener.document.getElementById('btnAttach').click();

//	if (window.showModalDialog)
//	{
//		var opener = window.dialogArguments;
//		opener.document.getElementById('txtAttachTransactionID').value = tid;
//        opener.document.getElementById('btnAttach').click();
//	}
//	else
//	{
//		window.opener.document.getElementById('txtAttachTransactionID').value = tid;
//        window.opener.document.getElementById('btnAttach').click();
//	}

}
 
function addpoint(map,latitude,longitude,text)
{
        var point = new GLatLng(latitude, longitude)
        var marker = new GMarker(point);
        map.setCenter(point, 13);
        GEvent.addListener(marker, "click", function() {    marker.openInfoWindowHtml(text);  });  
        map.addOverlay(marker);
} 
 
function clearselection()
{
    var table = document.getElementById('SelTable');
   if (! table) { return; }

    var tbodies = table.getElementsByTagName("tbody");

    for (var h = 0; h < tbodies.length; h++)
    {
        var ins = tbodies[h].getElementsByTagName("input");
        for (var i0 = 0; i0 < ins.length; i0++)
        {
            var fld = ins[i0];
            if (fld.id != '_reset')
                fld.value = '';
        }

        var ops = tbodies[h].getElementsByTagName("select");
        for (var i0 = 0; i0 < ops.length; i0++)
        {
            var fld = ops[i0];
            fld.selectedIndex = 0;
        }

    }
}     
function listchanged(fld,txt)
{
    var saved = document.getElementById(fld.id+'_ext')
    var arrval = txt.split(";");
    for (var i0 = 0; i0 < arrval.length; i0++)
    {
        var arr2 = arrval[i0].split(':');
        if (arr2[0] == fld.value)
        {
           var res = confirm(arr2[1]); 
           if (res !=  true)
           {
                fld.value = saved.value
               return(true); 
           }
        }
    } 
   saved.value = fld.value
    return(true); 
}

function startedit(sTransactionType,sFieldID,sFieldName)
{

	var sURL = "editpopup.aspx?tty="+sTransactionType+"&fid="+sFieldID+"&fnm="+sFieldName
	var sWidth = "700"
	var sHeight = "500"

	if (window.showModalDialog)
	{
		window.showModalDialog(sURL, self, "dialogHeight:"+sHeight+"px;dialogWidth:"+sWidth+"px;help:no;status:no");
	}
	else
	{
		window.top.captureEvents(Event.CLICK|Event.FOCUS);
		window.top.onclick=IgnoreEvents;
		window.top.onfocus=HandleFocus;
		winModalWindow = window.open(sURL,"ModalChild","dependent=yes,width="+sWidth+",height="+sHeight);
		winModalWindow.opener = self;
		winModalWindow.focus();
	}
}

function starttextedit(sFieldName,sTitle)
{

	var sURL = "editpopup.aspx?fnm="+sFieldName+"&ttl="+encodeURI(sTitle)
	var sWidth;
	var sHeight;
	
	sWidth = screen.width * 0.8;
	sHeight = 600;

	if (window.showModalDialog)
	{
		window.showModalDialog(sURL, self, "dialogHeight:"+sHeight+"px;dialogWidth:"+sWidth+"px;help:no;status:no");
	}
	else
	{
		window.top.captureEvents(Event.CLICK|Event.FOCUS);
		window.top.onclick=IgnoreEvents;
		window.top.onfocus=HandleFocus;
		winModalWindow = window.open(sURL,"ModalChild","dependent=yes,width="+sWidth+",height="+sHeight);
		winModalWindow.opener = self;
		winModalWindow.focus();
	}
}

function initedit()
{
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++)
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0)
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            if (key == 'fnm')
            {
	            if (window.showModalDialog)
	            {
		            var opener = window.dialogArguments;
		            document.getElementById('txtText').value = opener.document.getElementById(val).value;
	            }
	            else
	            {
		            document.getElementById('txtText').value = window.opener.document.getElementById(val).value;
	            }

            }
        }
    }
}

function savetext(sFieldName)
{
   var txtValue = document.getElementById('txtText').value;
	if (window.showModalDialog)
	{
		var opener = window.dialogArguments;
		opener.document.getElementById(sFieldName).value = txtValue;
	}
	else
	{
		window.opener.document.getElementById(sFieldName).value = txtValue;
	}
	window.close();
} 

function removeattachment(rid)
{
    document.getElementById('RemoveAttachmentID').value = rid;
    document.getElementById('btnRemoveAttachment').click();
}
function removeaddress(area,rid)
{
    document.getElementById('RemoveAddressArea').value = area;
    document.getElementById('RemoveAddressID').value = rid;
    document.getElementById('btnRemoveEmailAddress').click();
}

function utclick(htmlid,tableid,cmdname,cmdarg,recordrequired)
{
    if (tableid != htmlid)
    {
        tableid = htmlid.substring(0,htmlid.length-tableid.length-1);
    }
    if (recordrequired == 1)
    { 
        if (document.getElementById(tableid+'_SelectedIndex').value == '')
        {
            alert('Please select a row first'); 
        }
        else
        {    
            document.getElementById(tableid+'_Commands').value = cmdname+':'+document.getElementById(tableid+'_SelectedIndex').value;
            document.getElementById(tableid+'_Submit').click();
         }
     }
     else
     {
        document.getElementById(tableid+'_Commands').value = cmdname+':'+cmdarg;
        document.getElementById(tableid+'_Submit').click();
     }
}
function utselect(htmlid,tableid,irecordno)
{
    if (tableid != htmlid)
    {
        tableid = htmlid.substring(0,htmlid.length-tableid.length-1);
    }
    document.getElementById(tableid+'_SelectedIndex').value = irecordno;
}

function insertTab(o, e)
{
	var kC = e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which;
	if (kC == 9 && !e.shiftKey && !e.ctrlKey && !e.altKey)
	{
		var oS = o.scrollTop;
		if (o.setSelectionRange)
		{
			var sS = o.selectionStart;
			var sE = o.se-lectionEnd;
			o.value = o.value.substring(0, sS) + "\t" + o.value.substr(sE);
			o.setSelectionRange(sS + 1, sS + 1);
			o.focus();
		}
		else if (o.createTextRange)
		{
			document.selection.createRange().text = "\t";
			e.returnValue = false;
		}
		o.scrollTop = oS;
		if (e.preventDefault)
		{
			e.preventDefault();
		}
		return false;
	}
	return true;
}

function expanditem(itemid)
{
    document.getElementById('txtExpandID').value = itemid;
    document.getElementById('btnSamePage').click();
 }
function reprocessitem(itemid)
{
    document.getElementById('txtReprocessID').value = itemid;
    document.getElementById('btnSamePage').click();
 }

function chooseitem(selindex,selfield,btnfield)
{
    document.getElementById(selfield).value = selindex;
    document.getElementById(btnfield).click();
 }
  
function ReportShortcut(sType,Arg1,Arg2)
{
    document.getElementById('hidReportShortcut').value = sType+';'+Arg1+';'+Arg2;
    document.getElementById('btnReportShortcut').click();
}
function WizardShortcut(sType,Arg1,Arg2)
{
    document.getElementById('wa1_sShortcutArguments').value = sType+';'+Arg1+';'+Arg2;
    document.getElementById('wa1_cmdShortcut').click();
}

function vselect(imode,fromlist,tolist,selcodes)
{
    var fromfield = document.getElementById(fromlist);
    var tofield = document.getElementById(tolist);
    var selfield = document.getElementById(selcodes);

   if (imode == 1)
    {
        if (fromfield.selectedIndex < 0)
            alert('Please select an item from the left-hand list first'); 
        else
        {
            var addcode = fromfield[fromfield.selectedIndex].value;
            var addtext = fromfield[fromfield.selectedIndex].text;
            tofield.add(new Option(addtext,addcode));
            fromfield.remove(fromfield.selectedIndex);
            updateselcodes(tofield,selfield);
        }
    }
    else
    {
        if (tofield.selectedIndex < 0)
            alert('Please select an item from the right-hand list first'); 
        else
        {
            var addcode = tofield[tofield.selectedIndex].value;
            var addtext = tofield[tofield.selectedIndex].text;
            fromfield.add(new Option(addtext,addcode));
            tofield.remove(tofield.selectedIndex);
            updateselcodes(tofield,selfield);
        }
    }
}
function updateselcodes(tofield,selfield)
{
    selfield.value = '';

    for (var i0=0; i0 < tofield.options.length; i0++)
    {
        selfield.value = selfield.value +';' + tofield[i0].value; 
    } 
}
var xPos;
var yPos;

function showToolTip(title,msg,evt){
    if (evt) {
        var url = evt.target;
    }
    else {
        evt = window.event;
        var url = evt.srcElement;
    }
    xPos = evt.clientX;
    yPos = evt.clientY;

   var toolTip = document.getElementById("toolTip");
   toolTip.innerHTML = "<h1>"+title+"</h1><p>"+msg+"</p>";
   toolTip.style.top = parseInt(yPos)+2 + "px";
   toolTip.style.left = parseInt(xPos)+2 + "px";
   toolTip.style.visibility = "visible";
   
}

function hideToolTip(){
   var toolTip = document.getElementById("toolTip");
   toolTip.style.visibility = "hidden";
}

function editline(parenttty,parenttid,childtty,childtid)
{
    unsetchangesmade();
    document.getElementById('hidSelectedTabs').value = '';
    document.getElementById('hidEditLine1').value = parenttty;
    document.getElementById('hidEditLine2').value = parenttid;
    document.getElementById('hidEditLine3').value = childtty;
    document.getElementById('hidEditLine4').value = childtid;
    document.getElementById('btnEditLine').click();
}
function closeline(tty,tid)
{
    unsetchangesmade();
    document.getElementById('hidSelectedTabs').value = '';
    document.getElementById('hidCloseLine1').value = tty;
    document.getElementById('hidCloseLine2').value = tid;
    document.getElementById('btnCloseLine').click();
}
function cancelline(tty,tid)
{
    unsetchangesmade();
    document.getElementById('hidSelectedTabs').value = '';
    document.getElementById('hidCancelLine1').value = tty;
    document.getElementById('hidCancelLine2').value = tid;
    document.getElementById('btnCancelLine').click();
}
function newline(parenttty,parenttid,childtty)
{
    unsetchangesmade();
    document.getElementById('hidSelectedTabs').value = '';
    document.getElementById('hidNewLine1').value = parenttty;
    document.getElementById('hidNewLine2').value = parenttid;
    document.getElementById('hidNewLine3').value = childtty;
    document.getElementById('btnNewLine').click();
}
function deleteline(tty,tid)
{
    unsetchangesmade();
    var res = confirm('Please confirm this deletion'); 
     if (res ==  true)
     {
        document.getElementById('hidSelectedTabs').value = '';
        document.getElementById('hidDeleteLine1').value = tty;
        document.getElementById('hidDeleteLine2').value = tid;
        document.getElementById('btnDeleteLine').click();
     }
}
function copyline(parenttty,parenttid,childtty,childtid)
{
    var res = confirm('Please confirm this copy'); 
     if (res ==  true)
     {
        document.getElementById('hidSelectedTabs').value = '';
        document.getElementById('hidCopyLine1').value = parenttty;
        document.getElementById('hidCopyLine2').value = parenttid;
        document.getElementById('hidCopyLine3').value = childtty;
        document.getElementById('hidCopyLine4').value = childtid;
        document.getElementById('btnCopyLine').click();
     }
}
function detachline(tty,tid)
{
    var res = confirm('Please confirm that you want to detach this line'); 
     if (res ==  true)
     {
        document.getElementById('hidSelectedTabs').value = '';
        document.getElementById('hidDetachLine1').value = tty;
        document.getElementById('hidDetachLine2').value = tid;
        document.getElementById('btnDetachLine').click();
     }
}
function DeleteImage(fname)
{
    var res = confirm('Please confirm that you want to permanently delete this image ('+fname+')'); 
     if (res ==  true)
     {
        document.getElementById('txtDeleteImage').value = fname;
        document.getElementById('btnDeleteImage').click();
     }
}
function dologin()
{
    if (document.getElementById('btnHiddenLogon'))
        document.getElementById('btnHiddenLogon').click();
    else
    	document.Form1.submit();
}
function loginenter(e)
{
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if (key == 13)
	{
		event.keyCode = 0;
		dologin();
	}
}
function pagestartup()
{
    var sh = document.getElementById('_screenheight')
    var sw = document.getElementById('_screenwidth')
    if (sh)  sh.value = screen.height;
    if (sw)  sw.value = screen.width;
}
function uppercase(f)
{
    f.value=f.value.toUpperCase();
}
function dosign(fnm,uid,tid,dsp,soc)
{
    if (soc == 'S')
    {
        document.getElementById(fnm+'Dsp').value = dsp;
        document.getElementById(fnm).value = uid+';'+tid;
     }
     else
    {
        document.getElementById(fnm+'Dsp').value = '';
        document.getElementById(fnm).value = '';
    }
}
function clearfield(fnm)
{
    document.getElementById(fnm).value = '';
    document.getElementById(fnm+':Name').value = '';
}
function selecttab1(oWebTab,oTab,oEvent)
{
    var fld = document.getElementById('hidSelectedTabs')
    fld.value = fld.value+';'+oWebTab.ID+'='+oTab.index;
    createCookie('wtst_'+oWebTab.ID,oTab.index,999);
    var notloaded = oTab.findControl("notloaded");
    if (notloaded != null)
    {
         window.location.href = location.href;
     }
}
function selecttab2(oWebTab,oTab,oEvent)
{
    // We use oTab.Key rather than WebTab.ID because the latter concatenates parent web tab IDs to itself
    createCookie('st_'+oTab.Key,oTab.index,999);
    var afn = 'ai_' + oTab.Key + '_' + oTab.index;
    var afld = oTab.findControl(afn);
    if (afld != null)
    {
        var ajaxid = afld.innerHTML;
        if (ajaxid != '')
        {
            afld.innerHTML = '';
            var ofn = 'of_' + oTab.Key + '_' + oTab.index;
            ajaxcall(ajaxid,'','',ofn,1);
         }
     }
}

function createCookie(name,value,days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

var xmlHttp;

function ajaxcall(ajaxid,p1,p2,ofn,msg)
{
    var ofld = document.getElementById(ofn);
    if (ofld == null)
        alert('Output field missing: ' + ofn);
        if (msg == 1)
            ofld.innerHTML = '<table><tr><td><img src="images/loading.gif"></td><td>Please wait...</td></tr></table>';
    ofld.style.visibility = 'visible';
    
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
    var url="ajaxserver.aspx";
    url=url+"?p1="+p1;
    url=url+"&p2="+p2;
    url=url+"&ajid="+ajaxid;
    url=url+"&ofn="+ofn;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    { 
        var xml = xmlHttp.responseXML;
        //SR5874 - Firefox does not support the text property, it uses textContent.  But for proper cross browser support you need to 
        //   use  firstChild.nodeValue;
        //var status = xml.getElementsByTagName('status')[0].text;
        //var outputfield = xml.getElementsByTagName('outputfield')[0].test;
        var status = xml.getElementsByTagName('status')[0].firstChild.nodeValue;
        var action = xml.getElementsByTagName('action')[0].firstChild.nodeValue;
        var outputfield = xml.getElementsByTagName('outputfield')[0].firstChild.nodeValue;
        //SR5874-end
        if (status == '1')
        {
            var params = xml.getElementsByTagName('parameter'); 
            for (var i0=0; i0<params.length; i0+=1)
            {
                //SR5874
                document.getElementById(outputfield).innerHTML = params[i0].firstChild.nodeValue;
                //SR5874-end
             }
             if (outputfield == 'commentoutput')
             {
                        var fld = document.getElementById(outputfield);
                        var top = fld.style.top.replace(/px/,"");
                        var clientY = top - getScrollTop();
                        var overrun = clientY + fld.offsetHeight - getWindowHeight();
                        if (overrun > 0)
                        {
                            var newtop = fld.style.top.replace(/px/,"") - overrun;
                            if (newtop > getScrollTop())
                                fld.style.top = newtop;
                            else
                                fld.style.top = getScrollTop();
                        }
             }
             if (action == 6)
             {
                 // AjaxActionTriggerButton
                 var ajaxid = xml.getElementsByTagName('ajaxid')[0].firstChild.nodeValue;
                 var btn = document.getElementById('btn_' + ajaxid);
                 var hid = document.getElementById('hid_' + ajaxid);
                 btn.value = hid.value;
                 btn.disabled = false;
             }
         }
         else
         {
            //SR5874
             var errortext = xml.getElementsByTagName('error')[0].firstChild.nodeValue; 
            document.getElementById(outputfield).innerHTML=errortext;
            //SR5874-end
         }
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
} 

function createdoc(tty,fid,tid)
{
    document.getElementById('hidCreateDoc1').value = tty;
    document.getElementById('hidCreateDoc2').value = fid;
    document.getElementById('hidCreateDoc3').value = tid;
    document.getElementById('btnCreateDoc').click();
}
function popup(url,name,args)
{
	window.open(url,name,args);
}

function querystringvalue(ji)
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[0] == ji) {
    return ft[1];
    }
    }
}

function showcomment(event,ajaxid)
{	
    ajaxcall(ajaxid,'','','commentoutput',1);
	
    var fld = document.getElementById("commentoutput");
    var iwidth = 300;
	
    fld.style.left = event.clientX+10
    fld.style.top = event.clientY+0+getScrollTop();

    fld.style.width = iwidth;
//    fld.style.height = iheight;
    fld.style.display = 'block';
    
}
function getScrollTop()
{
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	return ScrollTop;
}
function hidecomment()
{
    var fld = document.getElementById("commentoutput")
    fld.style.left = 0
    fld.style.top = 0
    fld.style.width = 1;
    fld.style.height = 1;
    fld.innerHTML = "" ;
    fld.style.display = 'none';
}

function getWindowHeight() {
	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) 
	{
		//Non-IE
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

var hbHttp;
function heartbeat()
{
    hbHttp=GetXmlHttpObject();
    if (hbHttp != null)
    {
        var url="heartbeat.aspx";
        url=url+"?url="+encodeURI(location.href);
        url=url+"&sid="+Math.random();
//        hbHttp.onreadystatechange=stateChanged;
        hbHttp.open("GET",url,true);
        hbHttp.send(null);
      } 
}

function unsetchangesmade()
{
    var fld = document.getElementById('ChangesMade')
    if (fld != null)
    {
        fld.value = '0';
    }
}
function checkchangessaved()
{
    var fld = document.getElementById('ChangesMade')
    if (fld != null)
    {
        if (fld.value == '1')
            return("The changes you have made will be lost if you do.")
    }
}
function seturl(url)
{
    try
    {
        parent.location = url;
    }
    catch(ex)
    {
    }
}
function setfocus(fld)
{
    try
    {
        document.getElementById(fld).focus();
    }
    catch (ex)
    {
    }
}

function openwindow(sURL)
{

    window.open(sURL, '_blank', 'toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,left=20,top=20,width=780,height=580');

}
function triggerbutton(ajaxid)
{
    var ofn = 'lbl_' + ajaxid;
    var btn = document.getElementById('btn_' + ajaxid);
    var hid = document.getElementById('hid_' + ajaxid);
    hid.value = btn.value;
    btn.disabled = true;
    btn.value = "Processing";
    ajaxcall(ajaxid, '', '', ofn,1);
}

heartbeat();
setInterval("heartbeat()",30000);

