/*Verbal Request needed fns starts*/
var atTimer, atLastIDVR;
var mouseX, mouseY;
var forMapmouseX, forMapmouseY;
var dateBilled;
var glb_idInvoice;
var ValidDate = true;
var bFromMultiTripPanel = false;
var setHeight = true;

/*WebService Methods Starts*/
function atdeleteJobVR()
{    
    if(jsConfirm('Are you sure you want to delete this Simple Project Estimate?')==false)return;
	ActiveTextService.DeleteSelectedVRIds(atLastIDVR, OnCompleteJobVR);
}

function OnCompleteJobVR(arg)
{
	if(arg!=null && arg==true)
	 { 
	   hideVRAtWindow();
	   if(typeof(panelRefresh)=='function')
	    panelRefresh();
	   else
	   window.location.reload(); 
	 }
}
/* WebService ends*/
function getMouseXY(e) {
    if (window.location.href.toLowerCase().indexOf('addeditbuilder.aspx')>-1) return;
    
	mouseX = event.clientX + document.body.scrollLeft;
	mouseY = event.clientY + document.body.scrollTop;
	forMapmouseX=event.clientX;
	forMapmouseY=event.clientY;
}

var atEvents = new Object();
atEvents.onSurveyShown = function() {
	return true;
}

function hideVRAtWindow() {
try {
	window.clearTimeout(atTimer);
	document.getElementById(vratwId).style.display='none';
	document.getElementById(atwId).style.display='none';
	showHideSelectBoxes(true);
} catch(er) {status = "hideVRAtWindow";}
}

function fixDate(txt) {
	if(txt==null||txt==undefined) return "";
	return txt.toString().replace(/([\:]*00)+/,"");
}

function n(txt) 
{
	
	if(txt==null||txt==undefined) return "";
	return txt;
}

function showHideFields(bShow)
{

	qd("trParcel").style.display = (bShow?"inline":"none");
	qd("trClient").style.display = (bShow?"inline":"none");
	qd("trSubdivision").style.display = (bShow?"inline":"none");
	qd("trCustomer").style.display = (bShow?"inline":"none");
	qd("trPO").style.display = (bShow?"inline":"none");	
	qd("tblClientProj").style.display = (bShow?"none":"block");
	qd("trPhasename").style.display = (bShow?"none":"block");
	if(bShow)
	{
		qd("sSurveyType").innerText = "Project Type(s):";
	}
	else
	{
		qd("sSurveyType").innerText = "Phase(s):";
	}
}

function atEnterJobVR(str)
{
  if (str=='smalljobs')
   windowPopup("../main/addEditJobs.aspx?noHead=true&vrid="+atLastIDVR,970,640,1,1);
  else
   window.open("../main/proposalGenerator.aspx?vrid="+atLastIDVR); 
}

function atEditJobVR()
{
	windowPopup('../win/Verbalrequest.aspx?noHead=true&vrid='+ atLastIDVR,970,640,1,1);
}   
function PrintVREstimate()
{
    window.open("../win/PrintVerbalRequest.aspx?print=" + atLastIDVR + "&RefreshOpener=false");
}
/*verbal Request needed fns ends
Function add for panel on Control Panel form.
this fun. change mouseX position for Panels.*/
function qsClickPanel(idSurvey, panelMouseX, panelLeft, panelMouseY, panelTop) {

	var panelScrollTop = document.getElementById("divWebDesktop").scrollTop;
	var panelScrollLeft = document.getElementById("divWebDesktop").scrollLeft;
	
	mouseX = panelLeft + panelMouseX + document.body.scrollLeft - panelScrollLeft;
	mouseY = panelTop + panelMouseY  - panelScrollTop;
    
	forMapmouseX = panelLeft + panelMouseX;
	forMapmouseY = panelTop + panelMouseY;
	
	qsClick(idSurvey);
}

/* Drafting Queue needed fns starts*/
var atLastIdSurvey;
var invoices = "";
var bIsProject = false;
var bIsPhase = false;
var latitude;
var longitude;
var idbuilder;
var blnattach=false;
var IsApproved = false;
var isClientLoggedIn;
function qsClick(idSurvey) {
try {
if(idSurvey == "" )return;
	hideAtWindow();
	if (mouseX != undefined && mouseY != undefined)
	{
	document.getElementById(atwId).style.left =mouseX+20;
	document.getElementById(atwId).style.top = mouseY+10;
	}
	atShowSurvey(idSurvey);	
} catch(er) {msgbox('There was an error while attempting to display this Active Text.\r\nPlease refresh the page and try again.','vbOkOnly or vbInformation','Information');}
}
function hideAtWindow() {
try {
	window.clearTimeout(atTimer);
	document.getElementById(atwId).style.display='none';
	document.getElementById(vratwId).style.display='none';
	showHideSelectBoxes(true);
	hidePopup();
} catch(er) {status = "hideAtWindow";}
}
function atShowSurvey(idSurvey,hideSelect) {
try {
	if(idSurvey == 0) return;
	if(atLastIdSurvey == idSurvey && blnattach==false) 
	{
		document.getElementById(atwId).style.display = "inline";
		if((offY(document.getElementById(atwId))+document.getElementById(atwId).offsetHeight)>(document.body.offsetHeight+document.body.scrollTop)) {
			document.getElementById(atwId).style.top = (document.body.offsetHeight+document.body.scrollTop)-document.getElementById(atwId).offsetHeight-10;
		}

		if((offX(document.getElementById(atwId))+document.getElementById(atwId).offsetWidth)>(document.body.offsetWidth+document.body.scrollLeft)) {
			document.getElementById(atwId).style.left = (document.body.offsetWidth+document.body.scrollLeft)-document.getElementById(atwId).offsetWidth-10;
		}
		actHideInvoiceDueDate();
		hidePopup();
		if(hideSelect!=false) showHideSelectBoxes(false,false);
	}
	else
	{
		ActiveTextService.getJobInfo(idSurvey-0,atShowSurvey_cb)
	}	
} catch(er) {status="atShowSurvey"}
}

function atShowSurvey_cb(res) {    
try {
    if(res == null) return;
    HideContextMenus();
    HideContextSubMenus();
   	if(res.error!=null) {alert(res.error);return;}
	
	if(!(res != null && res.tables != null && res.tables.length == 3)) return;
	
	var row = res.tables[0].rows[0];
	atLastIdSurvey = row.idSurvey;
	atProjectId = row.idProject;
	atPhaseId = row.idStage;
	latitude=row.lat;
	longitude=row.lon;
	idbuilder=row.idBuilder;
	blnattach=false;
	actHideInvoiceDueDate();
	IsApproved=row.Approved;
	/*if the survey is project / phase than hide*/
	if(row.idProject != 0)
	{
		bIsProject = true; 
		showHideFields(false);	
		if(row.idStage > 0)
		{
			bIsPhase = true;
			qd("spanProjectType").innerHTML = 'Phase of Project';
		}	
		else
		{
			bIsPhase = false;	
			qd("spanProjectType").innerHTML = 'Multi-Phase Project';
		}	
	}
	else
	{
		bIsProject = false;
		bIsPhase = false;
		showHideFields(true);		
		qd("spanProjectType").innerHTML = 'Simple Project';
	}		
	if(row.poCd != null)
	{
		qd("poCd").innerHTML = row.poCd;	
	}
	else
	{
		qd("poCd").innerHTML = '';	
	}


	if(row.ProjectManager != null)
	{
		qd("PM").innerHTML = row.ProjectManager;	
	}
	else
	{
		qd("PM").innerHTML = '';
	}

	qd("atDateBy").innerHTML = row.sDate;
	qd("address").innerHTML = row.address.replace("~",""); // Remove the '~' Character From the address 2-26-08.docx 26.3 [Hiren]
	var tmpdate = new Date();
		
	if (row.eDate != '' && row.eDate != null)
	{
	    var objdate = row.eDate.split('-');
	    
	    var dueDate = new Date();
        dueDate.setFullYear(objdate[2], objdate[0]-1, objdate[1]);    
	    
	    if (dueDate > tmpdate)
          qd("duedate").className = "atBlue";
        else
          qd("duedate").className = "atRed"; 
	}
	if (row.eDate != null)
	qd("atDueDate").innerHTML ="Due on " + row.eDate;
	else
	qd("atDueDate").innerHTML = "No due date specified";
	
	qd("atBlock").innerHTML = TrancateString(n(row.block),10);
	qd("atBuilder").innerHTML = n(row.companyName);
	qd("atBuilderOfficeName").innerHTML = n(row.officeName);
	qd("atBuilderProj").innerHTML = n(row.companyName);
	qd("atBuilderOffice").innerHTML = n(row.officeName);
	
	var str = new String(n(row.customer));
	if(str.length > 25)
	{
		str = str.substring(0,25);
		str = str + " ...";
	}

	if(row.startDate == null)
	{
		qd("trStartDate").style.display = "none";
	}
	else
	{
	    if(bIsPhase == true)
	    {
		    qd("trStartDate").style.display = "inline";
		    qd("atStartDate").innerHTML = row.startDate;
		}
		else
		{
		    qd("trStartDate").style.display = "none";
		}
	}
	
	qd("atCustomer").innerHTML = str;
	if(row.builderAdded==true)
		qd("atEmployeeBy").innerHTML ="Client ";
	else
		qd("atEmployeeBy").innerHTML = n(row.enterBy);
	qd("atEmployeeStatus").innerHTML = n(row.employeeStatus);
	qd("atLot").innerHTML = TrancateString(n(row.lot),10);
	qd("atParcelID").innerHTML = n(row.parcelID);
	qd("atNeighborhood").innerHTML = n(row.neighborhood);
	qd("atShowId").innerHTML = row.showId;
	qd("atSection").innerHTML = TrancateString(n(row.section),10);
	qd("atTownship").innerHTML = TrancateString(n(row.township),10);
	qd("atRange").innerHTML = TrancateString(n(row.range),10);
	atLastShowId = row.showId;
	/*if(row.ShowPrj!=null && row.showId!=row.ShowPrj)
		qd("atProjShowId").innerHTML = row.ShowPrj;
	else
		qd("atProjShowId").innerHTML = "";*/

		//Mayur on 19012008	//Ramesh, May 31, 2008 show on simple and multi-phase project
		if(row.AbstractName!=null)
		{
			qd("atAbstractName").innerHTML = row.AbstractName;			
		}		

		if(row.AbstractNo!=null)
		{
			qd("atAbstractNo").innerHTML = row.AbstractNo;			
		}		

		if(row.GFNo!=null)
		{
			qd("atGFNo").innerHTML = row.GFNo;			
		}
		//Completed
		
    //Add by Divyesh on 16/2/08 for Priority field in Pop up.
	if (row.Priority1 != 0)
	    {qd("trPrority").style.display='inline';
	     qd("tdPrority").innerHTML = row.Priority1;
	    }
    else
	    {qd("trPrority").style.display='none';}
	
	qd("atPhname").style.display="none";
	if(row.showPjName!=null)
	{
		qd("atPjname").innerHTML = row.showPjName;
	}	
	qd("atPjname").style.display="inline";		
	if(bIsProject)
	{
        qd("trPrority").style.display='none';
		if(bIsPhase)
		{
			if(row.showPhName!=null)
			{
				qd("atPhname").innerHTML = row.showPhName;
			}
			qd("atPhname").style.display="inline";			
		}
	}
		
	var bShowLastupdate = true;
	if(bIsProject)
	{   
	    if (bIsPhase==false)
		 qd("trPhasename").style.display = "none";
		if(row.idStage == 0)
		{
			bShowLastupdate = false;
			qd("percentComplete").style.display = "inline";
			qd("lastUpdate").style.display = "none";
			if(row.statusName=="Complete")
				qd("percent").innerHTML = 100; 
			else
				qd("percent").innerHTML = row.percentComplete; 
		}		
	}
	
	if(bShowLastupdate)
	{
		qd("percentComplete").style.display = "none";
		qd("lastUpdate").style.display = "inline";
	}
	if(row.fieldNotes == null)
		{qd("notespic").style.display='none';}
	else
		{qd("notespic").style.display='inline';}
	if(row.attechmentExist == 0)
		{qd("attchpic").style.display='none';}
	else
		{qd("attchpic").style.display='inline';}

	if(row.FolderLocation != null)
	{	
		qd("tdFolderLocation").innerHTML = row.FolderLocation;	
	}
	else
	{
		try{
		qd("tdFolderLocation").innerHTML = '';
		}catch(er){ }
	}
		qd("tdCrewScheduledon").innerHTML = SyncAjax(ActiveTextService.get_path() + "/getCrewScheduledOnDate", "{ idSurvey:\"" + atLastIdSurvey + "\"}");
        
	if(row.showInvoice!=null)
	{
		if(row.showInvoice.substr(0,1)=="~") 
		{
			qd("atShowInvoice").innerHTML = "&nbsp;";
			invoices = "";
		}
		else 
		{
			if(res.tables[0].rows.length == 1)
			{
				qd("atShowInvoice").innerHTML = "(invoice " + row.showInvoice + ")";
			}
			else
			{
				var html = "(invoices ";
				invoices = "";
				for(var index = 0;index < res.tables[0].rows.length;index++)
				{
					if(index == res.tables[0].rows.length - 1)
						invoices += res.tables[0].rows[index].showInvoice;
					else
						invoices += res.tables[0].rows[index].showInvoice + ",&nbsp;";
				}
				qd("atShowInvoice").innerHTML = html + invoices + ")";
			}
		}
	} 
	else 
	{
		qd("atShowInvoice").innerHTML = "";
		invoices = "";
	}
	qd("atStatusDate").innerHTML = row.luDate;	
	qd("atUnit").innerHTML = TrancateString(n(row.unit),10);	
	var TripNo = res.tables[2].rows[0];
	var TripStatus = row.statusName + " Trips:" + TripNo.TripCurrent + "/" + TripNo.TripTotal;
	if(TripNo.TripTotal > 1)
	{
		qd("atStatus").innerHTML = TripStatus;
	}
	else
	{
		qd("atStatus").innerHTML = row.statusName;
	}	
	var stlist = res.tables[1].rows;
	var st = "<table border=0 cellpadding=0 cellspacing=0 class='atContents'>";
	if(stlist != null)
	{
	    for(var i=0;i<stlist.length;i++) 
	    {
		    if(row.idProject == 0)
		    {
		        currencySymbol = SyncAjax(ActiveTextService.get_path() + "/GetApplicationSettings", "{name:'CurrencySymbol'}");
			    st += "<tr><td class='actspan' nowrap><span style='width:117px;height:13px;overflow:hidden;text-overflow:ellipsis; FONT-SIZE: 8pt'>" + stlist[i].typeName + "&nbsp;</span></td><td class='actspan' align=right style='FONT-SIZE: 8pt'>"+currencySymbol + stlist[i].price + "&nbsp;</td><td class='actspan' style='FONT-SIZE: 8pt'>x " + stlist[i].quantity + "</td></tr>\r\n";
		    }
		    else if(row.idStage == 0)
		    {
			    st += "<tr><td class='actspan' nowrap><span class='actspan' style='width:167px;height:13px;overflow:hidden;text-overflow:ellipsis; FONT-SIZE: 8pt'>" + stlist[i].number + ". " + stlist[i].name + " - " + stlist[i].statusName + "</span></td></tr>\r\n";
		    }
		    else
		    {
			    if(i==0)
			        st += "<tr><td><span style='width:10px;'>&nbsp;</span></td><td style='width:100px;'><b><u>Task:</u></b>&nbsp;</td><td style='width:100px;'><b><u>Status:</u></b></td><td style='width:100px;'><b><u>% Complete:</u></b></td></tr>"
			    st += "<tr>"
			    st += "<td style='width:40px'><span style='width:10px;'>&nbsp;</span></td>"
			    st += "<td nowrap style='width:100px'><span title="+stlist[i].TaskName+" style='width:95px;height:13px;overflow:hidden;text-overflow: ellipsis; FONT-SIZE: 8pt'>"+stlist[i].TaskName+"</span></td>\r\n"
			    st += "<td nowrap><span style='width:85px;height:13px;overflow:hidden; FONT-SIZE: 8pt'>"+stlist[i].Status+"</span></td>\r\n"
			    st += "<td nowrap><span style='width:85px;height:13px;overflow:hidden; FONT-SIZE: 8pt;text-align:center;'>"+stlist[i].PerComplete+"</span></td>\r\n"
			    st += "</tr>"
		    }
	    }
	}
	if(row.idProject == 0)
	{
	    qd("tdsurveytype").style.display = "";
	    qd("tdTaskHistory").style.display = "none";
	}
	else if (row.idStage != 0)
	{
		qd("tdsurveytype").style.display = "none";
		qd("tdTaskHistory").style.display = "block";
	}
	else{
	    qd("tdsurveytype").style.display = "";
	    qd("tdTaskHistory").style.display = "none";
	}    
	st += "</table>";
	if (row.idStage != 0)
	{
	    qd("atTaskHistory").innerHTML = st;
	    qd("atSurveyTypes").innerHTML = st;
	}
    else
        qd("atSurveyTypes").innerHTML = st;
    
    if(!isClientLoggedIn) {
		document.getElementById(atwId).style.display = "inline";
		if((offY(document.getElementById(atwId))+document.getElementById(atwId).offsetHeight)>(document.body.offsetHeight+document.body.scrollTop)) {
			document.getElementById(atwId).style.top = (document.body.offsetHeight+document.body.scrollTop)-document.getElementById(atwId).offsetHeight-10;
		}

		if((offX(document.getElementById(atwId))+document.getElementById(atwId).offsetWidth)>(document.body.offsetWidth+document.body.scrollLeft)) {
			document.getElementById(atwId).style.left = (document.body.offsetWidth+document.body.scrollLeft)-document.getElementById(atwId).offsetWidth-10;
		}

		showHideSelectBoxes(false,false);
		
		if(bFromMultiTripPanel)
		{
			 bFromMultiTripPanel = false;
		}
		atEvents.onSurveyShown();
		
		if(bIsProject || bIsPhase)
		{
		    qd("mnuPrintJob").onmouseover = function() {FormatMenuText(this,'hover')} 
            qd("mnuPrintJob").onclick = function() {atPrintJob();} ;

            qd("mnuNewRevision").style.display = 'none';
            qd("mnuRevisions").style.display='none';
            qd("mnuRevisionSummary").style.display='none';
            createRevision();
            qd("mnuCopyJobInfo").style.display = 'none';
            qd("Separator1").style.display = 'none';
            qd("mnuProjectWorksheet").style.display = 'none';
            qd("mnuRevisionStatement").style.display = 'none';
		    
		    /* Added By Mayur on 24062008 [Task No:25 || Doc:20-6-08.docx] */
		    if(IsApproved == true)
			{    
			    if(bIsPhase)
			    {
			    
			        qd("mnuGenerateInvoices").style.display = 'block';
			        qd("mnuPrintWorkorder").style.display = 'none';
			        qd("mnuPhaseSummary").style.display='none';
			        qd("mnuPrintajenda").style.display = 'none';
			        qd("mnueditBillingCategory").style.display = 'none';
			        CreateBillingCategorysubMenu();
			        qd("mnuPreBillingWorksheet").style.display = 'block'; //show pre-billing menu
			        qd("mnuViewUnbilledItem").style.display = 'block';
			    }
			    else
			    {
			        qd("mnuGenerateInvoices").style.display = 'none';
			        qd("mnuPrintWorkorder").style.display = 'block';			        
			        qd("mnuPhaseSummary").style.display='block';
			        qd("mnuPrintajenda").style.display = 'block';	
			        qd("mnueditBillingCategory").style.display = 'none';	
			        qd("mnuPreBillingWorksheet").style.display = 'none'; //hide pre-billing menu for multi-phase project
			        qd("mnuViewUnbilledItem").style.display = 'none';
			    }
			    qd("mnuUpdateJobStatus").style.display = 'block';	
			    
			    //CMenu.Items.GetNamedItem("mnuPrintJob").Show();
			    qd("mnuPrintJob").style.display = 'block';
			    
			    qd("mnuVPInvoiceStmt").style.display = 'block';	
			    qd("mnuViewJobTimeSheet").style.display = 'block';	
			    qd("mnuProjectWorksheet").style.display = 'block';	
			    qd("mnuViewJobNotes").style.display = 'block';	
			    qd("mnuVPEInvoices").style.display = 'block';	
			    qd("Separator2").style.display = 'block';				    
			    qd("mnuEditJob").cells[1].innerHTML = "Edit this Project";
			}
			else
			{
			
			    qd("mnuUpdateJobStatus").style.display = 'none';	
			    qd("mnuPrintJob").style.display = 'none';
			    qd("mnuPrintWorkorder").style.display = 'none';
			    qd("mnuPhaseSummary").style.display='none';
			    qd("mnuPrintajenda").style.display = 'none';
			    qd("mnuVPInvoiceStmt").style.display = 'none';
			    qd("mnuViewJobTimeSheet").style.display = 'none';
			    qd("mnuProjectWorksheet").style.display = 'none';
			    qd("mnuViewJobNotes").style.display = 'none';
			    qd("mnuVPEInvoices").style.display = 'none';
			    qd("mnuGenerateInvoices").style.display = 'none';
			    qd("mnuViewUnbilledItem").style.display = 'none';
			    qd("Separator2").style.display = 'none';
			    qd("mnueditBillingCategory").style.display = 'none';
			    qd("mnuEditJob").cells[1].innerHTML = "Edit this proposal";
			}
			
			/* Completed */
		}	
		else
		{
		    /* Added By Mayur on 24062008 [Task No:25 || Doc:20-6-08.docx] */
		    qd("mnuUpdateJobStatus").style.display = 'block';
		    
		    //CMenu.Items.GetNamedItem("mnuPrintJob").Show();
		    qd("mnuPrintJob").style.display = 'block';
		    qd("mnuVPInvoiceStmt").style.display = 'block';
	        qd("mnuViewJobTimeSheet").style.display = 'block';
		    qd("mnuViewJobNotes").style.display = 'block';
		    qd("mnuVPEInvoices").style.display = 'block';
		    qd("Separator2").style.display = 'block';
		    qd("mnueditBillingCategory").style.display = 'block';
		    CreateBillingCategorysubMenu();
		    /* Completed */
		    		    
		    qd("mnuNewRevision").style.display = 'block';
		    qd("mnuCopyJobInfo").style.display = 'block';
		    qd("Separator1").style.display = 'block';
		    qd("mnuGenerateInvoices").style.display = 'block';
		    qd("mnuViewUnbilledItem").style.display = 'block';
		    qd("mnuPrintWorkorder").style.display = 'none';
		    qd("mnuPhaseSummary").style.display='none';
		    qd("mnuPrintajenda").style.display = 'none';
		    qd("mnuProjectWorksheet").style.display = 'none';
		    /* -- 03-18-08.doc: QuotesRevision.Doc: [Brijesh] -- */
		    var hasRevision = IsProjectHasRevision(atLastIdSurvey);
		    if(hasRevision=="true")
		    {
		        qd("mnuRevisionStatement").style.display = 'block';
		        qd("mnuRevisions").style.display='block';
		        qd("mnuRevisionSummary").style.display='block';
		        createRevision();
		    }
		    else
		    {
		        qd("mnuRevisionStatement").style.display = 'none';
		        qd("mnuRevisions").style.display='none';
		        qd("mnuRevisionSummary").style.display='none';
		    }
		    
           /*   Mayur    */
      
			qd("mnuPrintJob").onclick = "";
			
			qd("mnuPrintJob").onmouseover=function() {FormatMenuText(this,'hover');return GenerateOrderSubMenu('OrderSubMenu','ActiveTextCMenu',this);}
			//CMenu.Items.GetNamedItem("mnuPrintJob").OnClick = "";
			
			qd("mnuEditJob").cells[1].innerHTML = "Edit this Project";
			qd("mnuPreBillingWorksheet").style.display = 'block';  //show pre-billing menu
		 }
		 //when this line is removed then proposalwoeksheet.aspx page hava been working.
		 qd("mnuProjectWorksheet").style.display = 'none';
		 
	}	
	atInvoice();
	
} catch(er) {alert(er.message);status="atShowSurvey_cb";}
}
function CheckRevisions()
{
    ActiveTextService.getRevisions(atLastIdSurvey,CheckRevisions_cb);
}
function CheckRevisions_cb(res)
{
}
function createRevision()
{
    ActiveTextService.getRevisions(atLastIdSurvey,createRevision_cb);
}
function createRevision_cb(res)
{
    var strtable="<table id=\'RevisionSubMenu\' class=\'cMenu\' style=\'display:none;position:absolute;z-index:1197\' cellspacing=\'0\' cellpadding=\'2\' border=\'0\' onmouseout=\'HideRevisionSubMenu(\"RevisionSubMenu\");\' onmouseover=\'clearTimeout(TimeHideRevisionSubMenu);\'>";
    if(res.rows != null)
    {
           
    	for(var iCount = 0; iCount < res.rows.length ; iCount++)
		{
//		    var menuItem2 = new WebMenuItem();
//	        menuItem2.Name = "mnu" + res.rows[iCount].typename;
//	        menuItem2.Text = res.rows[iCount].typename;
//	        menuItem2.OnClick = "ShowCategoryPopup("+ res.rows[iCount].idsurveytype +")";
//	        CMenu.Items.GetNamedItem("mnueditBillingCategory").SubMenu.Items.Add(menuItem2);
	        
            strtable += "<tr id=\'ARevisionSubMenuclick\'  onmouseover=\'FormatMenuText(this,\"hover\")\' onmouseout=\'FormatMenuText(this,\"out\")\' onclick=\'qsClick("+ res.rows[iCount].idSurvey + ")\' ><td class=\'MenuPrefix\' nowrap></td><td nowrap>"+ res.rows[iCount].Showid +"</td><td class=\'HasSubMenu\' nowrap></td></tr>";
            
            //"<tr><td nowrap><a id=\'ABillingCatgSubMenuclick\' href=\'javascript:void(0)\' onclick=\'ShowCategoryPopup("+ res.rows[iCount].idsurveytype + ")\' >"+ res.rows[iCount].typename +"</a></td></tr>";
		}
		
		qd("mnuRevisions").onmouseover = function() {FormatMenuText(this,'hover');return GenerateRevisionSubMenu('RevisionSubMenu','ActiveTextCMenu',this);};
    }
    qd("divRevisionSubMenu").innerHTML = strtable + "</table>";	   
}
function CreateBillingCategorysubMenu()
{
    ActiveTextService.surveyTypesByHours(atLastIdSurvey,CreateBillingCategorysubMenu_cb);
}
function showphaseCategory()
{
    msgbox('This project is not being billed hourly.','vbok or vbWarning','Warning');
}
function CreateBillingCategorysubMenu_cb(res)
{
    qd("mnueditBillingCategory").onmouseover = function() {FormatMenuText(this,'hover')} 

    if(bIsPhase || bIsProject)
    {
        if(res.rows == null)
        {
            qd("mnueditBillingCategory").style.display = 'block';
            qd("mnueditBillingCategory").onclick = function() {showphaseCategory();};
            //qd("mnueditBillingCategory").OnClick = "showphaseCategory();"
            return;
        }
    }
        
    if(bIsProject == false && bIsPhase == false)
    {
        if(res.rows == null)
        {
            qd("mnueditBillingCategory").style.display = 'none';
            //CMenu.Items.GetNamedItem("mnueditBillingCategory").Hide();
            return;
        }
    }

    if(res.rows != null)
    {
        var strtable="<table id=\'BillingCatgSubMenu\' class=\'cMenu\' style=\'display:none;position:absolute;z-index:1197\' cellspacing=\'0\' cellpadding=\'2\' border=\'0\' onmouseout=\'HideBillingCatgSubMenu(\"BillingCatgSubMenu\");\' onmouseover=\'clearTimeout(TimeHideBillingCatgSubMenu);\'>";
        
    	for(var iCount = 0; iCount < res.rows.length ; iCount++)
		{
//		    var menuItem2 = new WebMenuItem();
//	        menuItem2.Name = "mnu" + res.rows[iCount].typename;
//	        menuItem2.Text = res.rows[iCount].typename;
//	        menuItem2.OnClick = "ShowCategoryPopup("+ res.rows[iCount].idsurveytype +")";
//	        CMenu.Items.GetNamedItem("mnueditBillingCategory").SubMenu.Items.Add(menuItem2);
	        
            strtable += "<tr id=\'ABillingCatgSubMenuclick\'  onmouseover=\'FormatMenuText(this,\"hover\")\' onmouseout=\'FormatMenuText(this,\"out\")\' onclick=\'ShowCategoryPopup("+ res.rows[iCount].idsurveytype + ")\' ><td class=\'MenuPrefix\' nowrap></td><td nowrap>"+ res.rows[iCount].typename +"</td><td class=\'HasSubMenu\' nowrap></td></tr>";
            
            //"<tr><td nowrap><a id=\'ABillingCatgSubMenuclick\' href=\'javascript:void(0)\' onclick=\'ShowCategoryPopup("+ res.rows[iCount].idsurveytype + ")\' >"+ res.rows[iCount].typename +"</a></td></tr>";
		}
		
		qd("mnueditBillingCategory").onmouseover = function() {FormatMenuText(this,'hover');return GenerateBillingCatgSubMenu('BillingCatgSubMenu','ActiveTextCMenu',this);};
		qd("divBillingCatgSubMenu").innerHTML = strtable + "</table>";	 
    }
}

function ShowCategoryPopup(idSurveyType)
{ 
    var idSchedule=SyncAjax(ActiveTextService.get_path() + "/getSchedule", "{idSurvey:'" + atLastIdSurvey + "',idSurveyType:'" + idSurveyType + "'}")
    var qstr = "idSurvey="+atLastIdSurvey+"&idSurveyType="+idSurveyType+"&idSchedule="+idSchedule+"&InvoiceEdited=true&PrintInvEdited=true";   
    var clientFeatures="dialogHeight:560px;dialogWidth:650px;status:no;resizable:no;scroll:yes;";
    showModalDialog("../win/BillingCategories.aspx?" + qstr,"",clientFeatures); 
}
function hidePopup()
{
qd("atwProjectInvoice").style.display = "none";
}
function actHideInvoiceDueDate()
{
 qd('ActUpdateInvoiceDueDate').style.display="none";
}
function TrancateString(str,limit)
{
	if(str.length > limit)
	{
		str = str.substring(0,limit);
		str = str + " ...";
	}	
	return str;
}
function getWinLeft(winWidth)
{
	var winLeft = (window.screen.width/2)-(winWidth/2);
	return winLeft;
}

function getWinTop(winHeight)
{
	var winTop = (window.screen.height/2)-(winHeight/2);
	return winTop;
}

function atRevision() 
{
	if(!bIsProject)
		windowPopup("../main/addEditJobs.aspx?noHead=true&id="+atLastIdSurvey+"&Type=Revision",970,640,1,1);
}
function atCopyInfo() 
{
	if(!bIsProject)
		windowPopup("../main/addEditJobs.aspx?noHead=true&id="+atLastIdSurvey+"&Type=CopyInfo",970,640,1,1);
}
function atScanJob() {
	docHdr=document.getElementById(vratwId);
	if(docHdr==null)
	{
		var myShowId = document.getElementById("vratShowId");
		if(document.getElementById(vratwId).style.display=="none")
		{
			var myShowId = document.getElementById("atShowId");
			if(document.getElementById(atwId).style.display!="none")
			{
				var myShowIdText=myShowId.innerText
				windowPopup("../barcode?noHead=true&showId="+ escape(myShowIdText),970,670,1,1);
			}
		}
		else
		{
			if(document.getElementById(vratwId).style.display!="none")	
			{
				var myShowIdText=myShowId.innerText
				windowPopup("../barcode?noHead=true&showId="+ escape(myShowIdText),970,670,1,1);
			}
		}
	}
	else
	{
		var myShowId = document.getElementById("vratShowId");
		if(document.getElementById(vratwId).style.display=="none")
		{
			var myShowId = document.getElementById("atShowId");
			if(document.getElementById(atwId).style.display!="none")	
			{
				var myShowIdText=myShowId.innerText
				windowPopup("../barcode?noHead=true&showId="+ escape(myShowIdText),970,670,1,1);
			}
		}
		else
		{
			if(document.getElementById(vratwId).style.display!="none")	
			{
				var myShowIdText=myShowId.innerText
				windowPopup("../barcode?noHead=true&showId="+ escape(myShowIdText),970,670,1,1);
			}
		}
	}
}
function atEditJob(step) 
{
    if(step == null) step = "";
	blnRefresh=true;
	if(!bIsProject)
		windowPopup("../main/addEditJobs.aspx?noHead=true&id="+atLastIdSurvey+"&step="+step,screen.width*97/100,screen.height*85/100,1,1);
	else
	{
		if(step == "2") step = "ProjectLocation";
		windowPopup("../main/proposalGenerator.aspx?noHead=true&id="+atProjectId+"&step="+step,screen.width*97/100,screen.height*85/100,1,1);
	}
}
function atEditJobnumber() 
{
    windowPopup("../main/editjobnumber.aspx?noHead=true&ShowId="+qd("atShowId").innerText,screen.width*90/100,screen.height*50/100,1,1);
}
function atedithourlyrates()
{
    windowPopup("../win/BillingCategories.aspx?isSetup=1",screen.width*80/100,screen.height*70/100,1,1);
}
function atPrintJob() 
{
  if(bIsProject)
  {
	if(!bIsPhase)
  	  window.open("../" + clsAppConfig.ClientCode + "/" + clsAppConfig.Idsite + "/attachments/orders/ORDER_" + atProjectId + ".pdf");
	else
  	  window.open("../" + clsAppConfig.ClientCode + "/" + clsAppConfig.Idsite + "/attachments/orders/ORDER_" + atProjectId + "_" + atPhaseId + ".pdf");
  }
 else
  {
   //window.open("../main/printMultipleJobs.aspx?print=" +atLastIdSurvey+ "&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close()</script>")) + "&showPrintMsg=false");
   windowPopup("../main/printMultipleJobs.aspx?print=" +atLastIdSurvey+ "&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close()</script>"))+"&showPrintMsg=false",950,650,1);
  } 
}

var officelatitude;
var officelongitude='';
function atJobDirection()
{   
  var url;
  if (officelongitude=='')
  {
    ActiveTextService.getOfficeLatLon(atJobDirection_cb);
  }
  else
  {
    url = "http://maps.yahoo.com/beta/#maxp=location&q1=" + officelatitude + "," + officelongitude + "&q2="+ latitude +","+ longitude +"&trf=0&mvt=m";
    window.open(url,'','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=990px,height=600px,left=10px,top=10px');
  }
}
function atJobDirection_cb(officelatlon)
{
    officelatitude=officelatlon[0];
    officelongitude=officelatlon[1];    
    url = "http://maps.yahoo.com/beta/#maxp=location&q1=" + officelatitude + "," + officelongitude + "&q2="+ latitude +","+ longitude +"&trf=0&mvt=m";
    window.open(url,'','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=990px,height=600px,left=10px,top=10px');
}

function actHideInvoiceDueDate()
{
 qd('ActUpdateInvoiceDueDate').style.display="none";
}

function atManualInvoice(chkPendingHours)
{
  if (chkPendingHours==undefined) chkPendingHours=0;
  ActiveTextService.GenerateManualInvoice(atLastIdSurvey,chkPendingHours,atManualInvoice_Cb); 
}

function atManualInvoice_Cb(ret)
{
  if (ret!=null && ret==-1)
	{
	  var retval=msgbox("Some hours pertaining to this job have not been approved by the manager.\r\nPlease choose an option below.","vbViewhour or vbIgnore or vbCancel or vbWarning","Warning");
	  if(retval==8)/*show pending hours*/
	  {
	    windowPopup("../main/addEditPendingHours.aspx?noHead=true&idSurvey="+atLastIdSurvey,900,600,1,1);
	    return;
	  }
	  else if(retval==5) /*ignore pending hours*/
	  {
	    atManualInvoice(1);return;
	  }
	  else
	   return; /*cancel process*/
	}
	else if(ret != null && ret > 0)
	{
		url = "../main/printInvoices.aspx?noHead=true&surveyToInvoice="+atLastIdSurvey
		windowPopup(url,1100,560,1,1);
	} 
}

function atInvoiceStatement() 
{ 
  ActiveTextService.GetProjectInvoiceList(atLastIdSurvey,atProjectId,atInvoiceStatement_cb);
}
function atInvoiceStatement_cb(ret)
{
  if(ret != null && ret != "")
   {
	window.open("../main/viewPrintInvoices.aspx?statement=1&idSurvey="+atLastIdSurvey,"printInvoice",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=980,height=560');
   }
  else
   msgbox('This job does not have an invoice.','vbOkOnly or vbInformation','Information');
}
  
function atInvoice()
{ 
  qd("mnuVPEInvoices").onmouseover = function() {FormatMenuText(this,'hover')} 
  ActiveTextService.GetActiveTextProjectInvoiceList(atLastIdSurvey,atProjectId,atInvoice_Cb);
}
function atInvoice_Cb(ret) 
{
    if(ret != null && ret.rows != null)
    {  
        var tblInvoiceList = ret;
        var strInvoiceSubMenu ;
        var strtable="<table id=\'InvoiceSubMenu\' class=\'cMenu\' style=\'display:none;position:absolute;z-index:1197\' cellspacing=\'0\' cellpadding=\'2\' border=\'0\' onmouseout=\'HideInvoiceSubMenu(\"InvoiceSubMenu\");\' onmouseover=\'clearTimeout(TimeHideInvoiceSubMenu);\'>";
          
		if(tblInvoiceList.rows.length > 0)
		{		
		    qd("mnuVPEInvoices").onmouseover = function() {FormatMenuText(this,'hover');return GenerateInvoiceSubMenu('InvoiceSubMenu','ActiveTextCMenu',this)};
 
		    for(var iCount = 0; iCount < tblInvoiceList.rows.length ; iCount++)
			{
				 var mntext = "";				 
				 mntext = tblInvoiceList.rows[iCount].showid + "&nbsp;&nbsp;&nbsp;&nbsp;" + tblInvoiceList.rows[iCount].datebilled+ "&nbsp;&nbsp;&nbsp;&nbsp;"+formatCurrency_Invoice(tblInvoiceList.rows[iCount].invoiceAmount);
				 if (parseInt(tblInvoiceList.rows[iCount].amountDiff)==0)
				    mntext += '<span style=color:red> (Paid)<span>';
                
                
                strtable += "<tr onmouseover=\'FormatMenuText(this,\"hover\")\' onmouseout=\'FormatMenuText(this,\"out\")\' onclick=\'window.open(\"../main/viewPrintInvoices.aspx?id=" + tblInvoiceList.rows[iCount].idInvoice + "\",\"_blank\",\"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=560,left=50,top=10\")\' ><td class=\'MenuPrefix\' noWrap></td><td noWrap>"+ mntext +"</td><td  class=\'HasSubMenu\' noWrap></td></tr>";                                

                
			}
			qd("divInvoiceSubMenu").innerHTML = strtable + "</table>";	 		
        } 
    }
} 

function checkInvoiceList()
{
    ActiveTextService.GetActiveTextProjectInvoiceList(atLastIdSurvey,atProjectId,checkInvoiceList_Cb);
}
function checkInvoiceList_Cb(ret) 
{
    if(ret == null || ret.rows == null)
    {
        msgbox('This job does not have an invoice.','vbOkOnly or vbInformation','Information');
    }
}

function atTimeSheet()
{
    var rowCount = SyncAjax(ActiveTextService.get_path() + "/getInvoicedStatustimeRecord", "{ idSurvey:\"" + atLastIdSurvey + "\"}");
    
    var showTimeSheetPopup;
    showTimeSheetPopup = readCookie("JobTimeSheetPopupCookie");

    if ((showTimeSheetPopup == null || showTimeSheetPopup == "" || showTimeSheetPopup == "0") && rowCount>0)
    {
        window.showModalDialog('../win/JobTimeSheetPopup.asp','Warning', "center:yes;status:no;unadorned:no;resizable:0;dialogWidth:485px;dialogHeight:150px");
    }
    
    if(!bIsProject)
		windowPopup("../main/addeditstatustimes.aspx?noHead=true&idSurvey=" + atLastIdSurvey,1020,640,1,1);
	else
	{
		if(bIsPhase)
			windowPopup("../main/addeditstatustimes.aspx?noHead=true&idSurvey=" + atLastIdSurvey,1020,640,1,1);
		else
			windowPopup("../main/addeditstatustimes.aspx?noHead=true&idProject=" + atProjectId,1020,640,1,1);
		
	}
}
function atUnBilledItem()
{
    url = "../reports/UnInvoicedProjectList.aspx?noHead=true&idSurvey="+atLastIdSurvey
	windowPopup(url,1150,560,1,1);
}
function atEditInvoice()
{
 blnRefresh=true;
 if(Trim(qd("atShowInvoice").innerHTML).length > 0)
 {
  ActiveTextService.GetInvoiceDetails(atLastIdSurvey,setInvoiceData);
 }
 else
 {
   msgbox('This job does not have an invoice.','vbOkOnly or vbInformation','Information');
 }
}

function setInvoiceData(ret)
{
	if(ret != null)
	{
		tblInvoice= ret;
		if(tblInvoice.rows.length == 1)
		{
			var tdInvoice = document.getElementById("spInvoice");
			tdInvoice.innerHTML = "";
			glb_idInvoice = tblInvoice.rows[0].idInvoice;
		}
		else if(tblInvoice.rows.length > 1)
		{
			var ddInvoice = document.createElement("SELECT");
			ddInvoice.id = "ddInvoices";
			ddInvoice.options.length = 0;
			ddInvoice.onchange = invoiceChange;
			var otTemp = document.createElement("OPTION");
			otTemp.value = -1;
			otTemp.innerText = "---";
			ddInvoice.appendChild(otTemp);
			
			for(var index = 0;index < tblInvoice.rows.length ; index++)
			{
				var ot = document.createElement("OPTION");
				ot.value = tblInvoice.rows[index].idInvoice;
				ot.innerText = tblInvoice.rows[index].showid;
				ddInvoice.appendChild(ot);
			}
			ddInvoice.options[0].selected = true;
			glb_idInvoice = tblInvoice.rows[0].idInvoice;
			var tdInvoice = document.getElementById("spInvoice");
			tdInvoice.innerHTML = "";
			tdInvoice.appendChild(ddInvoice);
			tdInvoice.appendChild(document.createTextNode(" "));
			qd('ActUpdateInvoiceDueDate').style.display="inline";
		}
		else
		{
			msgbox('This job has multiple invoices.','vbOkOnly or vbInformation','Information');
			glb_idInvoice = -1;
		}
	}
	else
	{		
		glb_idInvoice = -1;
		msgbox('An error occured while retrieving values for the invoice.','vbOkOnly or vbWarning','Warning');
	}
}
function invoiceChange()
{
	var dd = document.getElementById("ddInvoices");
	if(dd.value > 0)
	{
		glb_idInvoice = dd.value;
//		showEdit(atLastIdSurvey,dd.options[dd.selectedIndex].text,atProjectId,dd.value,atLastShowId);
	}
	else
	{		
		hidePopup();
		actHideInvoiceDueDate();
	}	
}
function atJobNotes() {
	var url = '../win/notes.aspx?idSurvey='+atLastIdSurvey;
	var findMyUrlIndex = window.location.href.toLowerCase().indexOf("notes.aspx");
	if(findMyUrlIndex<=0)
		jobsNotesWin=window.open(url,'jobsNotes','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=625,height=680,left='+getWinLeft(600)+',top='+getWinTop(500));	
		jobsNotesWin.focus();
}
function atAttachments() {
	blnattach=true;
	showAttachments(atLastIdSurvey);
} 
function atJobMap()
{
	if(!bIsProject)
		windowPopup("../Maps/gjv.aspx?noHead=true&idSurvey="+ atLastIdSurvey,970,640,1,1);
	else
		windowPopup("../Maps/gjv.aspx?noHead=true&idProject="+ atProjectId,970,640,1,1);
} 
function atClientInfo()
{  
   blnRefresh=true;
   windowPopup("../main/addEditBuilder.aspx?inSetup=true&idbuilder="+idbuilder,1200,775,1); 
} 
function atProjectWorksheet()
{  windowPopup("../main/ProposalWorksheet.aspx?id="+atProjectId,1000,650,1,1);
}

/* DraftingQueue needed fns ends ScheduledJobs needed fns starts*/
function atPrintJob1(idSurvey) {	
	//window.open("../main/printMultipleJobs.aspx?print=" +idSurvey+ "&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close();</script>")));
	windowPopup("../main/printMultipleJobs.aspx?print=" +atLastIdSurvey+ "&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close()</script>"))+"&showPrintMsg=false",950,650,1);
}
/* ScheduledJobs needed fns ends PhoneMemo.aspx needed fns starts*/ 
var qsLastTyped;
function qsCheckFind(obj)
 {
	 if(obj.id =="ctl00_cvlHeader1_LoginView1_HeadershifSearch_mainShiftSearch" )
        document.getElementById(atwId).style.left = offX(obj)+obj.offsetWidth-15;
    else    
        document.getElementById(atwId).style.left = offX(obj)+obj.offsetWidth+10;
	document.getElementById(atwId).style.top = offY(obj);
	value = obj.value;
	value=value.replace(/\\+/g,'');
	value=value.replace(/'+/g,'');		
		
	window.clearTimeout(atTimer);
	if(value!=qsLastTyped) hideAtWindow();
	qsLastTyped = value;
	if(value!="")
		atTimer = window.setTimeout("atFindSurvey('" + value + "')",777);
}

var estimateShowId='';
function atFindSurvey(showId, idSurvey) 
{
	if(showId!=null) 
	{
		if(showId.indexOf("i")!=0)
		{
		 estimateShowId = showId;
		 ActiveTextService.getRealId(showId,1,atShowId_cb);
		}
		else
		 ActiveTextService.getRealId(showId.substring(1,showId.length),2,atShowInvId_cb)
	}
	else if(idSurvey!=undefined) 
	{
		atShowSurvey(idSurvey)
	} 
}
function atShowInvId_cb(res){
	if(res.error!=null) {msgbox(res.error,'vbOkOnly or vbWarning','Warning');return;}
	if(res>0) {
		window.open("../main/viewPrintInvoices.aspx?id="+res,"printInvoice",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=980,height=560');
	}
}
function atShowId_cb(res) {
    if(res.error!=null) {msgbox(res.error,'vbOkOnly or vbWarning','Warning');return;}
    if(res!=0) 
		atShowSurvey(res)
    else
        qsEstimateNumber(estimateShowId);
}

function qsEstimateNumber(showId)
{
    var idSurvey = SyncAjax(ActiveTextService.get_path() + "/getRealId", "{showId:'" + showId + "',docType:3}");
    if (idSurvey>0)
        vrClick(idSurvey);
}

/* PhoneMemo.aspx needed fns ends..
Functions needed in report pages starts*/
function winShowId(showId,type)
{
	var url;
	if(type==1) {
		url = "../barcode/?noHead=true&showId="+escape(showId)
	} else if(type==2) {
		if(showId.substr(0,3)=='gen') {
			url = "../main/printInvoices.aspx?noHead=true&surveyToInvoice="+showId.substr(3)
		} else {
			url = "../main/viewPrintInvoices.aspx?showId="+escape(showId)
		}
	} else {
		return;
	}
	windowPopup(url,780,400,1,1);
}
/*Functions needed in report pages ends
Shift Search java script*/
var ssB = Object();
var ssT = Object();
var ssC = Object();
var ResulttextBoxId='';
var ShowATbubbleOnResult;
function Swift_showSwift(obj,cntTextId,blnShowAtbubble) {
	if (ResulttextBoxId!=cntTextId)
		qd("ssSearch").value='';	
	ShowATbubbleOnResult=blnShowAtbubble;	
	ResulttextBoxId=cntTextId;	
	var space = 1;
	ssB.w = 141;	/*Bubbles width*/
	ssB.h = 105;	/*Bubbles height*/
	ssT.w = 350;	/*Terms width*/
	ssT.h = 400;	/*Terms height*/
	var totalW = ssB.w+ssT.w;
	var totalH = ssB.h+ssT.h-10;
	var oX = offX(obj);	/*obj X*/
	var oY = offY(obj);	/*obj Y*/
	var oW = obj.offsetWidth;
	var sXb = document.body.scrollLeft;		/*Screen X: begin*/
	var sYb = document.body.scrollTop;		/*Screen Y: begin*/
	var sXe = document.body.clientWidth+sXb;	/*Screen X: end*/
	var sYe = document.body.clientHeight+sYb;	/*Screen Y: end*/
	ssB.obj = qd("ssBubbles");
	ssT.obj = qd("ssTerms");
	ssC.obj = qd("ssContents");
	
	/*Bubbles: Vertical*/
	if(oY-totalH/2 > sYb) {
		/*Location of obj allows enough space to fit bubble.*/
		ssB.y = oY-ssB.h;
		ssB.type = "u";
	} else {
		ssB.y = oY;
		ssB.type = "d";
	}
	ssB.obj.style.top = ssB.y;
	
	/*Bubbles & Terms: Horizontal*/
	if(totalW < oX) {
		ssB.x = oX-space-ssB.w;
		ssB.type += "l";
		ssT.x = ssB.x-ssT.w+5;
	} else {
		ssB.x = oX+oW+space;
		ssB.type += "r";
		ssT.x = ssB.x+ssB.w-5;
	}
	ssT.obj.style.left = ssT.x+30;
	
	if(30+oY-totalH > sYb) {
		ssT.y = 30+oY-totalH;
	} else {
		ssT.y = sYb+10;
	}
	ssT.obj.style.top = ssT.y;
	
	ssC.x = ssT.x+50;
	ssC.y = ssT.y+50;
	ssC.obj.style.left = 13;
	ssC.obj.style.top = 20;
	
	ssB.obj.style.display = "inline";
	ssT.obj.style.display = "inline";
	ssC.obj.style.display = "inline";
	Swift_ssMoveHide(ssT.obj, ssT.x+ssT.w-40, ssT.y+35, ssC.obj, ssB.obj,qd("ssError"))
	
	qd("ssSearch").focus();
	
}
function Swift_ssHelpShow(obj) {
 	var oX = offX(obj);
	var oY = offY(obj);
	var oW = obj.offsetWidth;
	var h = qd("ssHelp");
	h.style.left = oX+oW;
	h.style.top = oY+16;
	h.style.display = "inline";
	Swift_ssMoveHide(h, oX+oW+265, oY+50) 
	h.focus();
	if(shiftparameter == undefined)
	 Swift_fillhelp();
}

var ssToHide;
function Swift_ssMoveHide(obj,x,y,alsoHide1,alsoHide2, alsoHide3) {
	var c = qd("ssClose");
	if(ssToHide!=null&&ssToHide.obj!=obj) {
		obj.prevHide = ssToHide;
	}
	c.style.left = x+26; /*change this for change position of close button in swiftsearch*/
	c.style.top = y-25;
	c.style.display = "inline";
	ssToHide = Object();
	ssToHide.obj = obj;
	ssToHide.x = x;
	ssToHide.y = y;
	ssToHide.alsoHide1 = alsoHide1;
	ssToHide.alsoHide2 = alsoHide2;
	ssToHide.alsoHide3 = alsoHide3;
}

function Swift_ssHide() {
	var c = qd("ssClose");
	ssToHide.obj.style.display = "none";
	qd('ssResult').style.display = "none";
	if(ssToHide.alsoHide1!=null) ssToHide.alsoHide1.style.display = "none";
	if(ssToHide.alsoHide2!=null) ssToHide.alsoHide2.style.display = "none";
	if(ssToHide.alsoHide3!=null) ssToHide.alsoHide3.style.display = "none";
	if(ssToHide.obj.prevHide!=null) {
		var tmp = ssToHide.obj.prevHide;
		ssToHide.obj.prevHide = null;
		ssToHide = null;
		Swift_ssMoveHide(tmp.obj, tmp.x, tmp.y, tmp.alsoHide1, tmp.alsoHide2, tmp.alsoHide3);
	} else {
		c.style.display = "none";
		ssToHide = null;
	}
}

function Swift_ssSearchKeyed(obj) {
	var terms = obj.value;
	qd('ssResult').style.display = "none";
	if(window.event.keyCode==13 && window.event.ctrlKey)
	 Swift_ssDoSearch(obj);
	else if(window.event.keyCode == 13) 
		Swift_ssValidate(terms,offX(obj),offY(obj)+obj.offsetHeight);	
	else if(window.event.keyCode == 27)
		closeShiftSearchPopup();
}
function Swift_ssSearchESCKey(obj){
  if(window.event.keyCode == 27)
	Swift_ssHide();
}
function closeShiftSearchWindow(id){
  if(window.event.keyCode == 27)
	closeSwiftWindow(id);
}

function qm_over(obj) {
	obj.style.backgroundColor = "#0053A6";
}

function qm_out(obj) {
	obj.style.backgroundColor = "transparent";
}

function CheckShiftLastValue(obj,txtmsg){
  obj.style.color='#696969';
  obj.style.textAlign= 'Left';
  if(obj.value==txtmsg)obj.value='';
}

function CheckShiftCurrentValue(obj,txtmsg){
if(obj.value.replace(/\s+/g,'')=='')
  {
    obj.style.color='#696969';
    obj.style.textAlign= 'center';
    obj.value=txtmsg;
  }  
}

function Swift_fillhelp()
{ 
  var shiftresult = ActiveTextService.Loadshiftsearchhelp(callbackresponce);
}
var shiftparameter;
function callbackresponce(res)
{
  if (res != 'undefined' || res != '')
  {
      shiftparameter = res; 
      var strtmp='<table style="FONT-SIZE: 8pt">';
      var totalrows = shiftparameter.rows.length;
      var tmpi;
      for(tmpi=0;tmpi<=totalrows-1;tmpi++)
       strtmp +='<tr><td><a href="#" onclick=searchHelpFor("'+ shiftparameter.rows[tmpi].name + '")>' +  shiftparameter.rows[tmpi].name  + '</a></td><td>' + shiftparameter.rows[tmpi].helpNote + '</td></tr>';
      strtmp +='</table>';
      qd("ssHelpContents").innerHTML=strtmp;
  }
}

function searchHelpFor(searchKeyword)
{
  Swift_ssHide(); 
  var searchFor = qd('ssSearch').value.split('\n');
  var lastInput = searchFor[searchFor.length-1];
  if(lastInput.replace(/\s+/g,'')=='')
  {
    LastLineNumber=qd('ssSearch').value.lastIndexOf('\n');
    qd('ssSearch').value = qd('ssSearch').value.substr(0,LastLineNumber)+ searchKeyword + ':';
  }
  else
   {
     qd('ssSearch').value +='\n'+ searchKeyword + ':';
   }  
   qd('ssSearch').focus;
}

var isValidSwiftSearch;
function Swift_ssValidate(terms,x,y) {
	ssErrors = "";
	isValidSwiftSearch=true;	
	var intloop;	
	var intParamter;
	var isValidKeyword;
	var searchFor = terms.split('\n');
	for(intloop=0;intloop<searchFor.length;intloop++)
	 { 
	   if(searchFor[intloop].replace(/\s+/g,'')=='')
	    continue;
	   
	   isValidKeyword=false;  
	   var strCondition =searchFor[intloop].split(':');
	    if(strCondition.length == 2 && shiftparameter != 'undefined')
	     { 
	       for(intParamter=0;intParamter<=shiftparameter.rows.length-1;intParamter++)
	        {
	           if(shiftparameter.rows[intParamter].name ==strCondition[0].toLowerCase())
	            { 
	             var checkRegex = shiftparameter.rows[intParamter].regex;
	             if(strCondition[1].match(checkRegex)==null)
	                Swift_ssAddError(intloop+1,searchFor[intloop] + ' Not Valid input.');
	             isValidKeyword=true;
	             break;
	            }
	        }
	     }
	    if(isValidKeyword==false)
	        Swift_ssAddError(intloop+1,strCondition[0] + ' Not Valid Keyword for search.');	      	  
	 } 
	if(isValidSwiftSearch==false)
	 Swift_ssShowError(ssErrors,0,160);
	else
	 qd("ssError").style.display = "none";  
}
var serachtime=1;
var idx = 1;

function Swift_ssDoSearch(obj) 
{
    if(dv('ssSearch').replace(/\s+/g,'')=='')
    {
        msgbox('Please Enter Search Terms','vbOkOnly or vbInformation','Information');
        qd("ssSearch").focus();
        return;
    }
	Swift_ssValidate( dv('ssSearch') );
	if(isValidSwiftSearch==false)
	{ 
	  return;
	}	
 	ActiveTextService.shiftSearchResult(dv('ssSearch'),idx,SearchResult)
}

function SearchResult(res)
{
   if(res.error!=null)
    {
        msgbox(res.error,'vbOkOnly or vbWarning','Warning');
        return;
    }	
	if(res != '')
	 {	
	    
		if (res.substr(0,6)!="<input")
		  {
		    eval(res);
		    Swift_ssShowError(ssErrors,0,160);
		    qd("ssError").style.display = "inline";
		    return "";
		  }
		idx++;
	    var frm = qd("frmTemp");
        frm.contentWindow.document.getElementById("txtResult").value = res;
        frm.contentWindow.document.getElementById("btnCreate").click();
	} 
	else
	 msgbox('No results were found.','vbOkOnly or vbInformation','Information');
}

function closeSwiftWindow(id)
{
	var frm = qd("frmTemp");        
	frm.contentWindow.eval("Windows").close(id);
}

function minWindow(id)
{
	var frm = qd("frmTemp");
	frm.contentWindow.eval("Windows").minimize(id);
}

function maxWindow(id)
{
	var frm = qd("frmTemp");
	frm.contentWindow.eval("Windows").maximize(id);
}

function Swift_ssAddError(line,txt) {
	isValidSwiftSearch=false;
	ssErrors += "<tr><td><i>Line "+line+": </i></td><td nowrap>"+txt+"</td></tr>";
}
var strTempFeatures = 'dialogHeight:150px; dialogWidth:520px; scroll:no; status:no; help:no; resizable:no;';
function Swift_ssShowError(errRows,x,y) { 
    var strTemparguments=new Array();
    strTemparguments[0]="<table border=0 cellpadding=0 cellspacing=0 style='font-size: 8pt; align:center;'><tr><td colspan=2><b>Please correct the following error(s):</b></td></tr>"+errRows+"</table>";
    strTemparguments[1]="vbOkOnly or vbWarning"
    strTemparguments[2]="Error"
    showModalDialog(strMsgboxPath + 'js_msgbox.html', strTemparguments, strTempFeatures);
}

function Swift_ssHideError() {
	qd("ssError").style.display = "none";
	qd("ssSearch").focus();
}

function SwiftSearchSelectButtonClick(intResultBox)
{
  var selRowIdsurvey=qd('hdnPreviousResultId'+ intResultBox).value
  var rowObj = qd(intResultBox + 'tr' + selRowIdsurvey);
  try{rowObj.fireEvent('ondblclick',event);}catch(e){}
}

function selectShiftResultRow(selectedRowIdsurvey,AssignedClass,intResultBox)
{
  var currentResultRow=	qd(''+ intResultBox + 'tr' + selectedRowIdsurvey);
  if (currentResultRow.className=='tab-grid-row1' ||currentResultRow.className=='tab-grid-row2')
  {
    currentResultRow.className='OrangeBG';
    qd(''+ intResultBox + 'selResult' + selectedRowIdsurvey).checked=true;
  }
  else
  {
    currentResultRow.className=AssignedClass;
    qd(''+ intResultBox + 'selResult' + selectedRowIdsurvey).checked=false;
  }
  var LastSelectId;
  LastSelectId=	qd('hdnPreviousResultId'+ intResultBox).value;  
  if(LastSelectId!=0 && LastSelectId!=selectedRowIdsurvey)
  {
    qd(''+ intResultBox + 'tr' + LastSelectId).className = qd('hdnPreviousResultClass'+ intResultBox).value;
    qd(''+ intResultBox + 'selResult' + LastSelectId).checked=false;
	qd('shiftSearchSelect'+ intResultBox).disabled=false;
  }
  else if(LastSelectId==0)
   qd('shiftSearchSelect'+ intResultBox).disabled=false;
  else
   qd('shiftSearchSelect'+ intResultBox).disabled=true; 
   
  qd('hdnPreviousResultId'+ intResultBox).value =selectedRowIdsurvey;
  qd('hdnPreviousResultClass'+ intResultBox).value=AssignedClass;
}

function closeShiftSearchPopup()
{
  qd("ssBubbles").style.display = "none";
  qd("ssHelp").style.display == "none"
  qd("ssTerms").style.display = "none";
  qd("ssContents").style.display = "none";
  qd("ssError").style.display = "none";
  qd("ssClose").style.display = "none";
  qd("ssHelp").style.display = "none";
}

function selectShiftSelectJob(selectJob,intResultBox)
{
var showActiveText = true;
  if(typeof(ResulttextBoxId)=="object")
  {
  ResulttextBoxId.value=selectJob;
  ResulttextBoxId.style.color='black';
  ResulttextBoxId.style.textAlign= 'Left';
showActiveText = false;
 }
  else if(qd(ResulttextBoxId)!= null && qd(ResulttextBoxId)!= "")
  {
   qd(ResulttextBoxId).style.color='black';
   qd(ResulttextBoxId).style.textAlign= 'Left';
   qd(ResulttextBoxId).value=selectJob;
  }
  closeShiftSearchPopup();
    
  var docIframeControls = document.getElementsByTagName("iframe");
  var typeChecked = false;
  var inttmpElements=0;
  while(inttmpElements<docIframeControls.length) 
  {
    if(docIframeControls[inttmpElements].id.substr(0,17)=="ShiftSearchdialog")
      {
        var winDialogName=docIframeControls[inttmpElements].id.indexOf("_");        
        closeSwiftWindow(docIframeControls[inttmpElements].id.substr(0,winDialogName));
      }    
    inttmpElements++;
  } 
  if (showActiveText == true && ShowATbubbleOnResult==true && qd(ResulttextBoxId)!= null)
      qsCheckFind(qd(ResulttextBoxId));

}/*Shift Search ends*/
/*Function added in the DEVELOPER for showing the overlay screen over the entire screen
Displays the semi-transparent dialog cover*/
var coverShown = 0;
function showDialogCover(cntrlId) 
{
	coverShown += 1;
	hideAtWindow();
	showHideSelectBoxes(false,false);
	var dc = qd(cntrlId);
	dc.style.width = document.body.scrollWidth;		
	if (document.body.scrollHeight > document.body.offsetHeight)
		dc.style.height = document.body.scrollHeight; 
	else
	    dc.style.height = document.body.offsetHeight;
	
	dc.style.display = "inline";
	dc.style.background="white";
}
/*The dialog cover has been called only once, or this is the original dialog being hidden.*/
function hideDialogCover(cntrlId)
{
	showHideSelectBoxes(true,false);
	if (cntrlId==undefined)
	 qd("dialogCover").style.display = "none";
	else
	 qd(cntrlId).style.display = "none";
}

/*This function used in barcode page.*/
function popNotes(idSurvey, idEmployee) {	
idSurvey=idSurvey==undefined?'':idSurvey;
idEmployee=idEmployee==undefined?'':idEmployee;
screenX = (window.screen.width - 600)/2;
screenY = (window.screen.height - 500)/4;
try
{
 var notesPopup = window.open('../win/notes.aspx?idSurvey='+idSurvey+'&idEmployee='+idEmployee,'NotesPopupWindow','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=625,height=680,left='+screenX+',top='+screenY);
}
catch (err) 
{
 window.showModalDialog('../win/notes.aspx?idSurvey='+idSurvey+'&idEmployee='+idEmployee,'NotesPopupWindow', "maximize:yes;minimize:yes;dialogLeft:" + screenX+ ";dialogTop:" +screenY +";resizable:0;dialogWidth:625px;dialogHeight:680px");
}
notesPopup.focus();
}
/* These functions are used in Simple Project js.*/
function formatCurrencyStr(num) {
    if (num==null) {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 formatCurrency() {
    if(event)
    {
        var num = event.srcElement.value;
        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));
        event.srcElement.value = (((sign)?'':'-')  + num + '.' + cents);
    }
}
function isValidDate(dateStr) {
   var culture = SyncAjax(ActiveTextService.get_path() + "/GetApplicationSettings", "{name:'CultureName'}");
   var format = ""; 	
   if (culture.toLowerCase()=='en-us')
     format = "MDY";
   else
     format = "DMY";
     
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { 
      var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
      var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
   } else if (format.substring(1, 2) == "Y") { 
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
   } else { 
      var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
      var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
   }
   /* If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail*/
   if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { return false; }
   var parts = dateStr.split(RegExp.$1); 
   /* Split into 3 parts based on what the divider was
    Check to see if the 3 parts end up making a valid date*/
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

function atFindSurveyMultiTrip(showId, idSurvey)
{   
	bFromMultiTripPanel = true;
	
	if(idSurvey!=undefined) {
		atShowSurvey(idSurvey)
	} else if(showId!=null) {
		ActiveTextService.getRealId(showId,1,atShowId_cb)
	}
}
/*VerbalRequest Panel Functions*/
function vrClick(rowvalue1, panelMouseX, panelLeft, panelMouseY, panelTop)
{
   if (estimateShowId=='')
   {
        var hHeight;
        var headerHeight;
        
        if(typeof(headerId)=='undefined')
            headerHeight = 1;
        else
            headerHeight = qd(headerId).offsetHeight;
        
        
        if(headerHeight == ""  || headerHeight  == undefined)
            headerHeight = qd(cvlFreeheaderId).offsetHeight;


        var panelScrollTop;
        var panelScrollLeft;

        
        if(document.getElementById("divWebDesktop") != null)
        {
            panelScrollTop = document.getElementById("divWebDesktop").scrollTop;
	        panelScrollLeft = document.getElementById("divWebDesktop").scrollLeft;        
        }
        else
        {
            panelScrollTop = 0;
	        panelScrollLeft = 0;
        }

	    if (headerHeight==1)
	    hHeight = 116;
	    else
	    hHeight = 1;
    	
	    if (panelScrollTop == 0)
	         if (headerHeight == 116)
	            mouseY = panelTop + panelMouseY + document.body.scrollTop - 119 - hHeight ;
	         else
	            mouseY = panelTop + panelMouseY + document.body.scrollTop - hHeight ; 
	    else{
	        if (headerHeight == 116)
	            YPosition = panelTop + panelMouseY + document.body.scrollTop - 119 - hHeight ; 
	        else
	            YPosition = panelTop + panelMouseY + document.body.scrollTop -hHeight ;
    	        
	    mouseY = YPosition - panelScrollTop;
	    }
	    mouseX = panelLeft + panelMouseX + document.body.scrollLeft - panelScrollLeft;

	    forMapmouseX = panelLeft + panelMouseX;
	    forMapmouseY = panelTop + panelMouseY;
	}
	vrClickFunc(rowvalue1);
}
function vrClickFunc(rowvalue1)
{
    if(rowvalue1!="")
	{
		hideVRAtWindow();
		if(isNaN(mouseX))
		{
			document.getElementById(vratwId).style.left = 5;
	        document.getElementById(vratwId).style.top = 10;
		}
		else
		{
	        document.getElementById(vratwId).style.left = mouseX+5;
	        document.getElementById(vratwId).style.top = mouseY+10;		
		}
	    atShowVR(rowvalue1);
	} 
}
 
function atShowVR(idVR,hideSelect) {
	if(idVR == 0) return;
	    ActiveTextService.getVRInfo(idVR,atShowVR_cb);
} 
function atShowVR_cb(res)
{
    var RootNode;
    var redirectFlag = true;    
    if(res.error!=null)
    {
        msgbox(response.error,'vbOkOnly or vbWarning','Warning');
        return;
    }
    
    if(!(res != null && res.tables != 0 && res.tables.length ==1)) return;
        
    var cliinf;
    var row = res.tables[0].rows[0];	
    
    atLastIDVR = row.IDVerbalRequest;
    qd("vrreqMadeDate").innerHTML = row.Request_Made_Date;
    if (row.Request_Completion_Date == null)
       qd("vrreqCompDate").innerHTML="Not Specified"; 
    else
        qd("vrreqCompDate").innerHTML = row.Request_Completion_Date;
    if(row.companyname=='undefined' || row.companyname==null)
    {
        cliinf = '' + row.Client_Contact + "";
	}
    else
    {
        if(row.Client_Contact=='undefined' ||  row.Client_Contact=='' )
            cliinf = '' + row.companyname + '';
        else        
            cliinf = '' + row.companyname + '; ' + '' + row.Client_Contact + "" ;      
	}
    qd("vrreqCliInfCol21").innerHTML = n(cliinf);
    qd("vrreqCliNotesCol21").innerHTML = n(row.NoteText);
    
    currencySymbol = SyncAjax(ActiveTextService.get_path() + "/GetApplicationSettings", "{name:'CurrencySymbol'}");
    qd("vrreqestimatedCol22").innerHTML = currencySymbol + formatCurrencyStr(row.VerbalEstimatedCost);
	
    showHideFields(true);
    isClientLoggedIn=false;
    if(!isClientLoggedIn) {
	    document.getElementById(vratwId).style.display = "inline";
	    if (estimateShowId=='')
	    {
	      if((offY(document.getElementById(vratwId))+document.getElementById(vratwId).offsetHeight)>(document.body.offsetHeight+document.body.scrollTop)) {
		      document.getElementById(vratwId).style.top = (document.body.offsetHeight+document.body.scrollTop)-document.getElementById(vratwId).offsetHeight-10;
	      }

	      if((offX(document.getElementById(vratwId))+document.getElementById(vratwId).offsetWidth)>(document.body.offsetWidth+document.body.scrollLeft)) {
		      document.getElementById(vratwId).style.left = (document.body.offsetWidth+document.body.scrollLeft)-document.getElementById(vratwId).offsetWidth-10;
	      }
	    }
	    else
        {
          document.getElementById(vratwId).style.top="100px";
          document.getElementById(vratwId).style.left="660px";
        }
        
        estimateShowId='';
        showHideSelectBoxes(false,false);

	    atEvents.onSurveyShown();
	  }	
}
function onShowCMMenu()
 {
    if(document.getElementById('ISPopup_0') != null && event != null)
    {
        var CMX, CMY;
        if((event.clientX + document.getElementById('ISPopup_0').offsetWidth) > (document.body.offsetWidth + document.body.scrollLeft))
		    CMX = (document.body.offsetWidth + document.body.scrollLeft) - document.getElementById('ISPopup_0').offsetWidth - 10;
	    else
	        CMX = event.clientX + document.body.scrollLeft;
	    if((event.clientY + document.getElementById('ISPopup_0').offsetHeight) > (document.body.offsetHeight + document.body.scrollTop))
		    CMY = (document.body.offsetHeight + document.body.scrollTop) - document.getElementById('ISPopup_0').offsetHeight - 10;
	    else
	        CMY = event.clientY + document.body.scrollTop;
    	
	    setTimeout("document.getElementById('ISPopup_0').style.left = "+CMX+";");
        setTimeout("document.getElementById('ISPopup_0').style.top = "+CMY+";");
    } 
 }
 
function atPrintajenda() {
	//	window.open('../' + clsAppConfig.ClientCode + '/' + clsAppConfig.Idsite + '/attachments/agendas/AGENDA_' + atProjectId + '.pdf'); 
	//window.open("../main/printAgenda.aspx?idProject=" + atProjectId, "agenda"); 
	windowPopup("../main/printAgenda.aspx?idProject=" + atProjectId,screen.width*90/100,screen.height*80/100,1,1); 
}

function atPrintWorkorder() {
		//window.open('../' + clsAppConfig.ClientCode + '/' + clsAppConfig.Idsite + '/attachments/orders/ORDER_' + atProjectId+ '.pdf');
		//window.open("../main/printOrders.aspx?All=true&idProject=" + atProjectId);  
		windowPopup("../main/printOrders.aspx?All=true&idProject=" + atProjectId,screen.width*90/100,screen.height*80/100,1,1);  
}
function formatCurrency_Invoice(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));
    currencySymbol = SyncAjax(ActiveTextService.get_path() + "/GetApplicationSettings", "{name:'CurrencySymbol'}");
    return (((sign)?'':'-') + currencySymbol + num + '.' + cents);
}
/* -- 03-18-08.doc: QuotesRevision.Doc: [Brijesh] -- */
function IsProjectHasRevision(idsurvey){
    var IsProjectHasRevision = "false" ;
    if(idsurvey != "" && idsurvey != null && idsurvey != 'undefined'){
      IsProjectHasRevision = SyncAjax(ActiveTextService.get_path() + "/IsProjectHasRevision", "{ idSurvey:" + idsurvey + "}");
    }
    return IsProjectHasRevision;
}
function atRevisionStatement() 
{ 
  ActiveTextService.GetRevisionStatementDetails(atLastIdSurvey,atRevisionStatement_cb);
}
function atRevisionStatement_cb(ret)
{
  if(ret.rows != null && ret.rows != "")
   {
	window.open("../main/ViewRevisionStatement.aspx?id="+atLastIdSurvey,"ViewRevisionStatement",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=980,height=560');
   }
  else
   msgbox('This job does not have a Revision Statement.','vbOkOnly or vbInformation','Information');
}   
function atRevisionSummary() 
{ 
  ActiveTextService.GetRevisionSummary(atLastIdSurvey,atRevisionSummary_cb);
}
function atRevisionSummary_cb(ret)
{
  if(ret.rows != null && ret.rows != "")
   {
	window.open("../main/ViewRevisionSummary.aspx?id="+atLastIdSurvey,"ViewRevisionSummary",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1030,height=610');
   }
  else
   msgbox('This job does not have a Revision Statement.','vbOkOnly or vbInformation','Information');
}   
function atProjectSummary() 
{ 
  ActiveTextService.GetRevisionSummary(atLastIdSurvey,atProjectSummary_cb);
}
function atProjectSummary_cb(ret)
{
  if(ret.rows != null && ret.rows != "")
   {
	window.open("../main/ViewProjectSummary.aspx?id="+atLastIdSurvey,"ViewProjectSummary",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1200,height=700');
   }
  else
   msgbox('This job does not have a Project Summary.','vbOkOnly or vbInformation','Information');
}   
function atCreateNewFieldOrder()
{
    document.getElementById("LoadingOuterBox").style.display = "inline";	
	document.getElementById("LoadingOuterBox").style.zIndex = 9999;	
	document.getElementById("LoadingOuterBox").innerHTML = "";	
	document.getElementById("LoadingOuterBox").style.height=document.body.scrollHeight;
	document.getElementById("LoadingOuterBox").style.width=document.body.scrollWidth;
	document.getElementById("divNewFieldorderComments").style.display = "inline";
	document.getElementById("divNewFieldorderComments").style.zIndex = 999999;	
	ActiveTextService.GetNewFieldorderComments(atLastIdSurvey,GetNewFieldOrderComments_cb);
}
function GetNewFieldOrderComments_cb(res)
{
    qd("txtNewFieldorderComments").value = res;
} 
function SavetxtNewFieldorderComments()
{
    document.getElementById("divNewFieldorderComments").style.display = "none";
	document.getElementById("LoadingOuterBox").style.display = "none";
    ActiveTextService.SetNewFieldorderComments(atLastIdSurvey,qd("txtNewFieldorderComments").value,SavetxtNewFieldorderComments_cb);
}    
function CanceltxtNewFieldorderComments()
{
    document.getElementById("divNewFieldorderComments").style.display = "none";
	document.getElementById("LoadingOuterBox").style.display = "none";
}

function SavetxtNewFieldorderComments_cb()
{
    //parent.window.open("../main/printMultipleJobs.aspx?NewFieldOrder=1&print=" + atLastIdSurvey + "&createpdf=1&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close();</script>")));
    parent.windowPopup("../main/printMultipleJobs.aspx?NewFieldOrder=1&print=" +atLastIdSurvey+ "&createpdf=1&redir=" + escape("../message.aspx?msg=" +escape("<script>window.close()</script>"))+"",300,100,0);
}


function atPreBillingWorksheet() 
{
    //show popup doc - 9-22-08.docx (1)
    var showPreBillingPopup;
    showPreBillingPopup = readCookie("PreBillingPopupCookie");

    if (showPreBillingPopup == null || showPreBillingPopup == "" || showPreBillingPopup == "0")
    {
        //window.showModalDialog('../win/PreBillingWorksheetPopup.htm','Information', "center:yes;status:no;unadorned:no;resizable:0;dialogWidth:400px;dialogHeight:150px");
        window.showModalDialog('../win/PreBillingWorksheetPopup.asp','Information', "center:yes;status:no;unadorned:no;resizable:0;dialogWidth:400px;dialogHeight:150px");
        
    }
    windowPopup("../reports/PreBillingWorkSheet.aspx?idSurveyList="+atLastIdSurvey,screen.width*97/100,screen.height*85/100,1,1);
}
