function show(idString){
		element = document.getElementById(idString);
		element.style.display="block";
}

function hide(idString){
		element = document.getElementById(idString);
		element.style.display="none";
}

function showMenu(idString){
	hide('menuProject');
	hide('menuPublisher');
	hide('menuAdministrator');
	hide('menuProfile');
	hide('menuAlert');
	hide('menuReport');
	hide('menuIncidence');
	show(idString);
}
		
			function changeFieldsData()
			{
				var x=document.getElementById("varStatus");
				var status = x.value;
					
					var currencyName = document.getElementById("varCurrencyName"+status);
					var x1=document.getElementById("varCurrencyName");
					if (x1)
					{
						if ( currencyName.value != "varCurrencyName"+status)
							x1.value = currencyName.value;
						else
						{
							x1.value = "";
						}
							
					}
					
					var currencyValue = document.getElementById("varCurrencyValue"+status);
					var x=document.getElementById("varCurrencyValue");
					if (x)
					{
						if ( currencyValue.value != "varCurrencyValue"+status)
							x.value = currencyValue.value;
						else
						{
							x.value = "";
						}
					}
					
					var rewardType = document.getElementById("varRewardType"+status);
					var x=document.getElementById("varRewardType");
					if (x)
					{
						if ( rewardType.value == '1')
						{
							x.selectedIndex = 0;
						}
						else if ( rewardType.value == '2')
						{
							x.selectedIndex = 1;
						}
						else if (rewardType.value == '3')
						{
							x.selectedIndex = 2;
						}
						
						if (x1.value == "")
							x.selectedIndex = 0;
					}
					
					var rewardOccurrence = document.getElementById("varRewardOccurrence"+status);
					var x=document.getElementById("varRewardOccurrence");
					if (x)
					{
						x.selectedIndex = rewardOccurrence.value-1;
						if (x.selectedIndex < 0 || x.selectedIndex > 9)
							x.selectedIndex = 0;
					}
			}

			
			function makeQueryString(id)
			{
					
				var x=document.getElementById("varPublisherId");
				document.form1.action = "?id="+ id + "&publisherId=" + x.value;
			}
			
			/********** FUNCTION BELOW ARE TO BE USED BY offerBillingApproval.php *******************
			Created By: Ahmer Sultan
			Date Created: 02-19-2008
			*/
			// for trimming the string ... 
			function strtrim(string)
			{ 
				   //Remove leading spaces
				   while(string.charAt(0) == " ")
				      string = string.substring(1, string.length);
				
				   //Remove trailing spaces
				   while(string.charAt(string.length-1) == " ")
				      string = string.substring(string, string.length-1);
				
				   return string;
			}		
				
				
			// Adds the goods sold data on the table .. updates the respective hidden fields.
			function addInGoodsSold()
			{
				
				var table = document.getElementById("goodsSoldTable");
				var completePriceText = document.getElementById("completePrice");
				var completeCountText = document.getElementById("completeCount");
				
				if ( strtrim(completePriceText.value) == '' || strtrim(completeCountText.value) == '')
				{
					alert('Some of the input is missing!');
					return;
				}
				if ( isNaN(completePriceText.value) || isNaN(completeCountText.value))
				{
					alert('Some of the input is invalid!');
					return;
				}
				
				var publisherDD = document.getElementById("varPublisherId");
				var publisherId = publisherDD.value;
				var publisherName = publisherDD.options[publisherDD.selectedIndex].text;
				
				var ok = isPublisherAdded(publisherId);
				if ( ok == 1)
				{
					alert('This publisher has already been added');
					return;
				}
				
				var rowCount = 0;
				var rows = table.rows;
				var id =  rows.length + 1;
				
				//alert(id);
				var row = table.insertRow(0);
				row.id = "row_"+id;
						
				var p=row.insertCell(0);
				var c = row.insertCell(1)
				var mc=row.insertCell(2);
				var pc=row.insertCell(3);
				var mcp = row.insertCell(4);
				var ml = row.insertCell(5);
				var b = row.insertCell(6);
				//setting widths
				p.width = "300";
				c.width = "30";
				c.align = "right";
				mc.width = "85";
				pc.width = "30";
				mcp.width = "30";
				ml.align = "right";
				ml.width = "180";
				b.width = "130";
				b.align="right";
				
				mc.innerHTML =" completes @ $ ";
				mcp.innerHTML = " CPI ";
				
				
				var hiddenPub = "<input type='hidden' name='u_"+row.id+"' id='u_"+row.id+"' value='"+ publisherId+ "'/>";
				p.innerHTML = publisherId + " - " + publisherName + hiddenPub;
						
				
				var count = completeCountText.value;
				var price = completePriceText.value;
				
				var mul = Number(count) * Number(price);
				mul = roundUptoTwoPlaces(mul);
				var hiddenMul = "<input type='hidden' id='m_"+row.id+"' value='"+ mul+ "'/>";
				ml.innerHTML = "$" + mul + hiddenMul;
				
				var hiddenCount = "<input type='hidden' id='c_"+row.id+"' name='c_"+row.id+"' value='"+ count+ "'/>";
				var hiddenPrice = "<input type='hidden' id='p_"+row.id+"' name='p_"+row.id+"' value='"+ price+ "'/>";
				
				c.innerHTML = count + hiddenCount;
				pc.innerHTML = price + hiddenPrice;
							
				b.innerHTML = '<input type="button" value="edit" id="myButton" onclick="modifyTableRow(\''+ row.id + '\',\'goodsSoldTable\')"/> <input type="button" value="delete" id="deleteButton" onclick="deleteTableRow(\''+ row.id + '\',\'goodsSoldTable\')"/>';
				//updateApprovedTotalCompletes(count,1);
				//updateRevenues(mul,1);
				updateCOGS(mul,1);
				clearCountPriceTextBoxes();
			}
			
			
			// Enables to modify a row for the goods sold data.
			function modifyTableRow(rowId,targetTable)
			{
				//alert("modifying " + rowId );
				var count = document.getElementById("c_"+rowId);
				var price = document.getElementById("p_"+rowId);
				
				var row = document.getElementById(rowId);
				
				var hiddenCount = document.getElementById("c_"+rowId);
				var hiddenPrice = document.getElementById("p_"+rowId);
				
				var hiddenCountS = "<input type='hidden' id='c_"+row.id+"' name='c_"+row.id+"' value='"+ hiddenCount.value+ "'/>";
				var hiddenPriceS = "<input type='hidden' id='p_"+row.id+"' name='p_"+row.id+"' value='"+ hiddenPrice.value+ "'/>";
				
				var countInput = "<input  class='border inputField30' type='text' class='border inputField100' id='i_c_"+row.id+"' value='"+ count.value+ "'/>";
				var priceInput = "<input  maxlength='5'  class='border inputField30' type='text' class='border inputField100' id='i_p_"+row.id+"' value='"+ price.value+ "'/>";
				
				row.cells[1].innerHTML = countInput + hiddenCountS;
				row.cells[3].innerHTML = priceInput + hiddenPriceS; 
				
				row.cells[6].innerHTML = '<input type="button" value="save" id="myButtonS" onclick="saveTableRow(\''+ row.id + '\',\''+targetTable+'\')"/>';
				
			}
			
			
			// Save the modified data for the goods sold.
			function saveTableRow(rowId,targetTable)
			{
				//alert("saving3" + rowId);
				var count = document.getElementById("i_c_"+rowId);
				var price = document.getElementById("i_p_"+rowId);
				if ( strtrim(count.value) == '' || strtrim(price.value) == '')
				{
					alert('Some of the input is missing!');
					return;
				}
				
				if ( isNaN(count.value) || isNaN(price.value))
				{
					alert('Some of the input is invalid!');
					return;
				}
					
				var hiddenCountS = "<input type='hidden' id='c_"+rowId+"' name='c_"+rowId+"' value='"+ count.value+ "'/>";
				var hiddenPriceS = "<input type='hidden' id='p_"+rowId+"' name='p_"+rowId+"' value='"+ price.value+ "'/>";
				var hiddenCount = document.getElementById("c_"+rowId);
				var hiddenMul = document.getElementById("m_"+rowId);
				if ( targetTable == "goodsSoldTable")
				{
					updateCOGS(Number(hiddenMul.value),0);
				}
				else if (targetTable == "revenueTable")
				{
					updateApprovedTotalCompletes(hiddenCount.value,0);
					updateRevenues(Number(hiddenMul.value),0);
				}
						
				var row = document.getElementById(rowId);
				
				var mul = count.value* price.value;
				mul = roundUptoTwoPlaces(mul);
				var hiddenMulS = "<input type='hidden' id='m_"+row.id+"' value='"+ mul+ "'/>";
				
				row.cells[1].innerHTML = count.value + hiddenCountS;
				row.cells[3].innerHTML = price.value + hiddenPriceS;
				row.cells[5].innerHTML = "$"+mul + hiddenMulS;
			
				row.cells[6].innerHTML = '<input type="button" value="edit" id="myButton" onclick="modifyTableRow(\''+ row.id + '\',\''+targetTable+'\')"/> <input type="button" value="delete" id="deleteButton" onclick="deleteTableRow(\''+ row.id + '\',\''+targetTable+'\')"/>';
				if ( targetTable == "goodsSoldTable")
				{
					updateCOGS(mul,1);
				}
				else if (targetTable == "revenueTable")
				{
					updateApprovedTotalCompletes(count.value,1);
					updateRevenues(mul,1);
				}
				
			}
			
			// Updates the total completes being displayed in the goods sold section
			function updateApprovedTotalCompletes(updateCount,addOrSubtract)
			{
				var  y = document.getElementById("completeTag");
				var hC = document.getElementById("varApprovedCompletes");
				//var rows = document.getElementById("goodsSoldTable").rows;
				var rows = document.getElementById("revenueTable").rows;
				var count = Number(y.innerHTML);
				
				if ( addOrSubtract == 1)
					y.innerHTML = count + Number(updateCount);
				else 
					y.innerHTML = count - Number(updateCount);
				hC.value = y.innerHTML;
			}
			
			// Clears out the text boxes for inputting the goods sold infoo
			function clearCountPriceTextBoxes()
			{
				var completePriceText = document.getElementById("completePrice");
				var completeCountText = document.getElementById("completeCount");
				
				completePriceText.value = "";
				completeCountText.value = "";
			}
			
			// Clears out the text boxes for the inputting revenue info.
			function clearCountPriceRTextBoxes()
			{
				var completePriceText = document.getElementById("completePriceRevenue");
				var completeCountText = document.getElementById("completeCountRevenue");
				
				completePriceText.value = "";
				completeCountText.value = "";
			}
			
			// deletes the row in the goods sold.
			function deleteTableRow(rowId,targetTable)
			{
				//var table = document.getElementById("goodsSoldTable");
				var table = document.getElementById(targetTable);
				var row = document.getElementById(rowId);
				var count = document.getElementById("c_" + rowId);
				var mulH = document.getElementById("m_"+rowId);
				var c = Number(count.value);
				if ( targetTable == "goodsSoldTable")
				{
					updateCOGS(Number(mulH.value),0);
				}
				else if (targetTable == "revenueTable")
				{
					updateApprovedTotalCompletes(c,0);
					updateRevenues(Number(mulH.value),0);
				}
				
				table.deleteRow(row.rowIndex);
			}
	
			/// updates the cost of goods sold.
			function updateCOGS(total, addOrSubtract)
			{
				var c = document.getElementById("costOfGoodsTag");
				var hC = document.getElementById("varCostOfGoodsSold");
				var count = Number(hC.value);
				if ( addOrSubtract == 1)
				{
					count = count + Number(total);
				}
				else
				{
					count = count - Number(total);
				}
				hC.value = roundUptoTwoPlaces(count);
				c.innerHTML = "$"+hC.value;
				updateNetRevenue();
			}
			
			function updateNetRevenue()
			{
				var hC = document.getElementById("varCostOfGoodsSold");
				var hG = document.getElementById("varGrossRevenue");
				var hN = document.getElementById("varNetRevenue");
				
				hN.value = roundUptoTwoPlaces(Number(hG.value) - Number(hC.value));
				var n = document.getElementById("netRevenueTag");
				var g = document.getElementById("grossRevenueTag");
				var c = document.getElementById("costOfGoodsTag");
				c.innerHTML = "$"+hC.value;
				g.innerHTML = "$"+hG.value;
				n.innerHTML = "$"+hN.value;
			}
			
			
			/// updates the revenues displayed in the lower right hand corner.			
			function updateRevenues(updateTotal,addOrSubtract)
			{				
				
				var hY = document.getElementById("varCostOfGoodsSold");
				var hG = document.getElementById("varGrossRevenue");
				var hN = document.getElementById("varNetRevenue");
				
				var gross = Number(hG.value);
			
				if ( addOrSubtract == 1)
				{
					gross = gross + Number(updateTotal);
				}
				else
				{
					gross = gross - Number(updateTotal);
				}
				gross = roundUptoTwoPlaces(gross);
				var costOfGoodsSold = Number(hY.value);
				var net = gross - costOfGoodsSold;
				
	
				hG.value = roundUptoTwoPlaces(gross);
				hN.value = roundUptoTwoPlaces(net);
				
				updateNetRevenue();
			}
			
			// Checks if a publisher has already been added in the goods sold.
			function isPublisherAdded(pubId)
			{
				var rows = document.getElementById("goodsSoldTable").rows;
				var str = "";
				for ( r in rows)
				{
					var row = rows[r];
					if ( row && row.id != undefined)
					{
						var pub = document.getElementById("u_"+row.id);
						if ( pub != null )
						{
							if ( pub.value == pubId)
								return 1;
						}
					}
				}
				return 0;
				
			}
			
			// to be called by the form submit.. to check the input of the approved stats
			function approvedInputsCorrect()
			{
				var as = document.getElementById("varApprovedScreenouts");
				var ad = document.getElementById("varApprovedDropouts");
				var ao = document.getElementById("varApprovedOverquotas");
				
				if ( strtrim(as.value) == "" || strtrim(ad.value) == "" || strtrim(ao.value) == "")
				{
					alert("Some of the approved stats input is missing!");
					return false;
				}
				
				if ( isNaN(as.value) ||  isNaN(ad.value) ||  isNaN(ao.value))
				{
					alert("Some of the approved stats input is invalid!")
					return false;
				}
				
				return true;
			}
			// rounding decimal upto two places
			function roundUptoTwoPlaces(original)
			{
				var result=Math.round(original*100)/100;
				return result;
				//return original;
			}
			function addInRevenue()
			{
				
				var table = document.getElementById("revenueTable");
				var completePriceRText = document.getElementById("completePriceRevenue");
				var completeCountRText = document.getElementById("completeCountRevenue");
				
				if ( strtrim(completePriceRText.value) == '' || strtrim(completeCountRText.value) == '')
				{
					alert('Some of the input is missing!');
					return;
				}
				if ( isNaN(completePriceRText.value) || isNaN(completeCountRText.value))
				{
					alert('Some of the input is invalid!');
					return;
				}
				
				var rowCount = 0;
				var rows = table.rows;
				var id =  rows.length + 1;
				
				//alert(id);
				var row = table.insertRow(0);
				row.id = "Rrow_"+id;
						
				var pR=row.insertCell(0); // this is blank now
				var cR = row.insertCell(1)
				var mcR=row.insertCell(2);
				var pcR=row.insertCell(3);
				var mcpR = row.insertCell(4);
				var mlR = row.insertCell(5);
				var bR = row.insertCell(6);
				//setting widths
				pR.width = "320";
				cR.width = "30";
				cR.align = "right";
				mcR.width = "85";
				pcR.width = "30";
				mcpR.width = "30";
				mlR.align = "right";
				mlR.width = "180";
				bR.width = "130";
				bR.align="right";
				
				mcR.innerHTML =" completes @ $ ";
				mcpR.innerHTML = " CPI ";
				
				
										
				
				var count = completeCountRText.value;
				var price = completePriceRText.value;
				var mul = Number(count) * Number(price);
				mul = roundUptoTwoPlaces(mul);
				var hiddenMul = "<input type='hidden' id='m_"+row.id+"' value='"+ mul+ "'/>";
				mlR.innerHTML = "$" + mul + hiddenMul;
				
				var hiddenCount = "<input type='hidden' id='c_"+row.id+"' name='c_"+row.id+"' value='"+ count+ "'/>";
				var hiddenPrice = "<input type='hidden' id='p_"+row.id+"' name='p_"+row.id+"' value='"+ price+ "'/>";
				
				cR.innerHTML = count + hiddenCount;
				pcR.innerHTML = price + hiddenPrice;
							
				bR.innerHTML = '<input type="button" value="edit" id="myButton" onclick="modifyTableRow(\''+ row.id + '\',\'revenueTable\')"/> <input type="button" value="delete" id="deleteButton" onclick="deleteTableRow(\''+ row.id + '\',\'revenueTable\')"/>';
				updateApprovedTotalCompletes(count,1);
				updateRevenues(mul,1);
				clearCountPriceRTextBoxes();
			}
	
			
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function confirmLaunch(id)
	{
		var answer = confirm("Do you want to confirm the project is ready for launch?");
		if (answer)
			window.location = "?cmd=pl_cmd_ready_for_launch&id="+Number(id);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//TO BE USED ON offerRegister.php	
	function switchOptimusMode()
	{
		document.getElementById("varOptimusModeBlock").disabled = !document.getElementById("varActivateOptimus").checked;
		document.getElementById("varOptimusModeDetect").disabled = !document.getElementById("varActivateOptimus").checked;
	}
	
	function changeNielsenOffer(){
		var offers = document.getElementById('varOfferId');
		var offerId = offers.options[offers.selectedIndex].value;
		top.location = '?offerId='+offerId;
	}
	
	
	
	function changeNielsenData()
	{
		var x=document.getElementById("varRewardType");
		var type = x.value;
			
		var payout = document.getElementById("varPayout"+type);
		var x1=document.getElementById("varPayout");
		if(payout.value.indexOf('var')!=-1)
			x1.value = '';
		else
			x1.value = payout.value;
		
		var startTime = document.getElementById("varStartTime"+type);
		var x=document.getElementById("varStartTime");
		if(startTime.value.indexOf('var') == -1)
			x.value = startTime.value;
		
		var endTime = document.getElementById("varEndTime"+type);
		var x=document.getElementById("varEndTime");
		if(endTime.value.indexOf('var') == -1)
			x.value = endTime.value;
	}
	
	
	function changeProfileSurvey(){
		var surveys = document.getElementById('varProfileSurvey');
		var advertiserId = surveys.options[surveys.selectedIndex].value;
		top.location = '?id='+advertiserId;
	}
	
	
	function changeRecruitmentOffer(){
		var offers = document.getElementById('varProjectId');
		var offerId = offers.options[offers.selectedIndex].value;
		top.location = '?id='+offerId;
	}

	function checkIsValid(invite){
		
		var email = document.getElementById("email-"+invite.id);		
		
		if(invite.checked == true){
			email.disabled = false;			
		}
		else{
			email.disabled = true;
			email.checked = false;
		}
	}
	
	
	
	function validateStreetAddress(street,zipcode){
		
		var streetRegex = new RegExp('^[0-9]+[ ]+[a-zA-Z0-9]+[a-zA-Z0-9 ]+$');
		var zipcodeRegex = new RegExp('^[0-9]{5,5}$');
		
		if (street.match(streetRegex) && zipcode.match(zipcodeRegex)) {
		    return true;
	    } else {
	    	alert("Please Enter a valid Street Address (e.g: 2000 Broadway St) and 5 digit US Zipcode.");
	    }
		
		return false;
	}