/* this is for Year to Date report* **/var GLOBALreportTotal = "0";var GLOBALTotalBO = "0";var GLOBALTotalScrns = "0";var GLOBALLastTotalBO = "0";var GLOBALLastTotalScrns = "0";function calculateTotal(BO, Scrns, lastBO, lastScrns, Amount) {		GLOBALTotalBO = (parseFloat(GLOBALTotalBO) + parseFloat(BO));	GLOBALTotalScrns = (parseFloat(GLOBALTotalScrns) + parseFloat(Scrns));	GLOBALLastTotalBO = (parseFloat(GLOBALLastTotalBO) + parseFloat(lastBO));	GLOBALLastTotalScrns = (parseFloat(GLOBALLastTotalScrns) + parseFloat(lastScrns));	GLOBALreportTotal = (parseFloat(GLOBALreportTotal) + parseFloat(Amount));}function displayTotal() {	if (GLOBALTotalBO != "0")	{		document.write("<tr><td></td><td></td><td></td><td></td>");		document.write("<td>"+formatCurrency(parseFloat(GLOBALTotalBO)) +"</td>");		var diff = ((parseFloat(GLOBALTotalBO) / parseFloat(GLOBALLastTotalBO)) - 1) * 100;		document.write("<td>"+roundWhole(diff)+"%</td>");;		document.write("<td>"+roundNumber(GLOBALTotalScrns) +"</td>");		var avg = (parseFloat(GLOBALTotalBO) / parseFloat(GLOBALTotalScrns));		document.write("<td>"+roundNumber(avg)+"</td>");		var scrnsDiff = (parseFloat(GLOBALTotalScrns) - parseFloat(GLOBALLastTotalScrns));		document.write("<td>"+scrnsDiff+"</td>");		document.write("<td>&nbsp;</td>");		document.write("<td>&nbsp;</td></tr>");	}}function changeYTDReportView(form, url) {	if (form.ViewMonth.value == "") {	if (form.ViewType[0].checked==true) form.action = "/"+url+"/BOYTD-Dist?OpenView";	else form.action = "/"+url+"/BOYTD?OpenView";	} else form.action = "/"+url+"/BOYTD-Month?OpenView";}function resetDisplay() {	eform = document.all;	eform.exportButton.disabled = true;	eform.loadingTimes.value = "done";}/***disable the excel export button when the it first loaded***/function disableStart() {	eform = document.all;	if (eform.loadingTimes.value =="" ) eform.exportButton.disabled = true;}/* this is for upcoming report / Market Share Report* **/function changeView(form, url, viewName) {if ((form.ViewMonth.value == "" || form.ViewMonth.value == "All") && (form.ViewYear.value == "" || form.ViewYear.value == "All")) {	form.action = "/"+url+"/"+viewName+"?OpenView";} else if (form.ViewYear.value == "" || form.ViewYear.value == "All") {	form.action = "/"+url+"/"+viewName+"-month?OpenView";} else if (form.ViewYear.value != "" && form.ViewMonth.value != "" && form.ViewYear.value != "All" && form.ViewMonth.value != "All") {	form.action = "/"+url+"/"+viewName+"-yearmonth?OpenView";} else form.action = "/"+url+"/"+viewName+"-year?OpenView";}/*** check if the user has the admin role**/function isAdminRole(eform) {			roles = eform.UserRoles.value;	if (roles.indexOf("Admin") > -1) return true;	return false;}function ReportSearch() {	eform = document.forms[0]	//eform = document.all;	var param = ""	searchString = ""	viewPath = ""	accessDistributors = ""	var distArray = [];		param = "&report=" + eform.report.value;	if (eform.report.value.indexOf('WKLY') > -1) {		fromDate = eform.ViewDateRange.value				//searchString = "[DateTo]<=" + fromDate			fromYear = fromDate.substr(6, 4)		fromMonth = fromDate.substr(3, 2)		fromDay = fromDate.substr(0, 2)				//alert(fromDay + "." + fromMonth + "." + fromYear)				dateFrom = new Date(fromYear, fromMonth-1, fromDay, "23", "59");		dateFrom = new Date(dateFrom.valueOf() - (6 * 24 * 60 * 60 * 1000))				//alert(dateFrom.getDate() + "/" + (dateFrom.getMonth()+1) + "/" + dateFrom.getFullYear())				searchString = "[DateTo]<=" + fromDate + " AND " + "[DateTo]>=" + dateFrom.getDate() + "/" + (dateFrom.getMonth()+1) + "/" + dateFrom.getFullYear()				//alert(searchString)		//return false	}	else if (eform.report.value.indexOf("TC_") > -1) {		if (eform.report.value == "TC_VARIANCE") {			if (eform.State != null && eform.State.value != "" && eform.State.value != "All States") {				searchString = "[State]=" + eform.State.value				param = param + "&State=" + eform.State.value;			}				if (eform.Theatres != null && eform.Theatres.value != "" && eform.Theatres.value != "All Theatres") {				searchString = searchString + " AND [Theatre]=" + eform.Theatres.value				param = param + "&Theatres=" + eform.Theatres.value;			}		} else		if ( !isAdminRole(eform) )		{			searchString = "([DISTRIBUTOR]=\""+eform.DistName.value+"\"";			accessDistributors = (eform.AccessDistributors == null) ? "" : eform.AccessDistributors.value;			if (accessDistributors != "") {				distArray = accessDistributors.split(";");				//some users can see other distributors check list				n = 0				while (n < distArray.length) {					eachDist = Trim(distArray[n]);					searchString = searchString + " OR [DISTRIBUTOR]=\""+eachDist+"\"";					n = n + 1				}			} //accessDistributors != ""			searchString = searchString + ") "			if (eform.ViewYear != null && eform.ViewYear.value != "") searchString = searchString + " AND [CheckYear]=\"" + eform.ViewYear.value + "\"";		} else			if (eform.ViewYear != null && eform.ViewYear.value != "") searchString = searchString + "[CheckYear]=\"" + eform.ViewYear.value + "\"";	}			if (eform.ViewYear != null && eform.ViewYear.value != "") param = param + "&ViewYear=" + eform.ViewYear.value;	//if the user enters a month then has to enter a year as well	if (eform.ViewMonth != null && eform.ViewMonth.value != "" && eform.ViewYear.value == "")	{		param = param + "&ViewMonth=" + eform.ViewMonth.value;		alert("Please select the year as well to generate a report");		eform.ViewYear.focus();		return false;	} else if (eform.ViewMonth != null && eform.ViewMonth.value != "") {			param = param + "&ViewMonth=" + eform.ViewMonth.value;		searchString = searchString + " AND [CheckMonth]=\"" + eform.ViewMonth.value + "\""	}	//for weekly report - thurs, wkend and wk	if (eform.ViewWeek != null && eform.ViewWeek.value != "")	{		wkType = eform.ViewWeek.value;		wkType = wkType.toUpperCase();				if (wkType == "THURSDAY")			 wkType = "Thurs"		else if (wkType == "WEEKEND")			 wkType = "Wkend"		else			 wkType = "Wk"		param = "&report=wkly"+wkType;		if (eform.ViewYear != null && eform.ViewYear.value != "") param = param + "&ViewYear=" + eform.ViewYear.value;			 		param = param + "&ViewWeek=" + eform.ViewWeek.value + "&ViewDateRange=" + eform.ViewDateRange.value;		searchString = searchString + " AND NOT[Search"+wkType+"BO]=0"		//check the screens		if (eform.ViewScreens != null && eform.ViewScreens.value != "" && eform.ViewScreens.value != "All")		{		//SearchThursScrns				if (eform.ViewScreens.value == "<50")					searchString = searchString + " AND [Search"+wkType+"Scrns]<=50"				else // >50					searchString = searchString + " AND [Search"+wkType+"Scrns]"+eform.ViewScreens.value				param = param + "&ViewScreens="+eform.ViewScreens.value;		}		viewPath = "/"+eform.DBName.value+"/web\\weekly"+wkType+"Report";	}		//we want to return all record if none is selected	if (searchString == "") searchString = "[SearchTxt]=\"ALL\"";//	eform.ShowReport.onclick();		if (searchString) {		location.href = viewPath+"?SearchView&loadingTimes=done&SearchOrder=4&Start=1&Count=999"+param+"&Query=" + searchString;	}}/**** use this agent to pass params and so that* the agent can calculates the values and return back to the browser***/var responseText = "";function callAgent() {	var server = document.all.ServerName.value;	var path = document.all.DBName.value;	var ViewYear = document.all.ViewYear.value;	var ViewMonth = document.all.ViewMonth.value;	var ViewDist = "";	var ViewMP = "";	var ViewAction = "";	var ViewDiscrepancy = "";	var ViewCSS = "";		//Give the user something nice to look at	displayWindow = window.open('','displayWindow','width=400,height=200,left=400,top=200,screenX=400,screenY=200,z-index=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no')	displayWindow.document.write("<span style=\"color : #666;font-weight: bold;font-size: 12px;font-family: Helvetica, Arial, sans-serif;\">Please Wait</span><br><br>");	displayWindow.document.write("<img width='400' src='"+server + path + "/loading.gif'>");	if (document.all.ViewDist != null) ViewDist = document.all.ViewDist.value;	if (document.all.ViewMP != null) ViewMP = document.all.ViewMP.value;	if (document.all.ViewAction != null) ViewAction = document.all.ViewAction.value;	if (document.all.ViewDiscrepancy != null && document.all.ViewDiscrepancy.checked) ViewDiscrepancy = document.all.ViewDiscrepancy.value;	if (document.all.ViewCSS != null) ViewCSS = document.all.ViewCSS.value;	//if the user enters a month then has to enter a year as well	if (ViewMonth != null && ViewMonth != "" && ViewYear == "")	{		alert("Please select the year as well to generate a report");		document.all.ViewYear.focus();		return false;	} 		var ReportName = document.all.ReportName.value;	var sUsername = document.all.sUsername.value;	var report = document.all.report.value;		//Call the agent	var objDOM = new ActiveXObject("Microsoft.XMLDOM")	objHTTP = new ActiveXObject("Microsoft.XMLHTTP");	strUrl = server + path + '/GetTheatreCheckReport?OpenAgent&ViewYear='+ViewYear+'&ViewMonth='+ViewMonth+	'&report='+report+'&sUsername='+sUsername;	if (ViewDist != "") strUrl = strUrl + "&ViewDist="+ViewDist;	if (ViewMP != "") strUrl = strUrl + "&ViewMP="+ViewMP;	if (ViewAction != "") strUrl = strUrl + "&ViewAction="+ViewAction;	if (ViewDiscrepancy != "") strUrl = strUrl + "&ViewDiscrepancy="+ViewDiscrepancy;	if (ViewCSS != "") strUrl = strUrl + "&ViewCSS="+ViewCSS;		objHTTP.open("POST", strUrl, false, "", "");	objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	objHTTP.send(objDOM);	response = objHTTP.responseText;	displayWindow.close();//	alert(" response "+response);	section = document.getElementById("billings-table");	lastRow = section.rows.length - 1;	section.rows(lastRow).cells(0).innerHTML = response;//	document.write(response);//	document.forms[0].Content.value = response;//	document.forms[0].DisplayContent.value = response;//	document.forms[0].displayMsg.value = "Your report has been emailed to "+response;	document.forms[0].loadingTimes.value = "done";	document.forms[0].exportButton.disabled = false;//	alert("SDF "+document.forms[0].loadingTimes.value);	objHTTP = null;}function RefreshForm() {	eform = document.all	eform.ShowReport.onclick();}var rankingCounter = 1;function RankingCounter() {	document.write(rankingCounter++);}function generateXMLReport() {	var server = document.all.ServerName.value;	var path = document.all.DBName.value;	//Build up the XML object to pass to the agent	var uniqueIDs = document.getElementsByName("UniqueID");	var ViewYear = document.getElementsByName("ViewYear");	var ViewMonth = document.getElementsByName("ViewMonth");	var ReportName = document.getElementsByName("ReportName");	var sUsername = document.getElementsByName("sUsername");	var report = document.getElementsByName("report");	var ViewDist = document.getElementsByName("ViewDist");	var ViewMP = document.getElementsByName("ViewMP");	var ViewCSS = document.getElementsByName("ViewCSS");	var ViewAction = document.getElementsByName("ViewAction");	var ViewDiscrepancy = document.getElementsByName("ViewDiscrepancy");		//Give the user something nice to look at	displayWindow = window.open('','displayWindow','width=400,height=200,left=400,top=200,screenX=400,screenY=200,z-index=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no')	displayWindow.document.write("<span style=\"color : #666;font-weight: bold;font-size: 12px;font-family: Helvetica, Arial, sans-serif;\">Please Wait</span><br><br>");	displayWindow.document.write("<img width='400' src='"+server + path + "/loading.gif'>");		var objDOM = new ActiveXObject("Microsoft.XMLDOM")	RootEl = objDOM.createNode(1, "RootElement", "")	objDOM.documentElement = RootEl	if (uniqueIDs.length == null)	{		objHeaders = objDOM.createNode(1, "XMLEntry", "")		objHeaders.text = uniqueIDs.value		RootEl.appendChild(objHeaders)	}	else	{		for (var i = 0; i < uniqueIDs.length; i++)		{			objHeaders = objDOM.createNode(1, "XMLEntry", "")			objHeaders.text = uniqueIDs[i].value			RootEl.appendChild(objHeaders)		}	}	objHeaders = objDOM.createNode(1, "ViewYear", "")	objHeaders.text = ViewYear[0].value	RootEl.appendChild(objHeaders)	objHeaders = objDOM.createNode(1, "ViewMonth", "")	objHeaders.text = ViewMonth[0].value	RootEl.appendChild(objHeaders)	objHeaders = objDOM.createNode(1, "ReportName", "")	objHeaders.text = ReportName[0].value	RootEl.appendChild(objHeaders)	objHeaders = objDOM.createNode(1, "sUsername", "")	objHeaders.text = sUsername[0].value	RootEl.appendChild(objHeaders)	objHeaders = objDOM.createNode(1, "report", "")	objHeaders.text = report[0].value	RootEl.appendChild(objHeaders)	if (ViewDist[0] != null) {		objHeaders = objDOM.createNode(1, "ViewDist", "")		objHeaders.text = ViewDist[0].value		RootEl.appendChild(objHeaders)	}	if (ViewMP[0] != null) {		objHeaders = objDOM.createNode(1, "ViewMP", "")		objHeaders.text = ViewMP[0].value		RootEl.appendChild(objHeaders)	}	if (ViewCSS[0] != null) {		objHeaders = objDOM.createNode(1, "ViewCSS", "")		objHeaders.text = ViewCSS[0].value		RootEl.appendChild(objHeaders)	}	if (ViewAction[0] != null) {		objHeaders = objDOM.createNode(1, "ViewAction", "")		objHeaders.text = ViewAction[0].value		RootEl.appendChild(objHeaders)	}	if (ViewDiscrepancy[0] != null) {		objHeaders = objDOM.createNode(1, "ViewDiscrepancy", "")		objHeaders.text = ViewDiscrepancy[0].value		RootEl.appendChild(objHeaders)	}	//Call the agent	objHTTP = new ActiveXObject("Microsoft.XMLHTTP");	strUrl = server + path + '/ExportXMLReport?OpenAgent';	objHTTP.open("POST", strUrl, false, "", "");	objHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	objHTTP.send(objDOM);	response = objHTTP.responseText;	displayWindow.close();	document.forms[0].displayMsg.value = "Your report has been emailed to "+response;	objHTTP = null;}