// JavaScript Document
 
			
//cal			


 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep' ,'Oct', 'Nov', 'Dec'];
 var dueDateCal;
 var dueDateCal1;
 var dueDateCal2;
 var funcToRun=null;
 var defaultCreditDays=0;
 var tabIds = new Array();
 var textBoxToLabelHolder = new Object();
 var selectedCustomerObjid = null;
 var checkDirtyForm = false;
 
 var selectedCustomerValue=null;

 
 var selectTariffObjId=null;
 var selectSettingsObjId=null;
 var selectReportsObjId=null;
 var selectContactsObjId=null;
 
 var accountExpired=null;
 
 
 var accountIDUsed=0;
 var callLaterArray = new Array();
 
 
 
 function checkExpiryDateVal()
 {
	 if(accountExpired)
	 {
		 return false;
	 }
	 else
	 {
		 return true;
	 }
	 
 }
 
 
 
 function loadCustomer()
 {
	 
	 var createBillCustomerText = document.getElementById('customerNameNew');
	 
	 if(createBillCustomerText !=null)
	 {
		 selectedCustomerValue=createBillCustomerText.value;
		 
	 }	 
	 
	 navigate('customers','TAB');
	 
	 chooseTab('custTabL');
	 
	 if(selectedCustomerValue !=null || selectedCustomerValue=="")
	 {
		 setTimeout("valueExg(selectedCustomerValue)",500);
		 
	 }
	 
 }
 
 function valueExg(val)
 {

	 var createCustomerDiv=document.getElementById('createCustomer');
	 
	 if(createCustomerDiv !=null)
	 {
		 
		 createCustomerDiv.style.display="";
	 }
	 
	
	 var createCompanyNameText = document.getElementById('createCompanyName'); 
	 
	 if(val !=null)
	 {
			 
		createCompanyNameText.value= val;
	 }
		 
	 selectedCustomerValue=null;
	 
	 
 }
 
 
 
 
 function selectedCustomer(objid)
 {
	 if(selectedCustomerObjid != null)
	 {
		var selectedCustomerObj = document.getElementById(selectedCustomerObjid);
		if(selectedCustomerObj != null)
			selectedCustomerObj.className="linkblack";
	 }
	 if(objid != null)
	 {
		 var obj = document.getElementById(objid);
		 
		 if(obj !=null)
		 {
			obj.className ="selectedLink";
			 
			 
			selectedCustomerObjid = objid;
		 }
	 }

 }
 

 
 function selectedOptions(tabName,objid)
 {
	 
	 if(tabName=="settings")
	 {
		var selectedOptionObjId=selectSettingsObjId;
	 }
	 else if(tabName=="tariff")
	 {
		
		var selectedOptionObjId=selectTariffObjId;
		 
	 }
	 else if(tabName=="reports")
	 {
		var selectedOptionObjId=selectReportsObjId;
	 }
	 
	 if(selectedOptionObjId != null)
	 {
		var selectedOptionObj = document.getElementById(selectedOptionObjId);
		if(selectedOptionObj != null)
			 //alert(selectedOptionObjId);
			selectedOptionObj.className="linkblack";
	 }
	 if(objid != null)
	 {
		 var obj = document.getElementById(objid);
		 
		 if(obj !=null)
		 {
			 
			obj.className ="selectedLink";
			selectedOptionObjId = objid;
			
			if(tabName=="settings")
			{
			selectSettingsObjId=selectedOptionObjId;
			}
			else if(tabName=="tariff")
			{
			selectTariffObjId=selectedOptionObjId;
			}
			else if(tabName=="reports")
			{
			selectReportsObjId=selectedOptionObjId;
			}
		 }
	 }
	 
	 
 }
 
 function selectedContacts(objid)
 {
	 if(selectContactsObjId != null)
	 {
		var selectContactsObj = document.getElementById(selectContactsObjId);
		if(selectContactsObj != null)
			selectContactsObj.className="normaltext";
	 }
	 if(objid != null)
	 {
		 var obj = document.getElementById(objid);
		 
		 if(obj !=null)
		 {
			obj.className ="selectedLink";
			 
			 
			selectContactsObjId = objid;
		 }
	 }

 }
 
 function selectedBills(objid)
 {
	 if(selectContactsObjId != null)
	 {
		var selectContactsObj = document.getElementById(selectContactsObjId);
		if(selectContactsObj != null)
			selectContactsObj.className="normaltext";
	 }
	 if(objid != null)
	 {
		 var obj = document.getElementById(objid);
		 
		 if(obj !=null)
		 {
			obj.className ="selectedLink";
			 
			 
			selectContactsObjId = objid;
		 }
	 }
	 
	 
	 
 }
 
 
 
 
 
 
 
 
 //tabIds.inited = false;
 function chooseTab(tabName)
 {
	 
		 initTabIds();
	 
	 for (var i=0;i<tabIds.length ;i++ )
	 {
		 if(tabIds[i].obj != null && tabIds[i].name == tabName)
		 {
			 //alert(tabName);
			//alert(tabIds[i].obj.className)
				try
				{
			tabIds[i].obj.removeClassName(tabIds[i].className);		
			tabIds[i].obj.addClassName(tabIds[i].selectedClassName);
				}
				catch (error)
				{
					tabIds[i].obj.className = tabIds[i].selectedClassName;
				}
			
			
			
			//alert(tabIds[i].obj.className)
		 }
		 else
		 {
			 try
			 {
				tabIds[i].obj.removeClassName(tabIds[i].selectedClassName);
			tabIds[i].obj.addClassName(tabIds[i].className);	 
			 }
			 catch (error)
			 {
				tabIds[i].obj.className = tabIds[i].className;
			 }
			
		 }
	 }
	 
	 //alert(tabAnchor);
	// alert(document.getElementById(tabAnchor));
	//document.getElementById(tabAnchor).removeClassName("Tabcustomer");
	 //document.getElementById(tabAnchor).addClassName("TabcustomerSelected");
//	 	 alert(tabAnchor.className);
 }
 function initTabIds()
 {
	 tabIds[0] = {name:"custTabL",obj:document.getElementById('custTabL'),className:'Tabcustomer', selectedClassName:'TabcustomerSelected'};
	  tabIds[1] = {name:"payTabL",obj:document.getElementById('payTabL'),className:'Tabpayment', selectedClassName:'TabpaymentSelected'};
	   tabIds[2] = {name:"repTabL",obj:document.getElementById('repTabL'),className:'Tabreport', selectedClassName:'TabreportSelected'};
	    tabIds[3] = {name:"tarTabL",obj:document.getElementById('tarTabL'),className:'Tabtariff', selectedClassName:'TabtariffSelected'};
		 tabIds[4] = {name:"setTabL",obj:document.getElementById('setTabL'),className:'Tabsetting', selectedClassName:'TabsettingSelected'};
		  
 }
 function createNewBillsDate()
 {
	
	var poDateCal2 = new dhtmlxCalendarObject('poDate2');
	poDateCal2.setDateFormat('%d %b %Y');
	var poDatevalue = document.getElementById('poDate2').value;
	if(poDatevalue != "")
	{
		poDateCal2.setDate(new Date(Date.parse(poDatevalue)));
	}
	var billDateCal2 = new dhtmlxCalendarObject('billDate2');
	billDateCal2.setDateFormat('%d %b %Y');
	billDateCal2.attachEvent("onClick", billDateSelected2);
	var billDatevalue = document.getElementById('billDate2').value;
	if(billDatevalue != "")
	{
		billDateCal2.setDate(new Date(Date.parse(billDatevalue)));
	}
	dueDateCal2 = new dhtmlxCalendarObject('dueDate2');
	dueDateCal2.setDateFormat('%d %b %Y');
	dueDateCal2.attachEvent("onClick", dueDateSelected2);
	var dueDatevalue = document.getElementById('dueDate2').value;
	if(dueDatevalue != "")
	{
		dueDateCal2.setDate(new Date(Date.parse(dueDatevalue)));
		}
 }

 function createUpdateBillsDate()
 {
	 var poDateCal1 = new dhtmlxCalendarObject('poDate1');
		poDateCal1.setDateFormat('%d %b %Y');
		var poDatevalue = document.getElementById('poDate1').value;
		if(poDatevalue != "")
		{
			poDateCal1.setDate(new Date(Date.parse(poDatevalue)));
		}
		var billDateCal1 = new dhtmlxCalendarObject('billDate1');
		billDateCal1.setDateFormat('%d %b %Y');
		billDateCal1.attachEvent("onClick", billDateSelected1);
		var billDatevalue = document.getElementById('billDate1').value;
		if(billDatevalue != "")
		{
			billDateCal1.setDate(new Date(Date.parse(billDatevalue)));
		}
		dueDateCal1 = new dhtmlxCalendarObject('dueDate1');
		dueDateCal1.setDateFormat('%d %b %Y');
		dueDateCal1.attachEvent("onClick", dueDateSelected1);
		var dueDatevalue = document.getElementById('dueDate1').value;
		if(dueDatevalue != "")
		{
			dueDateCal1.setDate(new Date(Date.parse(dueDatevalue)));
		}
 }
 
 var searchCal = null;
function createBillPageDates(onlyBill)
{
	if(onlyBill == null)
		onlyBill = false;
	if(document.getElementById('poDate')!=null)
	{
		var poDateCal = new dhtmlxCalendarObject('poDate');
		poDateCal.setDateFormat('%d %b %Y');
	}
	if(document.getElementById('billDate')!=null)
	{
		var billDateCal = new dhtmlxCalendarObject('billDate');
		billDateCal.setDateFormat('%d %b %Y');
		billDateCal.attachEvent("onClick", billDateSelected);
	}

	//cal1 = setTimeout("new dhtmlxCalendarObject('poDate').setDateFormat('%d %b %Y')",200);
	//cal2 = setTimeout("new dhtmlxCalendarObject('billDate').setDateFormat('%d %b %Y')",200);
	if(document.getElementById('dueDate')!=null)
	{
		dueDateCal = new dhtmlxCalendarObject('dueDate');
		dueDateCal.setDateFormat('%d %b %Y');
		dueDateCal.attachEvent("onClick", dueDateSelected);
	}
	if(onlyBill)
		return ;

	if(document.getElementById('paymentDate')!=null)
	{
		var paymentDateCal = new dhtmlxCalendarObject('paymentDate');
		paymentDateCal.setDateFormat('%d %b %Y');
		var today = new Date();
		paymentDateCal.setDate(today);
	}
	if(document.getElementById('chequeDate')!=null)
	{
		var cheqDate = new dhtmlxCalendarObject('chequeDate');
		var today = new Date();
		cheqDate.setDate(today);
		cheqDate.setDateFormat('%d %b %Y');
	}
	
	if( document.getElementById('fromDate') == null ||  document.getElementById('toDate')==null)
		return;
	searchCal = new dhtmlxDblCalendarObject('dhtmlxDblCalendar', false, {
	        isMonthEditable: true,
	        isYearEditable: true
	    });
	 searchCal.setYearsRange(1980, 2020);
	 searchCal.setDateFormat("%d/%m/%Y");
	 
	 var todayDate = new Date(); ;
	 var oneMonthAgo = new Date(todayDate.getTime()-24*60*60*30*1000);
	 
	 
	 var cal_fromDate=(oneMonthAgo.getDate()<10?'0':'')+''+oneMonthAgo.getDate()+'/'+((oneMonthAgo.getMonth()+1)< 10?'0':'')+(oneMonthAgo.getMonth()+1)+'/'+oneMonthAgo.getFullYear();
	 var cal_toDate=(todayDate.getDate()<10?'0':'')+''+todayDate.getDate()+'/'+((todayDate.getMonth()+1)< 10?'0':'')+(todayDate.getMonth()+1)+'/'+todayDate.getFullYear();
	 
	 //searchCal.setDate(cal_fromDate, cal_toDate);
	//alert ((oneMonthAgo.getMonth()+1) +'    '+ (todayDate.getMonth()+1));
	searchCal.leftCalendar.setDate(cal_fromDate);
	searchCal.rightCalendar.setDate(cal_toDate);
	 
	 
	 var fromDateInput = document.getElementById('fromDate');
	 fromDateInput.value=(oneMonthAgo.getDate()<10?'0':'')+''+oneMonthAgo.getDate()+' '+ months[oneMonthAgo.getMonth()]+' '+oneMonthAgo.getFullYear();
	 var toDateInput = document.getElementById('toDate');
	 toDateInput.value =(todayDate.getDate()<10?'0':'')+''+todayDate.getDate()+' '+ months[todayDate.getMonth()]+' '+todayDate.getFullYear();;
	 
	 searchCal.leftCalendar.attachEvent("onClick", searchDateLeftSelected);
	 searchCal.rightCalendar.attachEvent("onClick", searchDateRightSelected);
	 
	
	
}
function searchDateLeftSelected(fromDate)
{
	
	var fromDateInput = document.getElementById('fromDate');
	if(fromDateInput != null)
	{
	var dateLeft = new Date(Date.parse(searchCal.leftCalendar.getDate()));
	fromDateInput.value=(dateLeft.getDate()<10?'0':'')+''+dateLeft.getDate()+' '+ months[dateLeft.getMonth()]+' '+dateLeft.getFullYear();
	}
	
	//alert(' from date = '+new Date(Date.parse(searchCal.rightCalendar.getDate())));
}
function searchDateRightSelected(toDate)
{

	var toDateInput = document.getElementById('toDate');
	if(toDateInput != null)
	{
		var dateRight=new Date(Date.parse(searchCal.rightCalendar.getDate()));
		toDateInput.value = (dateRight.getDate()<10?'0':'')+''+dateRight.getDate()+' '+ months[dateRight.getMonth()]+' '+dateRight.getFullYear();
	}
	
}
 function  createReportPageDates()
 {
 	var poDateCal = new dhtmlxCalendarObject('billdateafter');
 	poDateCal.setDateFormat('%d %b %Y');
 	var billDateCal = new dhtmlxCalendarObject('billdatebefore');
 	billDateCal.setDateFormat('%d %b %Y');
 	//billDateCal.attachEvent("onClick", billDateSelected);
 	//cal1 = setTimeout("new dhtmlxCalendarObject('poDate').setDateFormat('%d %b %Y')",200);
 	//cal2 = setTimeout("new dhtmlxCalendarObject('billDate').setDateFormat('%d %b %Y')",200);
 	
 	
 }
 function billDateSelected2(date)
{
	
	if(document.getElementById('billDate2') == null)
		return;
	var billdatevalue = document.getElementById('billDate2').value;
	
	if(billdatevalue=="")
    	return;
   
	if(document.getElementById('creditDays2')==null)
    	return;
	var creditdays = document.getElementById('creditDays2').value;
	
	if(creditdays == "")
		return;
	
	var dateToFormat = (new Date(Date.parse(billdatevalue)+creditdays*24*60*60*1000));
	
	if(dueDateCal2 != null)
		dueDateCal2.setDate(dateToFormat);
}
function dueDateSelected2(date)
{
	if(document.getElementById('billDate2') == null)
		return;
	var billdatevalue = document.getElementById('billDate2').value;
	if(billdatevalue=="")
    	return;
	var creditdays = document.getElementById('creditDays2');
	if(creditdays == null)
		return;
	if(document.getElementById('dueDate2') == null)
		return;
	var dueDate = document.getElementById('dueDate2').value;
	if(dueDate=="")
    	return;
	var credDysMs = Date.parse(dueDate) - Date.parse(billdatevalue);
	var cd = credDysMs/(24*60*60*1000);
	creditdays.value = cd > 0 ? cd:0;
}
function billDateSelected(date)
{
	if(document.getElementById('billDate') == null)
		return;
	var billdatevalue = document.getElementById('billDate').value;
    if(billdatevalue=="")
    	return;
    if(document.getElementById('creditDays')==null)
    	return;
	var creditdays = document.getElementById('creditDays').value;
	if(creditdays == "")
		return;
	var dateToFormat = (new Date(Date.parse(billdatevalue)+creditdays*24*60*60*1000));
	if(dueDateCal != null)
		dueDateCal.setDate(dateToFormat);
}
function dueDateSelected(date)
{
	if(document.getElementById('billDate') == null)
		return;
	var billdatevalue = document.getElementById('billDate').value;
	if(billdatevalue=="")
    	return;
	var creditdays = document.getElementById('creditDays');
	if(creditdays == null)
		return;
	if(document.getElementById('dueDate') == null)
		return;
	var dueDate = document.getElementById('dueDate').value;
	if(dueDate=="")
    	return;
	var credDysMs = Date.parse(dueDate) - Date.parse(billdatevalue);
	var cd = credDysMs/(24*60*60*1000);
	creditdays.value = cd > 0 ? cd:0;
}
function billDateSelected1(date)
{
	if(document.getElementById('billDate1') == null)
		return;
	var billdatevalue = document.getElementById('billDate1').value;
    if(billdatevalue=="")
    	return;
    if(document.getElementById('creditDays1')==null)
    	return;
	var creditdays = document.getElementById('creditDays1').value;
	if(creditdays == "")
		return;
	var dateToFormat = (new Date(Date.parse(billdatevalue)+creditdays*24*60*60*1000));
	if(dueDateCal != null)
		dueDateCal1.setDate(dateToFormat);
}
function dueDateSelected1(date)
{
	if(document.getElementById('billDate1') == null)
		return;
	var billdatevalue = document.getElementById('billDate1').value;
	if(billdatevalue=="")
    	return;
	var creditdays = document.getElementById('creditDays1');
	if(creditdays == null)
		return;
	if(document.getElementById('dueDate1') == null)
		return;
	var dueDate = document.getElementById('dueDate1').value;
	if(dueDate=="")
    	return;
	var credDysMs = Date.parse(dueDate) - Date.parse(billdatevalue);
	var cd = credDysMs/(24*60*60*1000);
	creditdays.value = cd > 0 ? cd:0;
}
function paymentModeChanged(payMode)
{

	if(payMode == null)
		return;

	//this.options[this.selectedIndex].value
	if(payMode.options == null)
		return;

	var selection = payMode.selectedIndex+1;
	var cc = document.getElementById('cc');
	var dd = document.getElementById('dd');
	var cheque = document.getElementById('cheque');
	var ddcheque = document.getElementById('ddcheque');
	var bankdetails= document.getElementById('bankdetails');
	var wt= document.getElementById('wt');
	var lc= document.getElementById('lc');
	if(cc == null || dd == null || cheque == null || ddcheque == null ||bankdetails==null || wt==null || lc==null)
		return;

	var block = "block";
	var none = "none";
	
	switch(selection)
	{
	case 2: //cc selected
			cc.style.display=block;
			dd.style.display = none;
			cheque.style.display = none;
			ddcheque.style.display = none;
			bankdetails.style.display = none;
			wt.style.display =none;
			lc.style.display = none;
			clearInputTags('paymentForm',['paymentDate']);
			break;
	case 3: // cheque selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = block;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate']);
		break;
	case 4: // dd selected
		cc.style.display=none;
		dd.style.display = block;
		cheque.style.display = none;
		ddcheque.style.display = block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate']);
		break;
	case 5://wt selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = none;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =block;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate']);
		break;
		
	case 6://lc selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = none;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = block;
		clearInputTags('paymentForm',['paymentDate']);
		break;
	default:
		cc.style.display=none;
		ddcheque.style.display = none;
		dd.style.display = none;
		cheque.style.display = none;
		bankdetails.style.display = none;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate']);
	break;
	
	}
	
	
}


function advpaymentModeChanged(payMode)
{

	if(payMode == null)
		return;

	//this.options[this.selectedIndex].value
	if(payMode.options == null)
		return;

	var selection = payMode.selectedIndex+1;
	var cc = document.getElementById('cc');
	var dd = document.getElementById('dd');
	var cheque = document.getElementById('cheque');
	var ddcheque = document.getElementById('ddcheque');
	var bankdetails= document.getElementById('bankdetails');
	var wt= document.getElementById('wt');
	var lc= document.getElementById('lc');
	if(cc == null || dd == null || cheque == null || ddcheque == null ||bankdetails==null || wt==null || lc==null)
		return;

	var block = "block";
	var none = "none";
	
	switch(selection)
	{
	case 2: //cc selected
			cc.style.display=block;
			dd.style.display = none;
			cheque.style.display = none;
			ddcheque.style.display = none;
			bankdetails.style.display = none;
			wt.style.display =none;
			lc.style.display = none;
			clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
			break;
	case 3: // cheque selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = block;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
		break;
	case 4: // dd selected
		cc.style.display=none;
		dd.style.display = block;
		cheque.style.display = none;
		ddcheque.style.display = block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
		break;
	case 5://wt selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = none;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =block;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
		break;
		
	case 6://lc selected
		cc.style.display=none;
		dd.style.display = none;
		cheque.style.display = none;
		ddcheque.style.display =block;
		bankdetails.style.display = block;
		wt.style.display =none;
		lc.style.display = block;
		clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
		break;
	default:
		cc.style.display=none;
		ddcheque.style.display = none;
		dd.style.display = none;
		cheque.style.display = none;
		bankdetails.style.display = none;
		wt.style.display =none;
		lc.style.display = none;
		clearInputTags('paymentForm',['paymentDate','refNumber','amountText']);
	break;
	
	}
	
	
}




function checkPassword(formId,pw1,pw2)
{
	
	var pwd1Obj = document.getElementById(pw1);
	var pwd2Obj = document.getElementById(pw2);
	
	if(pwd1Obj == null || pwd2Obj == null)
	{
		
		return false;
	}
	pass1 = pwd1Obj.value;
	pass2 = pwd2Obj.value;
	
	if (pass1 != pass2) 
	{
	
		var passwordMsg=document.getElementById('passwordError');
		if(passwordMsg !=null)
		{
			passwordMsg.style.display="";
			//alert ("in pwd error");
		}
		// alert ("\nYou did not enter the same new password twice. Please re-enter your password.")
		
		return false;
	}
	else 
	{
		var passwordMsg= document.getElementById('passwordError');
			if(passwordMsg !=null)
			{
			passwordMsg.style.display="none";
			}
		return true;
	}
}

function checkUpdateUserPassword(formId,pw1,pw2)
{
	
	var pwd1Obj = document.getElementById(pw1);
	var pwd2Obj = document.getElementById(pw2);
	
	if(pwd1Obj == null || pwd2Obj == null)
	{
		
		return false;
	}
	pass1 = pwd1Obj.value;
	pass2 = pwd2Obj.value;
	
	if (pass1 != pass2) 
	{
	
	var passwordMsg=document.getElementById('passwordError1');
	if(passwordMsg !=null)
	{
		passwordMsg.style.display="";
	
	}
	// alert ("\nYou did not enter the same new password twice. Please re-enter your password.")
	
	return false;
	}
	else 
	{
		var passwordMsg= document.getElementById('passwordError1');
		if(passwordMsg !=null){passwordMsg.style.display="none";}
		return true;
	}
}


function createUserChecks(formId,formsubmitAction,password,repassword,fname,username,useremail,errormsg)
{
	if(checkForMandatoryFields([fname,username,useremail,password,repassword],useremail,errormsg))
		{
			if(checkPassword(formId,password,repassword))
			{
				submitData(formId,formsubmitAction);
					
			}
		}
	
}

	


function checkAmountPending()
{

	var amountText=document.getElementById('amountText');
	var hiddenAmountPending= document.getElementById('hiddenAmountPending');
	var saveButton =document.getElementById('saveButton');
	var num1 = Number(amountText.value);
	var num2 = Number(hiddenAmountPending.value);
	
	//alert(""+num1  + "   " +num2);
	if(num1>num2)
	{

		alert('Payment amount must not be more than the pending amount');
		//saveButton.disabled =true;
	}
	else
	{
		try
		{
		  document.paymentForm.onsubmit(); 
		}
		catch(error)
		{
		  alert("Not Submitted");	
		}
		 
	}
	
}

function checkAmountPendingForUpdate()
{

	var amountText2=document.getElementById('amountText2');
	var hiddenAmountPending= document.getElementById('hiddenAmountPending');
	var hiddenAmount=document.getElementById('hiddenAmount');
	
	
	var num1=Number(amountText2.value);
	var num2=Number(hiddenAmount.value);
	
	var num3=Number(hiddenAmountPending.value);
	
	var subtractedAmt=num1-num2;
	if(subtractedAmt>num3)
	{
		alert('Payment amount must not be more than the pending amount');
		
	}
	else
	{
		
		//if(document.updatePaymentForm1.onsubmit())
		 //{
			
			
		    //alert(hiddenAmount.value + 'After Putting' + amountText2.value );
			hiddenAmount.value=amountText2.value;
		
			document.updatePaymentForm1.onsubmit(); 
		    //alert(hiddenAmount.value);
		    
		 //}
		//alert('i never went inseide');
	}
	
}




function paymentModeChangedForUpdate(payMode2)
{
	
	if(payMode2 == null)
		return;

	//this.options[this.selectedIndex].value
	if(payMode2.options == null)
		return;
	
	
	
	
	
	var selection2 = payMode2.selectedIndex+1;
	var cc2 = document.getElementById('cc2');
	var dd2 = document.getElementById('dd2');
	var cheque2 = document.getElementById('cheque2');
	var ddcheque2 = document.getElementById('ddcheque2');
	var bankdetails2= document.getElementById('bankdetails2');
	var wt2= document.getElementById('wt2');
	var lc2= document.getElementById('lc2');
	if(cc2 == null || dd2 == null || cheque2 == null || ddcheque2 == null ||bankdetails2==null || wt2==null || lc2==null)
	return;	

	var block = "block";
	var none = "none";

		switch(selection2)
		{
		case 2: //cc selected
				cc2.style.display=block;
				dd2.style.display = none;
				cheque2.style.display = none;
				ddcheque2.style.display = none;
				bankdetails2.style.display = none;
				wt2.style.display =none;
				lc2.style.display = none;
				clearInputTags('updatePaymentForm1',['paymentDate2']);
				break;
		case 3: // cheque selected
			cc2.style.display=none;
			dd2.style.display = none;
			cheque2.style.display = block;
			ddcheque2.style.display =block;
			bankdetails2.style.display = block;
			wt2.style.display =none;
			lc2.style.display = none;
			clearInputTags('updatePaymentForm1',['paymentDate2']);
			break;
		case 4: // dd selected
			cc2.style.display=none;
			dd2.style.display = block;
			cheque2.style.display = none;
			ddcheque2.style.display = block;
			bankdetails2.style.display = block;
			wt2.style.display =none;
			lc2.style.display = none;
			clearInputTags('updatePaymentForm1',['paymentDate2']);
			break;
		case 5://wt selected
			cc2.style.display=none;
			dd2.style.display = none;
			cheque2.style.display = none;
			ddcheque2.style.display =block;
			bankdetails2.style.display = block;
			wt2.style.display =block;
			lc2.style.display = none;
			clearInputTags('updatePaymentForm1',['paymentDate2']);
			break;
			
		case 6://lc selected
			cc2.style.display=none;
			dd2.style.display = none;
			cheque2.style.display = none;
			ddcheque2.style.display =block;
			bankdetails2.style.display = block;
			wt2.style.display =none;
			lc2.style.display = block;
			clearInputTags('updatePaymentForm1',['paymentDate2']);
			break;
		default:
			cc2.style.display=none;
			ddcheque2.style.display = none;
			dd2.style.display = none;
			cheque2.style.display = none;
			bankdetails2.style.display = none;
			wt2.style.display =none;
			lc2.style.display = none;
			clearInputTags('updatePaymentForm1',['paymentDate2']);
		break;
		
		}
	
	
}








function verifyStringLength(event,textInput,length)
{
	//alert('in');
	
	var toRet = validatePinCode(event,textInput,length);
	return toRet;
	
	
}


//promptText home
function promptTextFunction()
{
	promptTextFunction2('form.awesome1');
	promptTextFunction2('form.awesome2');
	promptTextFunction2('form.awesome3');
}
 function promptTextFunction2(nameOfFormClass){
    // alert('vaibhav');
	  // Select all textboxes and assign them to an array
	  var textboxes = $$(nameOfFormClass+' input.input-text1');

	  // Iterate through all textboxes in the form
	  textboxes.each(function(input, index){
		

	    var label = input.previous();
	    textBoxToLabelHolder[input.id] = label;
	    // TimedObserver to check for autocomplete	
		try
		{
			
			if (index == 0){
				new Form.Observer(input.up('form'), 0.1, function(form, value) {
				  			textboxes.each(function(inputX){
											if(inputX == null ||inputX.value ==null || inputX.previous()==null)
												return;
										  if (!inputX.value.empty()) {
													   try
													   {
														inputX.previous().addClassName('hastext1');   
													   }
													   catch (error)
													   {
														 inputX.previous().className = 'hastext1';
													   }
														
										  }
							});
			  });
			}	
		}
		catch (error)
		{
			//do nothing
		}
	    

	    // Fade the label back when a field gains focus		
	    input.onfocus = function(){
	      if (input.value.empty()){
		   // alert(label.className);
		   try
		   {
			label.removeClassName('overlay1');
	        label.addClassName('focus1');
	       // alert(label.className);
		   }
		   catch (error)
		   {
			   label.className = 'focus1';
		   }
		    
	           
	      }
	    }

	    // Check if a field is empty when the user switches out
	    input.onblur = function(){
			 
	      if (input.value.empty()){
			  try
			  {
				    label.removeClassName('focus1').removeClassName('hastext1');  
			label.addClassName('overlay1');
	    
			  }
			  catch (error)
			  {
				  label.className = 'overlay1';
			  }
			  
	      //alert('remove');        
	      }
	      // Fade the label back if a field has text
	      if (!input.value.empty()) {
		    	label.style.border="1px solid #32343d";
				try
				{
					label.removeClassName('focus1').removeClassName('overlay1');
			  label.addClassName('hastext1');	
				}
				catch (error)
				{
					label.className='hastext1';
				}
				if(input.id && input.id == 'projectNameNew')
			  {
					setTimeout("submitSingleField(['"+input.id+"'],'checkprojectexists',null)",500);
							
			  }  
			  	if(input.id && input.id == "updateProjectName")
			  	{
					setTimeout("submitSingleField(['"+input.id+"'],'checkprojectexistsupdateform',null)",500);
			  		//submitSingleField([input.id],'checkprojectexistsupdateform',null);
			  	}
			  	
			  	if(input.id && input.id == "customerNameNew")
			  	{
					setTimeout("submitSingleField(['"+input.id+"'],'checkcustomerexists',null)",1500);
			  		//submitSingleField([input.id],'checkprojectexistsupdateform',null);
					
					
			  	}
			  	if(input.id && input.id == "domainNameId")
			  	{
			  		setTimeout("getSubDomain()",500);
			  	}
			  	
			  	
		     
		    }
	    }
	    // Fade the label back if a field has text
	      if (!input.value.empty()) {
		    	label.style.border="1px solid #222222";
				try{

		        label.removeClassName('focus1').removeClassName('overlay1');
			  label.addClassName('hastext1');
				}
				catch(error)
				{

					label.className = 'hastext1';
				}
		     
		    }  
	   // Fade the label back when the user starts to type		
	    input.onkeypress = function(){
			try
			{
				label.removeClassName('focus1').removeClassName('overlay1');
	         label.addClassName('hastext1');	
			}
			catch (error)
			{
				label.className = 'hastext1';
			}
			 
	    };
	  });
	}
 
 
 function changeValuePending()
 {
	 
	 
	 var billValueText =document.getElementById("billValue");
	 var amountReceivedText =document.getElementById("amountRecvd");
	 var penAmtLabel =document.getElementById("penAmt");
	 
	 var amtReceive=amountReceivedText.value;
	 var billVal=billValueText.value;
	 
	 
	 
	 if(billValueText!=null)
	 {
		 
		 penAmtLabel.innerHTML=  billVal - amtReceive;
		
		 
	 }
	 amtReceive="";
	 billVal="";
	 
 }
 
 
 function changeUpdateValuePending()
 {
	 var billValueText =document.getElementById("updatebillValue");
	 var amountReceivedText =document.getElementById("updateAmountRecvd");
	 var penAmtLabel =document.getElementById("pendingInEditId");
	 
	 var amtReceive=amountReceivedText.value;
	 var billVal=billValueText.value;
	 
	 
	 
	 if(billValueText!=null)
	 {
		 
		 penAmtLabel.innerHTML=  billVal - amtReceive;
		
		 
	 }
	 amtReceive="";
	 billVal="";
	 
	 
	 
	 
	 
 }
 
 function changeUpdateValuePendingFromCreateBill()
 {
	 var billValueText =document.getElementById("billValue1");
	 var amountReceivedText =document.getElementById("amountRecvdCreate");
	 var penAmtLabel =document.getElementById("pendingInEditIdBill");
	 
	 var amtReceive=amountReceivedText.value;
	 var billVal=billValueText.value;
	 
	 
	 
	 if(billValueText!=null)
	 {
		 
		 penAmtLabel.innerHTML=  billVal - amtReceive;
		
		 
	 }
	 amtReceive="";
	 billVal="";
	 
	 
	 
	 
	 
 }
 
 
 
 function createNewContactsFromDropDown()
 {
	 var contactPopUp =document.getElementById("contactpopup");
	 
		if(contactPopUp !=null)
		{
			contactPopUp.style.display="";
			dobj = contactPopUp;
		}	
 }
 
function setDropDownValueInHidden(selectComp,idOfHidden,contactPopUp)
{
  if(selectComp.options[selectComp.selectedIndex].value== -999)
	{
		 if(createNewContactsFromDropDown)
			 createNewContactsFromDropDown();
	}
	var objOfHidden = document.getElementById(idOfHidden);
	if(selectComp == null)
		return;

	if(objOfHidden == null)
		return;
	//this.options[this.selectedIndex].value
	if(selectComp.options == null)
		return;
	objOfHidden.value = selectComp.options[selectComp.selectedIndex].value;
	
	
}

function showDefaultButton()
{    
	var showMakeDefault=document.getElementById('createNewContacts')
	
	if(showMakeDefault!=null)
	{   
		
		var defaultLabel = document.getElementById('defaultLabel')
		if(defaultLabel!=null)
		{
			defaultLabel.style.display="none";	
		}
		
		document.getElementById('showMakeDefault').style.display="";
			 
	}
}	

var flagForPwd=1;
function showPasswordBox()
{
	
	var editPwdLabel2=document.getElementById('editPwdLabel')
	
	if(editPwdLabel2 !=null)
	{
		if(flagForPwd==1)
		{
			var pwdDiv = document.getElementById('divPwd')
			if(pwdDiv!=null)
			{
				pwdDiv.style.display="";	
			}
			
			flagForPwd=0;
		}
		else
		{

			var pwdDiv = document.getElementById('divPwd')
			if(pwdDiv!=null)
			{
				pwdDiv.style.display="none";	
			}
			
			flagForPwd=1;
			
		}
					
		
	}
}



function hideDeletedSalesRep(salesRepId)
{
	//alert(salesRepId);
    var deletedSalesRepDiv=document.getElementById(salesRepId);
   
	if(deletedSalesRepDiv!=null)
	{   
	
	   deletedSalesRepDiv.style.display="none";
		
			 
	}
	
	
	
}


function changeHiddenMakeBossVal()
{
	var showMakeB=document.getElementById('showMakeBoss');
	var makeBoss = document.getElementById('hiddenMakeBoss');
	if(showMakeB!=null)
	{
		//alert(makeBoss);
		if(showMakeB.checked)
		{
			
			makeBoss.value = 1;
			//get the button element and change its value to unboss
		}
		else
		{
			makeBoss.value = 0;
		}
		//alert(makeBoss.value);
	}
	
	var showMakeBForBill=document.getElementById('showMakeBossForBill');
	var makeBossForBill = document.getElementById('hidMakeBossForBill');
	if(showMakeBForBill!=null)
	{
		//alert(makeBoss);
		if(showMakeBForBill.checked)
		{
			makeBossForBill.value = 1;
			//get the button element and change its value to unboss
		}
		else
		{
			makeBossForBill.value = 0;
		}
		//alert(makeBoss.value);
	}
	
	
	
	
	
	var makeBossCreateCont =document.getElementById('hiddenBoss');
	if(makeBossCreateCont !=null)
	{
		if(makeBossCreateCont.value==0)
		{
			makeBossCreateCont.value = 1;
		}
		
	}
	
	
	var checkMakeBoss =document.getElementById('showMakeB');
	
	//alert(checkMakeBoss);
	var makeBossShowContacts =document.getElementById('hidMakeBoss');
	if(checkMakeBoss !=null)
	{
		if(checkMakeBoss.checked)
		{
			
			makeBossShowContacts.value = 1;
		}
		else
		{
			
			makeBossShowContacts.value = 0
		}
		
	}
	
	
	
}

function removeMakeBossVal()
{
	
	
	var removeBoss=document.getElementById('hiddenMakeBoss');
	//alert(removeBoss.value);
	if(removeBoss !=null)
	{
		if(removeBoss.value==1)
		{
			
			removeBoss.value=0; 
		//	alert(removeBoss.value);
		}
	}
	
	var removeBossCreateCont=document.getElementById('hiddenBoss')
	if(removeBossCreateCont !=null)
	{
		if(removeBossCreateCont.value ==1)
		{
			removeBossCreateCont.value=0;
			
		}
		
	}
	
	var removeBossShowCont=document.getElementById('hidMakeBoss')
	if(removeBossShowCont !=null)
	{
		if(removeBossShowCont.value ==1)
		{
			removeBossShowCont.value=0;
			
		}
		
		
	}
	
	
	
}
function changeHiddenDefaultVal()
{
	
	
	var showMakeDef=document.getElementById('showMakeDefault');
	var dafaultVal= document.getElementById('hiddenMakeDefault');
	if(showMakeDef !=null)
	{
	   if(showMakeDef.checked)
	   {
		   
		   dafaultVal.value=1;
		    
	   }
	   else
	   {
		   
		   dafaultVal.value=0;
	   }
	}   	
	
	var showMakeDefForBill=document.getElementById('showMakeDefaultForBill');
	var dafaultValForBill= document.getElementById('hidMakeDefaultForBill');
	if(showMakeDefForBill !=null)
	{
	   if(showMakeDefForBill.checked)
	   {
		   
		   dafaultValForBill.value=1;
		   
	   }
	   else
	   {
		   
		   dafaultValForBill.value=0;
	   }
	}   
	
	
	
	
	var dafaultValCreateCont= document.getElementById('hiddenDefault');
	if(dafaultValCreateCont !=null)
	{
	   if(dafaultValCreateCont.value==0)
	   {
		  // alert('inside');
		   dafaultValCreateCont.value=1;
		   
		   
	   }
	   
	}  
	
	var checkDefault=document.getElementById('showMakeDef');
	//alert(checkDefault);
	var makeDefaultShowContacts= document.getElementById('hidMakeDefault');
	if(checkDefault !=null)
	{
	   if(checkDefault.checked)
	   {
		   
		   makeDefaultShowContacts.value=1;
		   
	   }
	   else
	   {
		   
		   makeDefaultShowContacts.value =0;
	   }
	}  
	
	
	
	
	
	
}


function hideUpdateSalesRepResult()
{
	
	var updateSalesRepResult=document.getElementById('updateSalesRepResult');
	
	if(updateSalesRepResult !=null)
	{
		document.getElementById('updateSalesRepResult').style.display="none";
	}
}

function hideSalesrepDivs()
{
	var updateSalesRepResult = document.getElementById('updateSalesRepResult'); 
	if(updateSalesRepResult!=null){updateSalesRepResult.style.display="none";}
	var salesRepList = document.getElementById('SalesRepList'); 
	if(salesRepList!=null){salesRepList.style.display="none";}
	var updateSalesRep =document.getElementById('updateSalesRep'); 
	if(updateSalesRep!=null){updateSalesRep.style.display="none";}
	var SalesRepInformation = document.getElementById('SalesRepInformation'); 
	if(SalesRepInformation!=null){SalesRepInformation.style.display="none";}
	var deleteDiv = document.getElementById('DeletedSalesRepList'); 
	if(deleteDiv!=null){deleteDiv.style.display="none";}
	var showupdatedProfile = document.getElementById('showupdatedProfile');
	if(showupdatedProfile!=null){showupdatedProfile.style.display="none";}
	
	
}



function callUpdateUserForm()
{
	
	//var updateUserFormResult=document.getElementById('updateUserForm');
	
	
	
		if(document.updateUserForm.onsubmit())
		 {//this check triggers the validations

		    document.updateUserForm.submit();
		 }
	
	
}

function showSendAlert()
{
    var sendAlertDiv=document.getElementById('sendAlertDiv');
	
	if(sendAlertDiv !=null)
	{
		sendAlertDiv.style.display="";
	}
	
}

function showAddContactsInBill()
{
    var addContactDiv=document.getElementById('contactpopup');
	
    //alert(addContactDiv);
    
	if(addContactDiv !=null)
	{
		
		addContactDiv.style.display="";
	}
	
}



function floatingDiv(divID)
		{
			var divClick = divID;
			
			switch(divClick)
			{
			case 'registrationClick':
				var registrationResultDiv = document.getElementById('registrationResult');
				if(registrationResultDiv!=null){
					registrationResultDiv.style.display="none";
					}
				var registrationFormData = document.getElementById('registrationFormData');
				if(registrationFormData!=null){registrationFormData.style.display="";}
				document.getElementById('registration').style.display="";
				  dobj = document.getElementById("registration");
			   break;
			case 'registrationCloseClick':
				 
				document.getElementById('registration').style.display="none";
				//clearing form
				clearInputTags('registrationForm');
				var accountAvaliabilityMessage = document.getElementById('accountAvaliabilityMessage');
				if(accountAvaliabilityMessage!=null){accountAvaliabilityMessage.style.display="none";}
				var domainAvaliabilityMessage = document.getElementById('domainAvaliabilityMessage');
				if(domainAvaliabilityMessage!=null){domainAvaliabilityMessage.style.display="none";}
				var emailAvaliabilityMessage = document.getElementById('emailAvaliabilityMessage');
				if(emailAvaliabilityMessage!=null){emailAvaliabilityMessage.style.display="none";}
			   break;
			   
			   
			case 'forgotPasswordCloseClick':
				 
				document.getElementById('forgotpassword').style.display="none";
			   break;
			   
			case 'resendActivationCloseClick':
				 
				document.getElementById('resendactivationlink').style.display="none";
			   break;
			   
			   
			case 'forgotPasswordClick':
				
				var registrationFormData = document.getElementById('forgotpassword');
				if(registrationFormData!=null){registrationFormData.style.display="";}
				dobj = registrationFormData;
				
			   break;
			   
			case 'resendActivationClick':
				
				var registrationFormData = document.getElementById('resendactivationlink');
				if(registrationFormData!=null){registrationFormData.style.display="";}
				dobj = registrationFormData;
			   break;
			   
			default:  
		      //alert('vaibhav');
			}
		}

function swap(divID1,divID2)
{
	if(document.getElementById(divID1)){
		document.getElementById(divID1).style.display='none';}
	if(document.getElementById(divID2)){
		document.getElementById(divID2).style.display='';}
}
function customersDiv(divID)
			{  var divClick = divID;
				switch(divClick)
				{
					case 'createCustomerClick':
						  
						  document.getElementById('createCustomer').style.display="";
						  document.getElementById('updateCustomer').style.display="none";
						  document.getElementById('CustomerInformation').style.display="none";
						  //document.getElementById('ContactList').style.display="none";
						  document.getElementById('ContactInformation').style.display="none";
						  document.getElementById('createContacts').style.display="none";
						  document.getElementById('updateContacts').style.display="none";
						 
						  messageDiv2= document.getElementById('messagesDiv')
						  if(messageDiv2 !=null)
						  {
							  messageDiv2.style.display="none";
						  }	 
						  
						  break;
				    case 'CustomerInformationClick':
						  
						  document.getElementById('createCustomer').style.display="none";
						  document.getElementById('CustomerInformation').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('ContactInformation').style.display="none";
						  document.getElementById('createContacts').style.display="none";
						  document.getElementById('updateContacts').style.display="none";
						  messageDiv2= document.getElementById('messagesDiv')
						  if(messageDiv2 !=null)
						  {
							  messageDiv2.style.display="none";
						  }	
						  
						  break;
					 case 'createContactsClick':
						  
						  if(checkForDirtyForm()){
						  registerFormForDirtyCheck('createNewContacts');
						  setTimeout("resetCheckDirtyForm()",200);
						  document.getElementById('createCustomer').style.display="none";
						  document.getElementById('CustomerInformation').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('ContactInformation').style.display="none";
						  document.getElementById('createContacts').style.display="";
						  document.getElementById('updateContacts').style.display="none";
						  
						  messageDiv2= document.getElementById('messagesDiv')
						  if(messageDiv2 !=null)
						  {
							  messageDiv2.style.display="none";
						  }	
						  clearInputTags('createNewContacts');
						  var makeDef = document.getElementById('hiddenMakeDefault');
						  var makeBoss = document.getElementById('hiddenMakeBoss');
						  if(makeDef)
							  makeDef.value=0;
						  if(makeBoss)
							  makeBoss.value=0;
						  showDefaultButton();
						  }
						  break;
				      case 'ContactInformationClick':
						  
						  document.getElementById('createCustomer').style.display="none";
						  document.getElementById('CustomerInformation').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('ContactInformation').style.display="";
						  document.getElementById('createContacts').style.display="none";
						  break;
				     case 'updateCustomerClick':
				    	
						  document.getElementById('updateCustomer').style.display="";
						  document.getElementById('createCustomer').style.display="none";
						  document.getElementById('CustomerInformation').style.display="none";
						  //document.getElementById('ContactList').style.display="none";
						  document.getElementById('ContactInformation').style.display="none";
						  document.getElementById('createContacts').style.display="none";
						  messageDiv2= document.getElementById('messagesDiv')
						  if(messageDiv2 !=null)
						  {
							  messageDiv2.style.display="none";
						  }
						  
						  
						  break;
				     case 'updateContactsClick':
				    	 
						  document.getElementById('createCustomer').style.display="none";
						  document.getElementById('createContacts').style.display="none"
						  document.getElementById('CustomerInformation').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('ContactInformation').style.display="none";
						  document.getElementById('updateContacts').style.display="";
						  break;	  
						  
					  
					default:  
					    //  alert('vaibhav');
					
				}
				
				
				
				
			}

function customersDivSearch(divID)
			{  var divClick = divID;
				switch(divClick)
				{
					case 'ListAFClick':
						  
						  document.getElementById('ListAF').style.display="";
						  document.getElementById('ListGK').style.display="none";
						  document.getElementById('ListLP').style.display="none";
						  document.getElementById('ListQU').style.display="none";
						  document.getElementById('ListVZ').style.display="none";
						  break;
				    case 'ListGKClick':
						  
						  document.getElementById('ListAF').style.display="none";
						  document.getElementById('ListGK').style.display="";
						  document.getElementById('ListLP').style.display="none";
						  document.getElementById('ListQU').style.display="none";
						  document.getElementById('ListVZ').style.display="none";
						  break;
						  
				    case 'ListLPClick':
						  
						  document.getElementById('ListAF').style.display="none";
						  document.getElementById('ListGK').style.display="none";
						  document.getElementById('ListLP').style.display="";
						  document.getElementById('ListQU').style.display="none";
						  document.getElementById('ListVZ').style.display="none";
						  break;
				    case 'ListQUClick':
						  
						  document.getElementById('ListAF').style.display="none";
						  document.getElementById('ListGK').style.display="none";
						  document.getElementById('ListLP').style.display="none";
						  document.getElementById('ListQU').style.display="";
						  document.getElementById('ListVZ').style.display="none";
						  break;
					case 'ListVZClick':
						  
						  document.getElementById('ListAF').style.display="none";
						  document.getElementById('ListGK').style.display="none";
						  document.getElementById('ListLP').style.display="none";
						  document.getElementById('ListQU').style.display="none";
						  document.getElementById('ListVZ').style.display="";
						  break;
						  
					default:  
					    //  alert('vaibhav');
					
				}
				
				
				
				
			}
			
			
			
			
		function billDivSearch(divID,arrowId,yearDivId)
		
		
			{
				//alert('Params '+divID+' '+arrowId+' '+yearDivId);
		
			var divClick = divID;
				switch(divClick)
				{
					 
				    case 'monthIDClick':
							
					       var yearArrow = document.getElementById(arrowId);
						   var yearID = document.getElementById(yearDivId);
						   var Open = yearArrow.className;
					    if(yearArrow.className=='arrowClose')
					      {
						   yearID.style.display="";
						   try
						   {
							yearArrow.removeClassName('arrowClose');
						   yearArrow.addClassName('arrowOpen');
						   }
						   catch (error)
						   {
								yearArrow.className = 'arrowOpen';
						   }
						   
						  //  alert(document.getElementById('arrowYear').className);
						  }
						  else
						  { 
						   yearID.style.display="none";
						   try
						   {
							yearArrow.removeClassName('arrowOpen');
						   yearArrow.addClassName('arrowClose');

						   }
						   catch (error)
						   {
							yearArrow.className = 'arrowClose';
						   }
						   						   }
						 
					    
						  break;
						  
					default:  
					    //  alert('vaibhav');
					
				}
				
				
				
				
			}
		
		
		
		function monthDivSearch(billsDivId,monthArrowId)
		{
			
			
			
			//var billsDivs = document.getElementById(billsDivId);
			var NewArrowId=monthArrowId.id;
				
			
			monthDivHideShow(billsDivId,NewArrowId);
			
			
			
		}
		
		
		
		function monthDivHideShow(billsDivId,NewArrowId)
		{
			var monthArrow = document.getElementById(NewArrowId);
			var billsDivId2 = document.getElementById(billsDivId);
			
			
		
			 if(monthArrow.className=='arrowClose')
		      {
				 billsDivId2.style.display="";
		
					try
					   {
						  monthArrow.removeClassName('arrowClose');
						  monthArrow.addClassName('arrowOpen');
					   }
					catch(error)
					  {
						  monthArrow.className = 'arrowOpen';
					  }
		      }
			  
			  else
			  { 
			   billsDivId2.style.display="none";
			   
					   try
					   {
						   	monthArrow.removeClassName('arrowOpen');
						   	monthArrow.addClassName('arrowClose');
					   }
					   catch(error)
					   {
						   monthArrow.className= 'arrowClose';
					   }
			   }
			
			 
			 
			 
			 
		}
		
		
		
		
		function loadAutoSuggest()
		{
			
			var options = {
					script:"/BillsReminder/public/index.php?url=getcustomerbyname&json=true&",
					varname:"input",
					json:true,
					callback: function (obj) {
						var hidField = document.getElementById('customerName');
						var hidField2 = document.getElementById('hiddenCustomerId');
						
						if(hidField != null)
							hidField.value = obj.id;
						if(hidField2 !=null)
							hidField2.value = obj.id;
						
						submitSingleField(null,'getcustomercontacts',obj.id); 
						}
					};	
			var as_json = new AutoSuggest('customerNameNew', options);
			var options2 = {
					
					script:"/BillsReminder/public/index.php?url=getprojectbyname&json=true&",
					varname:"input",
					json:true,
					callback: function (obj) {
						//alert(obj.id); 
						var hidField = document.getElementById('projectName');
						//alert(hidField);
						if(hidField != null)
							hidField.value = obj.id;
					}
				};
			var as_json2 = new AutoSuggest('projectNameNew', options2);
			
			
		
			var options4 = {
					
					script:"/BillsReminder/public/index.php?url=getallcitiesbycountryid&json=true&",
					varname:"input",
					extraField:"countryId",
					json:true,
					callback:function(obj){
				 		var hidField = document.getElementById('cityId');
				 	    if(hidField != null)
                        hidField.value = obj.id;
					}
				};	
			var as_json4 = new AutoSuggest('cityName',options4);
			
			var options5 = {
					
					script:"/BillsReminder/public/index.php?url=getallcitiesbycountryidforupdatecustomer&json=true&",
					varname:"input",
					extraField:"countryId1",
					json:true,
					callback:function(obj){
				 		var hidField = document.getElementById('cityId1');
				 	    if(hidField != null)
                        hidField.value = obj.id;
					}
				};	
			var as_json4 = new AutoSuggest('cityName1',options5);
			
			
			
			
		}
		
		
		function updateLoadAutoSuggest()
		{
			var options = {
					script:"/BillsReminder/public/index.php?url=getcustomerbyname&json=true&",
					varname:"input",
					json:true,
					callback: function (obj) {
						var hidField = document.getElementById('updateCustomerId');
						if(hidField != null)
							hidField.value = obj.id;
						submitSingleField(null,'getcustomercontactsforupdate',obj.id); 
						}
					};	
			var as_json = new AutoSuggest('updateCustomerNameNew', options);
			var options2 = {
					script:"/BillsReminder/public/index.php?url=getprojectbyname&json=true&",
					varname:"input",
					json:true,
					callback: function (obj) {
						//alert(obj.id); 
						var hidField = document.getElementById('updateProjectId');
						//alert(hidField);
						if(hidField != null)
							hidField.value = obj.id;
					}
				};	
			var as_json2 = new AutoSuggest('updateProjectName', options2);
		
		
		}
			function BillDiv(divID)
			{  var divClick = divID;
				switch(divClick)
				{
					case 'createBillClick':
						  if(checkForDirtyForm())
						  {
							  registerFormForDirtyCheck('createBillForm');
							  setTimeout("resetCheckDirtyForm()",200);
						
						  clearInputTags('createBillForm',['projectName','customerName','custContactHid','creditDays']);
						  document.getElementById('createBill').style.display="";
						  document.getElementById('selectPeople').style.display="";
						 // document.getElementById('paymentList').style.display="none";
						  document.getElementById('billnformation').style.display="none";
						  document.getElementById('paymentInformation').style.display="none";
						  document.getElementById('makeFastPaymentDivId').style.display="none";
						  document.getElementById('updatePayment').style.display="none";
						  document.getElementById('createPayment').style.display="none";
						  document.getElementById('editBill').style.display="none";
						  messageDiv2= document.getElementById('messagesDiv')
						  if(messageDiv2 !=null)
						  {
							  messageDiv2.style.display="none";
						  }	 
						  var adjustAdvPaymentDiv = document.getElementById('adjustAdvPayment');
						  if(adjustAdvPaymentDiv!=null){adjustAdvPaymentDiv.style.display="none";}
						  var addProjectLable = document.getElementById('addProjectLable');
						  if(addProjectLable!=null){addProjectLable.style.display="none";}
						  var projectNameDive = document.getElementById('projectNameDive');
						  if(projectNameDive!=null){projectNameDive.style.display="none";}
						  var customeNameDiv = document.getElementById('customeNameDiv');
						  if(customeNameDiv!=null){customeNameDiv.style.display="none";}
						  var selectedPeopleForBillForm = document.getElementById('selectedPeopleForBillForm');
						  if(selectedPeopleForBillForm!=null){selectedPeopleForBillForm.style.display="none";}
						  var selectedPeopleForBillLabel = document.getElementById('selectedPeopleForBillLabel');
						  if(selectedPeopleForBillLabel!=null){selectedPeopleForBillLabel.style.display="none";}
						  loadAutoSuggest();
						  }
						 
						  
						   break;
					case 'makeFastPayments':
							document.getElementById('makeFastPaymentDivId').style.display="";
							document.getElementById('createBill').style.display="none";
							  document.getElementById('selectPeople').style.display="none";
							 var payList=document.getElementById('paymentList');
							 if(payList!=null){
								 payList.style.display="none";
							 }
							  document.getElementById('billnformation').style.display="none";
							  document.getElementById('paymentInformation').style.display="none";
							  document.getElementById('createPayment').style.display="none";
						   break;
				    case 'showBillClick':
						  
						  document.getElementById('createBill').style.display="none";
						  document.getElementById('selectPeople').style.display="none";
						  document.getElementById('paymentList').style.display="";
						  document.getElementById('billnformation').style.display="";
						  document.getElementById('paymentInformation').style.display="";
						  document.getElementById('createPayment').style.display="none";
						  break;
						  
				    case 'createPaymentClick':
				    	  if(checkForDirtyForm()){
							  registerFormForDirtyCheck('paymentForm');
							  setTimeout("resetCheckDirtyForm()",200);
						  document.getElementById('createBill').style.display="none";
						  document.getElementById('selectPeople').style.display="none";
						  document.getElementById('paymentList').style.display="";
						  document.getElementById('billnformation').style.display="";
						  document.getElementById('paymentInformation').style.display="none";
						  document.getElementById('createPayment').style.display="";
						  document.getElementById('updatePayment').style.display="none";
						  document.getElementById('updatePaymentResult').style.display="none";
						  
						  
						  var selectedPeopleForBillForm = document.getElementById('selectedPeopleForBillForm');
						  if(selectedPeopleForBillForm!=null){selectedPeopleForBillForm.style.display="none";}
						  var selectedPeopleForBillLabel = document.getElementById('selectedPeopleForBillLabel');
						  if(selectedPeopleForBillLabel!=null){selectedPeopleForBillLabel.style.display="none";}
						  
						  clearInputTags('createPayment',['paymentDate']);
						  
				    	  }
						  break;
				    case 'adjustPaymentClick':
				    	  if(checkForDirtyForm()){
							  registerFormForDirtyCheck('openAdvPaymentPopupDiv');
							  setTimeout("resetCheckDirtyForm()",200);
						  document.getElementById('createBill').style.display="none";
						  document.getElementById('selectPeople').style.display="none";
						  document.getElementById('paymentList').style.display="";
						  document.getElementById('billnformation').style.display="";
						  document.getElementById('paymentInformation').style.display="none";
						  document.getElementById('openAdvPaymentPopupDiv').style.display="";
						  document.getElementById('updatePayment').style.display="none";
						  document.getElementById('updatePaymentResult').style.display="none";
						  
						  
						  var selectedPeopleForBillForm = document.getElementById('selectedPeopleForBillForm');
						  if(selectedPeopleForBillForm!=null){selectedPeopleForBillForm.style.display="none";}
						  var selectedPeopleForBillLabel = document.getElementById('selectedPeopleForBillLabel');
						  if(selectedPeopleForBillLabel!=null){selectedPeopleForBillLabel.style.display="none";}
						  
						  clearInputTags('openAdvPaymentPopupDiv',['amountRecvdpopup']);
						  
				    	  }
						  break;
				    case 'monthIDClick':
					     
						   document.getElementById('monthID').style.display="";
						   document.getElementById('arrowYear').className="arrowOpen"
						   
						
						   
						 
						
						  break;
				    case 'createContactsClick':
				    	  document.getElementById('contactpopup').style.display="";
				    	  loadAutoSuggest();
				    	  
				    	  
						
				    	  
				    	  break;
				    case 'updateBillClick':
				    		
				    	  document.getElementById('updatePayment').style.display="none";
				    	  document.getElementById('updatePaymentResult').style.display="none";
						  document.getElementById('createBill').style.display="none";
						  document.getElementById('selectPeople').style.display="none";
						  document.getElementById('paymentList').style.display="none";
						  document.getElementById('billnformation').style.display="none";
						  document.getElementById('paymentInformation').style.display="none";
						  document.getElementById('createPayment').style.display="none";
						  document.getElementById('editBill').style.display="";
						  document.getElementById('selectedPeopleForBillLabel').style.display="none";
						  document.getElementById('selectedPeopleForBillForm').style.display="";
						  updateLoadAutoSuggest();
						  break;
					default:  
					    //  alert('vaibhav');
					
				}
				
				
				
				
			}
	       
			
			function reportDiv(divID)
			{  var divClick = divID;
			
				switch(divClick)
				{
				
					case 'reportBillClick':
						
						  document.getElementById('ReportBill').style.display="";
						  document.getElementById('ReportReceivable').style.display="none";
						  document.getElementById('ReportCustomers').style.display="none";
						  document.getElementById('ReportBillFilters').style.display="none";
						  document.getElementById('ReportcustomerFilters').style.display="none";
						  document.getElementById('ReportUser').style.display="none";
						  loadAutoSuggestForReport();
						  
						  break;
					case 'generateReptBillClick':
						  
						  document.getElementById('ReportBill').style.display="";
						  document.getElementById('ReportReceivable').style.display="none";
						  document.getElementById('ReportCustomers').style.display="none";
						  document.getElementById('ReportBillFilters').style.display="";
						  document.getElementById('ReportcustomerFilters').style.display="none";
						  document.getElementById('ReportUser').style.display="none";
						  break;
				    case 'reportReceiveClick':
						  
				          document.getElementById('ReportBill').style.display="none";
						  document.getElementById('ReportReceivable').style.display="";
						  document.getElementById('ReportCustomers').style.display="none";
						  document.getElementById('ReportBillFilters').style.display="none";
						  document.getElementById('ReportcustomerFilters').style.display="none";
						  document.getElementById('ReportUser').style.display="none";
						  break;
						  
				    case 'reportCustomerClick':
						  
				    	  document.getElementById('ReportBill').style.display="none";
						  document.getElementById('ReportReceivable').style.display="none";
						  document.getElementById('ReportCustomers').style.display="";
						  document.getElementById('ReportBillFilters').style.display="none";
						  document.getElementById('ReportcustomerFilters').style.display="none";
						  document.getElementById('ReportUser').style.display="none";
						  break;
				    case 'genrateRepCustClick':
						  
				    	  document.getElementById('ReportBill').style.display="none";
						  document.getElementById('ReportReceivable').style.display="none";
						  document.getElementById('ReportCustomers').style.display="";
						  document.getElementById('ReportBillFilters').style.display="none";
						  document.getElementById('ReportcustomerFilters').style.display="";
						  document.getElementById('ReportUser').style.display="none";
						  break;
				    case 'reportUsersClick':
					     
				    	document.getElementById('ReportBill').style.display="none";
						  document.getElementById('ReportReceivable').style.display="none";
						  document.getElementById('ReportCustomers').style.display="none";
						  document.getElementById('ReportBillFilters').style.display="none";
						  document.getElementById('ReportcustomerFilters').style.display="none";
						  document.getElementById('ReportUser').style.display="";
						  break;
					default:  
					     // alert('vaibhav');
					
				}
				
				
				
				
			}
			
			
function checkValueContactList(checkFor,showEffectOn)
{
	var chkElement = document.getElementById(checkFor);
		if(chkElement!=null)
		{
			
			 var custContactId=document.getElementById('hiddenContCustId');
			 //alert(custContactId);
			 var customerNameHidden32=document.getElementById('custHidExists');
			 //alert(customerNameHidden32);
			
			
			    var result=checkCustomerId(custContactId,customerNameHidden32);
				
				if(chkElement==null || chkElement.value=="0" || chkElement.value=="")
				{
					var showEffectElement  = document.getElementById(showEffectOn);
					if(showEffectElement!=null)
					{
						showEffectElement.style.border="2px solid #990000";
					
						var customerID=document.getElementById('customerName2');
					
						id1 = customerID.id ;
						{
					  		if(id1!=null && customerID.value!="")
					  		{
					  			
					  			setTimeout("submitSingleField(['"+id1+"'],'fetchcontacts',null)",500);
					  		}
					  	 
					  		else
					  		{
					  			var customerIDError=document.getElementById('messagesDiv');
					  			if(customerIDError !=null)
					  			{
					  				customerIDError.style.display="";
					  			}
					  			
					  		}
					  		
						}
						return false;
					}
				}
				else if(!result)
				{
					
					var showEffectElement  = document.getElementById(showEffectOn);
					if(showEffectElement!=null)
					{
					showEffectElement.style.border="2px solid #990000";
					if(customerNameHidden32 !=null && customerNameHidden32.value!="")
					{
						var customerID=document.getElementById('customerName2');
						customerID.value=customerNameHidden32.value;
						id=customerID.id;
						setTimeout("submitSingleField(['"+id+"'],'fetchcontacts',null)",500);
						//custContactId.value="";
					}
					return false;
					}
				}
				else
				{
					
					var showEffectElement  = document.getElementById(showEffectOn);
					if(showEffectElement!=null)
					{
					showEffectElement.style.border="1px solid #222222";
					return true;
					}
				}	
		}
		return false;
}

function checkCustomerId(custContactId,customerNameHidden32)
{
	 var selectBoxId  = document.getElementById('custContact');
	if(custContactId !=null && customerNameHidden32 !=null)
	{
	 if(custContactId.value != customerNameHidden32.value)
		{
		 	//custContactId.value="";
		 	selectBoxId.innerHTML="";
			return false;
		}
	
	 else
	 {
		 return true;
	 }
	}
	else
	{
		return true;
	}
	
}

			
			function callthis()
			{
				alert('asddddddddddddddddddddddddddd');
			}
			
			function settingDiv(divID)
			{  var divClick = divID;
				switch(divClick)
				{
					case 'myProfileClick':
							
							
						
						  document.getElementById('showupdatedProfile').style.display="none";	
						  document.getElementById('updateUserProfile').style.display="";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('settingUsers').style.display="none";
						  document.getElementById('ContactList').style.display="none";
						  document.getElementById('settingNewUser').style.display="none";
						  document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="none";
						  
						  var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						  
						  var settingSalesReps = document.getElementById('settingSalesReps');
						  if(settingSalesReps!=null){settingSalesReps.style.display="none";}
						  var SalesRepInformation = document.getElementById('SalesRepInformation');
						  if(SalesRepInformation!=null){SalesRepInformation.style.display="none";}
						  var updatingPermission = document.getElementById('updatingPermission');
						  if(updatingPermission!=null){updatingPermission.style.display="none";}
						  var updateSalesRep = document.getElementById('updateSalesRep');
						  if(updateSalesRep!=null){updateSalesRep.style.display="none";}
						  var userUpdatedResult=document.getElementById('UserUpdated');
						  if(userUpdatedResult!=null){userUpdatedResult.style.display="none";}
						  var createSalesRepForm = document.getElementById('createSalesRepFormDiv');
						  if(createSalesRepForm!=null){createSalesRepForm.style.display="none";}
						  
						  break;
					case 'myCompProfileClick':
						  
						  document.getElementById('updateUserProfile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="";
						  document.getElementById('settingUsers').style.display="none";
						  document.getElementById('ContactList').style.display="none";
						  document.getElementById('settingNewUser').style.display="none";
						  document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="none";
						  
						  var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						  
						  var settingSalesReps = document.getElementById('settingSalesReps');
						  if(settingSalesReps!=null){settingSalesReps.style.display="none";}
						  var SalesRepInformation = document.getElementById('SalesRepInformation');
						  if(SalesRepInformation!=null){SalesRepInformation.style.display="none";}
						  var updatingPermission = document.getElementById('updatingPermission');
						  if(updatingPermission!=null){updatingPermission.style.display="none";}
						  var userUpdatedResult=document.getElementById('UserUpdated');
						  if(userUpdatedResult!=null){userUpdatedResult.style.display="none";}
						  var createSalesRepForm = document.getElementById('createSalesRepFormDiv');
						  if(createSalesRepForm!=null){createSalesRepForm.style.display="none";}
						  break;
						  
						  
						 
						  
						  
					case 'creatUserClick':
						  
						  document.getElementById('updateUserProfile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('settingUsers').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('settingNewUser').style.display="";
						  document.getElementById('settingNewUsertext').style.display="";
						  //document.getElementById('settingNewUserEdit').style.display="none";
						  document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="none";
						  
						  var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						  
						  var settingEditUser = document.getElementById('settingEditUser');
						  if(settingEditUser!=null){settingEditUser.style.display="none";}
						  var settingEditUsertext = document.getElementById('settingEditUsertext');
						  if(settingEditUsertext!=null){settingEditUsertext.style.display="none";}
						  var userInformationLabel = document.getElementById('userInformationLabel');
						  if(userInformationLabel!=null){
						  userInformationLabel.style.display="none";}
						  var updatingPermissions = document.getElementById('updatingPermission');
						  if(updatingPermissions!=null){updatingPermissions.style.display="none";}
						  var userNameFailureMessage = document.getElementById('userNameFailureMessage');
						  if(userNameFailureMessage!=null){userNameFailureMessage.style.display = "none";}
						  var emailFailureMessage = document.getElementById('emailFailureMessage');
						  if(emailFailureMessage!=null){emailFailureMessage.style.display = "none";}
						  var profileForm = document.getElementById('updateUserProfile');
						  if(profileForm!=null){profileForm.style.display="none";}
						  var userUpdatedResult=document.getElementById('UserUpdated');
						  if(userUpdatedResult!=null){userUpdatedResult.style.display="none";}
						  
						  
						  break;
					case 'editUserClick':
						
						  //document.getElementById('updateUserProfile').style.display="none";
						  //document.getElementById('settingCompanyPro').style.display="none";
						  //document.getElementById('settingUsers').style.display="";
						  //document.getElementById('ContactList').style.display="";
						  //document.getElementById('settingNewUser').style.display="none";
						  //document.getElementById('settingNewUsertext').style.display="";
						  
						  var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						  
						  
						 var settingEditUser = document.getElementById('settingEditUser');
						 if(settingEditUser!=null)
						 {
							 settingEditUser.style.display="";
						 }
						 var userEditlink = document.getElementById('userEdit');
						 if(userEditlink!=null)
						 {
							 userEditlink.style.display="";
						 }
						 
						  document.getElementById('settingEditUsertext').style.display="";
						  userEditlink.style.display="none";
						  document.getElementById('userInformationLabel').style.display="none";
						  //document.getElementById('settingNewUserEdit').style.display="none";
						  //document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="none";
						  document.getElementById('updatingPermission').style.display="none";
						  var perferencesForm = document.getElementById('settingPreferences');
						  if(perferencesForm!=null){perferencesForm.style.display="none";}
						  var profileForm = document.getElementById('updateUserProfile');
						  if(profileForm!=null){profileForm.style.display="none";}
						  break;
						  
					case 'creatSalesRepClick':
							
						 var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						
						  document.getElementById('updateUserProfile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('SalesRepInformation').style.display="none";
						  document.getElementById('updateSalesRep').style.display="none";
						  document.getElementById('updateSalesRepResult').style.display="none";
						  document.getElementById('settingSalesReps').style.display="";
						  document.getElementById('SalesRepList').style.display="";
						  document.getElementById('settingNewSalesRep').style.display=""; 
						  document.getElementById('settingNewSalesReptext').style.display="";
						  document.getElementById('DeletedSalesRepList').style.display="none";
						  var createSalesRepForm = document.getElementById('createSalesRepFormDiv');
						  if(createSalesRepForm!=null){createSalesRepForm.style.display="";}
						  var perferencesForm = document.getElementById('settingPreferences');
						  if(perferencesForm!=null){perferencesForm.style.display="none";}
						  var profileForm = document.getElementById('updateUserProfile');
						  if(profileForm!=null){profileForm.style.display="none";}
						  clearInputTags('createSalesRepForm');
						  
						  
						  
					/*case 'editUserClick':
						  
						  document.getElementById('settingMyprofile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('settingUsers').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('settingNewUser').style.display="";
						  document.getElementById('settingNewUsertext').style.display="none";
						  document.getElementById('settingNewUserEdit').style.display="";
						  document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="";
						  break;*/
						  break;
					case 'updateSalesRepClick':
						  document.getElementById('SalesRepInformation').style.display="none";
						  document.getElementById('updateSalesRep').style.display="";
						  break;
					case 'editPermissionClick':
						
						 var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						  if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						  
						  document.getElementById('updateUserProfile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('settingUsers').style.display="";
						  document.getElementById('ContactList').style.display="";
						  document.getElementById('settingNewUser').style.display="";
						  document.getElementById('settingNewUsertext').style.display="";
						  var settingNewUserEdit = document.getElementById('settingNewUserEdit');
						  if(settingNewUserEdit!=null){settingNewUserEdit.style.display="none";}
						  document.getElementById('settingPreferences').style.display="none";
						  document.getElementById('settingPermission').style.display="";
						  break;
					
					case 'preferencesClick':
						 
						 var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
							
						  document.getElementById('settingNewSalesRep').style.display="none";	
						  document.getElementById('SalesRepList').style.display="none";
						  document.getElementById('settingPreferences').style.display="";	
						  document.getElementById('updateUserProfile').style.display="none";
						  document.getElementById('settingCompanyPro').style.display="none";
						  document.getElementById('settingUsers').style.display="none";
						  document.getElementById('ContactList').style.display="none";
						  document.getElementById('settingNewUser').style.display="none";
					
						//  document.getElementById('settingNewUsertext').style.display="none";
						  
						  //document.getElementById('settingNewUserEdit').style.display="none";
						  document.getElementById('settingPermission').style.display="none";
						  
						  var userUpdatedResult=document.getElementById('UserUpdated');
						  if(userUpdatedResult!=null){userUpdatedResult.style.display="none";}
						  var showupdatedProfile = document.getElementById('showupdatedProfile');
						  if(showupdatedProfile!=null) {showupdatedProfile.style.display="none";}
						  break;
						  
					case 'autoSmsAndEmailAlertsDiv':
						var autoEmailAndSms = document.getElementById('autoSmsAndEmailAlertsDiv');
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="";}
						
						 var autoEmailAndSms = document.getElementById('SalesRepList');
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('settingNewSalesRep');
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('settingPreferences'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('ContactList'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('settingNewUser'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('updateSalesRep'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('settingCompanyPro'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
						 
						 var autoEmailAndSms = document.getElementById('updateUserProfile'); 
						 if(autoEmailAndSms!=null){autoEmailAndSms.style.display="none";}
					
					default:  
					    // alert('vaibhav');
					
				}
				
			}

			
//popup script
			
			var nn6 = document.getElementById &&! document.all;

			//alert(nn6);

			var isdrag = false;
			var x, y;
			var dobj;
		

			function movemouse( e ) {
			  if( isdrag ) {
			  //  alert(e.clientX);
			   dobj.style.left = (nn6 ? tx + e.clientX - x : tx + event.clientX - x)+'px';
			    dobj.style.top  = (nn6 ? ty + e.clientY - y : ty + event.clientY - y)+'px';
			   
			    return false;
			  }
			}

			function selectmouse( e ) {
				try{
			  var fobj       = nn6 ? e.target : event.srcElement;
			  
			  var topelement = nn6 ? "HTML" : "BODY";

			  while (fobj.tagName != topelement && fobj.className != "dragme") {
			    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
			  }
			  
			  
			  if (fobj.className=="dragme") {
			   //alert(fobj.className);
			    isdrag = true;
			  //  dobj = document.getElementById("registration");
			 //   dobj1 = document.getElementById("registration");
				//alert(dobj);
			//    alert(dobj.style.left)
			    if(dobj!=null){
			    
			    x = nn6 ? e.clientX : event.clientX;
			    y = nn6 ? e.clientY : event.clientY;
				tx = parseInt(dobj.style.left+0);
			    ty = parseInt(dobj.style.top+0);
			     
				//alert(x+ ' '+y);
			    document.onmousemove=movemouse;
			    return false;
			    }
			  }
				}
				catch(errorr)
				{
					//alert(errorr);
				}
			}


			function styledPopupClose() {
			  document.getElementById("registration").style.display = "none";
			}
			function styledPopupShow() {
			 		 
			//  alert('dsfdsf');
			   document.getElementById("registration").style.display = "";
			   document.getElementById('registration').style.zIndex="100000000";
			}
			document.onmousedown=selectmouse;
			document.onmouseup=new Function("isdrag=false");
			
			
function checkInArray(arrayObj,chkValue)
{
		if(arrayObj!=null){
	 	var i;
	 	for(i=0; i < arrayObj.length; i++){
	 	if(arrayObj[i] === chkValue)
	      return true;
	  };
	  return false;
	}
	return false;	
}
			
function clearInputTags(formId,exceptionalElements)
   { 	
	
    var form = document.getElementById(formId);
    if(form!=null)
    {
    	   var inputElements = form.getElementsByTagName('input');
   try{
            for(var i=0;i<inputElements.length;i++)
            {
            	
                    if(inputElements[i].type=="submit"|| inputElements[i].type=="button"){
                            //do not change the value
                    }
                    else if(inputElements[i].type=="hidden")
                    {
                    	//check for exceptional hiddens whose value is to be removed
                    	var returnResult = checkInArray(exceptionalElements,inputElements[i].id);
                    	if(returnResult)
                    	{
                    		//remove the value
                    		inputElements[i].value="";
                    	}
                    }
                    else if(inputElements[i].type=="checkbox")
                    {
                            inputElements[i].checked="";
                    }
                    else{
                            if(inputElements[i].type=="text")
                            {
                                //do not remove the the exceptionalElements
                            	var returnResult = checkInArray(exceptionalElements,inputElements[i].id);
                                if(!returnResult)
                            	{
                            		inputElements[i].value="";
                            	}
                                if(inputElements[i].onblur)
                            	{
                            		inputElements[i].onblur();
                            	}
                            }
                    }
                    
            }
            
   }catch(e)
   {
           alert('some error occured while clearing form data' + e);
       }
       }
       
}


function createPermissionArray()
{
	 
	 var permissionChk=document.getElementsByName("permissionsChk")
	 
	 if(permissionChk!=null)
	 {
		 var permissionIds = new Array();
		 for(var i=0;i<permissionChk.length;i++)
		 {
			 if(permissionChk[i].checked)
			 {
				 permissionIds[permissionIds.length] = permissionChk[i].value;
			 }
		 }	 	
		 
		 //creating the string for hidden permission
		var hiddenPermissionList  = document.getElementById('permissionlist');
		if(hiddenPermissionList!=null)
		{
			var permissionString  = permissionIds.toString();
			hiddenPermissionList.value=permissionString;
		}
		
		 
	 }
}

function editPermissionArray()
{
	 
	 var permissionChk=document.getElementsByName("editPermissionsChk")
	 
	 if(permissionChk!=null)
	 {
		 var permissionIds = new Array();
		 for(var i=0;i<permissionChk.length;i++)
		 {
			 if(permissionChk[i].checked)
			 {
				 permissionIds[permissionIds.length] = permissionChk[i].value;
			 }
		 }	 	
		 
		 //creating the string for hidden permission
		var hiddenPermissionList  = document.getElementById('editpermissionlist');
		if(hiddenPermissionList!=null)
		{
			var permissionString  = permissionIds.toString();
			hiddenPermissionList.value=permissionString;
		}
		
		 
	 }
}	

			
function showDivOfYetToBeVerifyEmailId(formId,divId,divID1)
{
	//alert(divId);
	//alert(divID1);
	var showDiv = document.getElementById(divId);
	var showDiv1 = document.getElementById(divID1);
	//alert(showDiv);
	//alert('--------'+showDiv1);
	if(showDiv!=null && showDiv1!=null)
	{  
		showDiv.style.display="";
		showDiv1.style.display="";
	}
}
function showDataSaveMessDiv(divId)
{
	var showDiv = document.getElementById(divId);
	if(showDiv!=null)
	{
		showDiv.style.display="";
		dId=showDiv.id;
		setTimeout("clearPreferenceMessage(''+dId+'')",4000);
	}
}

function showEmailSendMessage(divId)
{
	var showEmailMessageDiv = document.getElementById(divId);
	if(showEmailMessageDiv !=null)
	{
		showEmailMessageDiv.style.display="";
		messageId = showEmailMessageDiv.id;
		setTimeout("clearPreferenceMessage(''+messageId+'')",5000);
	}
}

function hideDivOfYetToBeVerifyEmailId(formId,divId,divID1)
{
	//alert(formId);
	var showDiv = document.getElementById(divId);
	var showDiv1 = document.getElementById(divID1);
	//alert(showDiv);
	//alert(showDiv1);
	if(showDiv!=null && showDiv1!=null)
	{
	
		showDiv.style.display="none";
		showDiv1.style.display="none";
	}
}

function showCreateContactsDiv(divId)
{
	var showDiv = document.getElementById(divId);
	if(showDiv!=null)
	{
		showDiv.style.display="";
	}
	
}

function clearPreferenceMessage(divId)
{
	var hideDiv = document.getElementById(divId)
	if(hideDiv!=null)
	{
		hideDiv.style.display="none";
		hideDiv.innerHTML="";
	}
}
function deleteBill()
{
	var response=confirm("Are you sure you wish to delete this bill? All associated payments will be deleted.");
	if(response==true){
	submitSingleField(['billId'],'deleteBill',null);
	}
}
function selectedTransaction(paymentId){
	//submitSingleField(null,'detailedtransaction',paymentId);
	window.open("/BillsReminder/public/index.php?url=payments/detailedtransaction&inputDirect="+paymentId,"_blank");
}


function paymentDeleteCalled(obj)
{
	
	var response=confirm("Are you sure you wish to delete this payment?");
	if(response == true)
	{
		
		if(obj!=null)
		{
			
			submitSingleField([obj],'deletePayment');
			
//			var updatePaymentResult2=document.getElementById('updatePaymentResult');
//			if(updatePaymentResult2!=null)
//			{
//				
//				updatePaymentResult2.style.display='none';
//			}
			
			var hideDiv=document.getElementById(obj);
			if(hideDiv!=null)
			{
				hideDiv.style.display='none';
			}
		}	
			
	}
	else{
			var hideDiv=document.getElementById(obj);
			if(hideDiv!=null)
			{
				
				hideDiv.style.display='';
			}
		
		}
	
}

function clearContactsForBill()
{
	var custContact = document.getElementById('custContact');
	if(custContact!=null)
	{
		custContact.innerHTML="";
	}
}

// global variable
var clickedFromDashBoard = false;
function loadBillFromDashBoard(billId)
{
	// alert(billId);
	clickedFromDashBoard = true;
	var billIdOnMasterPage = document.getElementById('billIdForDashboard');
	if(billIdOnMasterPage!=null)
	{
		billIdOnMasterPage.value=billId;
		// alert('**************************'+billIdOnMasterPage.value);
	}
	navigate('bills','TAB');
	chooseTab('payTabL');
}
function loadBillByIdWithDelay()
{
	if(clickedFromDashBoard)
	{	
	submitSingleField(['billIdForDashboard'],'getbilldetails');
		
	}
}

function createCustomerCancelClicked()
{
	var createCustomer = document.getElementById('createCustomer');
	if(createCustomer!=null)
	{
		createCustomer.style.display="none";
	}
	clearMandatoryFieldsErrors(['createCompanyName','createCreditDays'],'createCustomerError');
}

function createContactDeleteClicked()
{
	var createContact = document.getElementById('createContacts');
	if(createContact!=null)
	{
		createContact.style.display="none";
	}
	clearMandatoryFieldsErrors(null,'createContactFormError');
}

function showBillDetailsOnDashboard(dashboardDivId)
{
	var dashboardDiv = document.getElementById(dashboardDivId);
	if(dashboardDiv!=null)
	{
		dashboardDiv.style.display="";
	}
}
function hideBillDetailsOnDashboard(dashboardDivId)
{
	var dashboardDiv = document.getElementById(dashboardDivId);
	if(dashboardDiv!=null)
	{
		dashboardDiv.style.display="none";
	}
}

function closeBillCreationPopup()
{
	var createBillPopDiv = document.getElementById('createBillPopDiv');
	if(createBillPopDiv!=null)
	{
		createBillPopDiv.style.display="none";
	}
}

function closeAdvancePaymentPopup()
{
	var createadvPaymentPopDiv = document.getElementById('createAdvancePaymentPopDiv');
	if(createadvPaymentPopDiv!=null)
	{
		createadvPaymentPopDiv.style.display="none";
	}
}

//FOR PAYMENTS

function onChangePaymentOptions()
{
	var tariffPlanCombo = document.getElementById('tariffPlanCombo');
	if(tariffPlanCombo!=null)
	{
		var selIndex = tariffPlanCombo.selectedIndex;
		var selectedPlanId = tariffPlanCombo.options[selIndex].value;
		var viewablePlanName = document.getElementById('viewablePlanName'); 
		switch(selectedPlanId)
		{
			case '2':
				document.getElementById('plan2Div').style.display="";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="none";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Standard @1000 Per Month";
				setPlanDetails(1,25,1000,2);
			break;
			case '3':
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="";
				document.getElementById('plan4Div').style.display="none";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Standard+ @1500 Per Month";
				setPlanDetails(2,75,1500,3);
			break;
			case '4':
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Preferred+ @2000 Per Month";
				setPlanDetails(3,200,2000,4);
				break;
			case '5':
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="none";
				document.getElementById('plan5Div').style.display="";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Gold @3000 Per Month ";
				setPlanDetails(5,350,3000,5);
				break;
			case '6':
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="none";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Platinum @4000 Per Month";
				setPlanDetails(10,500,4000,6);
				break;
			case '7':
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="none";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="";
				viewablePlanName.value="Unlimited+ @6000 Per Month";
				setPlanDetails(-1,-1,6000,7);
				break;
			default:
				document.getElementById('plan2Div').style.display="none";
				document.getElementById('plan3Div').style.display="none";
				document.getElementById('plan4Div').style.display="";
				document.getElementById('plan5Div').style.display="none";
				document.getElementById('plan6Div').style.display="none";
				document.getElementById('plan7Div').style.display="none";
				viewablePlanName.value="Preferred+ @2500 Per Month";
				setPlanDetails(3,200,2000,4);//if he checks for sms and comes back again
			
			break;
		}
		
	}
}

function onChangePaymentPeriod()
{
	
	var planForperiodCombo = document.getElementById('planForperiodCombo');
	if(planForperiodCombo!=null)
	{
		var selIndex = planForperiodCombo.selectedIndex;
		var selectedPeriod = planForperiodCombo.options[selIndex].value;
		var discountPercentageLabel = document.getElementById('discountPercentageLabel');
		switch(selectedPeriod)
		{
			case '1':
				setOfferDetails(0,1);
				discountPercentageLabel.value = "0%";
			break;
			case '3':
				setOfferDetails(0,3);
				discountPercentageLabel.value = "0%";
				break;
			case '6':
				setOfferDetails(0,6)
				discountPercentageLabel.value = "0%";
				break;
			case '12':
				setOfferDetails(10,12);
				discountPercentageLabel.value = "10%";
				break;
			default:
				setOfferDetails(10,12);
				discountPercentageLabel.value = "10%";
			break;
		}
   }
}
function showCCPaymentDiv()
{
	var ccPaymentFormDiv = document.getElementById('ccPaymentFormDiv');
	if(ccPaymentFormDiv!=null){ccPaymentFormDiv.style.display="";}
}
function hideCCPaymentDiv()
{
	var ccPaymentFormDiv = document.getElementById('ccPaymentFormDiv');
	if(ccPaymentFormDiv!=null){ccPaymentFormDiv.style.display="none";}
}
function setPlanDetails(maxUserForPlan,maxBillsForPlan,amountForPlan,selectedPlanId)
{
	var maxUsers = document.getElementById('maxUsers');
	if(maxUsers!=null){maxUsers.value=maxUserForPlan;}
	var maxBills = document.getElementById('maxBills');
	if(maxBills!=null){maxBills.value=maxBillsForPlan;}
	var planAmount = document.getElementById('planAmount');
	if(planAmount!=null){planAmount.value=amountForPlan;}
	var planId = document.getElementById('planName');
	if(planId!=null){planId.value=selectedPlanId;}
	calculateTariffPlan();
}
function setOfferDetails(selectedDiscount,noOfMonths)
{
	var discountSelected = document.getElementById('discountSelected');
	if(discountSelected!=null){discountSelected.value=selectedDiscount;}
	var discountForMonths = document.getElementById('discountForMonths');
	if(discountForMonths!=null){discountForMonths.value=noOfMonths;}
	calculateTariffPlan();
}
function setSmsPackDetails(selectedSmsPack,selectedSmsPlanId,selectedSmsPackPrice)
{
	
	var smsPackSelected = document.getElementById('smsPackSelected');
	if(smsPackSelected!=null){smsPackSelected.value=selectedSmsPack;}
	var smsPack = document.getElementById('smsPack');
	if(smsPack!=null){smsPack.value=selectedSmsPlanId;}
	var smsPackPrice = document.getElementById('smsPackPrice');
	if(smsPackPrice!=null){smsPackPrice.value=selectedSmsPackPrice;}
	calculateTariffPlan();
}

function selectSMSPackOnly()
{
	var smsPackSelection = document.getElementById('smsPackSelection');
	if(smsPackSelection!=null){
		if(smsPackSelection.checked)
		{
			setPlanDetails(0,0,0,null);
			setOfferDetails(0,0);
			var planSelectionDiv = document.getElementById('planSelectionDiv');
			if(planSelectionDiv!=null){
			planSelectionDiv.style.display="none";}
			var periodSelectionDiv = document.getElementById('periodSelectionDiv');
			if(periodSelectionDiv!=null){periodSelectionDiv.style.display="none";}
			var periodDiscountDiv = document.getElementById('periodDiscountDiv');
			if(periodDiscountDiv!=null){periodDiscountDiv.style.display="none";}
			var viewablePlanName = document.getElementById('viewablePlanName');
			if(viewablePlanName!=null){viewablePlanName.value="None";}
			var smsPackNone = document.getElementById('smsPackNone');
			if(smsPackNone!=null){smsPackNone.style.display="none";}
			var smsNoneLabel = document.getElementById('smsNoneLabel');
			if(smsNoneLabel!=null){smsNoneLabel.style.display="none";}
			var smsPackSelected = document.getElementById('smsPackSelected');
			if(smsPackSelected!=null){smsPackSelected.checked="checked";}
			document.getElementById('plan2Div').style.display="none";
			document.getElementById('plan3Div').style.display="none";
			document.getElementById('plan4Div').style.display="none";
			document.getElementById('plan5Div').style.display="none";
			document.getElementById('plan6Div').style.display="none";
			document.getElementById('plan7Div').style.display="none";
			setSmsPackDetails('1,500 SMSs @ 0.75Rs per sms',9,1125);
		}
		else
		{
			var planSelectionDiv = document.getElementById('planSelectionDiv');
			if(planSelectionDiv!=null){planSelectionDiv.style.display="";}
			var periodSelectionDiv = document.getElementById('periodSelectionDiv');
			if(periodSelectionDiv!=null){periodSelectionDiv.style.display="";}
			var periodDiscountDiv = document.getElementById('periodDiscountDiv');
			if(periodDiscountDiv!=null){periodDiscountDiv.style.display="";}
			var smsPackNone = document.getElementById('smsPackNone');
			if(smsPackNone!=null){smsPackNone.style.display="";}
			var smsNoneLabel = document.getElementById('smsNoneLabel');
			if(smsNoneLabel!=null){smsNoneLabel.style.display="";}
			onChangePaymentOptions();
			onChangePaymentPeriod();
			calculateTariffPlan();
		}
		
	}
}

function calculateTariffPlan()
{
	var maxUserForPlan=0;
	var maxBillsForPlan=0;
	var amountForPlan=0;
	var selectedDiscount=0;//this is the percent
	var noOfMonths = 1;
	var selectedSmsPack = "None";
	var selectedSmsPackPrice=0;
	var maxUsers = document.getElementById('maxUsers');
	if(maxUsers!=null){maxUserForPlan=(maxUsers.value * 1);}
	var maxBills = document.getElementById('maxBills');
	if(maxBills!=null){maxBillsForPlan = (maxBills.value * 1);}
	var planAmount = document.getElementById('planAmount');
	if(planAmount!=null){amountForPlan=(planAmount.value * 1);}
	var discountSelected = document.getElementById('discountSelected');
	if(discountSelected!=null){selectedDiscount = (discountSelected.value * 1);}
	var discountForMonths = document.getElementById('discountForMonths');
	if(discountForMonths!=null){noOfMonths = (discountForMonths.value * 1);}
	var smsPackSelected = document.getElementById('smsPackSelected');
	if(smsPackSelected!=null){selectedSmsPack = smsPackSelected.value;}
	var smsPackPrice = document.getElementById('smsPackPrice');
	if(smsPackPrice!=null){selectedSmsPackPrice = (smsPackPrice.value * 1)}
	//calculation starts here
	
	var totalAmount = ((amountForPlan*noOfMonths) - (selectedDiscount*.01*(amountForPlan*noOfMonths)) + selectedSmsPackPrice);
	if(maxUserForPlan===-1 && maxBillsForPlan===-1 )
	{
		//alert(' Users : Unlimited' + ' Bills : Unlimited ' + 'Amount :' + totalAmount + ' Selected Sms Pack' + selectedSmsPack);
		drawPlanSelectionTable(((amountForPlan*noOfMonths) - (selectedDiscount*.01*(amountForPlan*noOfMonths))),noOfMonths,selectedDiscount,'Unlimited','Unlimited',selectedSmsPack,selectedSmsPackPrice,totalAmount);
	}
	else{
		//alert(' Users : '+maxUserForPlan + ' Bills : ' + (maxBillsForPlan* noOfMonths)+ ' Amount : ' + totalAmount + " Selected Sms Pack " + selectedSmsPack);
		drawPlanSelectionTable(((amountForPlan*noOfMonths) - (selectedDiscount*.01*(amountForPlan*noOfMonths))),noOfMonths,selectedDiscount,maxUserForPlan,(maxBillsForPlan* noOfMonths),selectedSmsPack,selectedSmsPackPrice,totalAmount);
	}
	
	
	
}
	function drawPlanSelectionTable(planAmount,validity,discount,users,bills,smsPack,smsPackAmount,totalAmount)
	{
		var showViewablePlanName  = document.getElementById('viewablePlanName');
		if(showViewablePlanName!=null){document.getElementById('showSelectedPlan').value = showViewablePlanName.value;}
		var showSelectedPlanAmount = document.getElementById('showSelectedPlanAmount');
		if(showSelectedPlanAmount!=null){showSelectedPlanAmount.value="INR " + planAmount + ".00";}
		var showValidity = document.getElementById('showValidity');
		if(showValidity!=null){
			if(validity===1)
			showValidity.value=validity + " Month";
			else
			showValidity.value=validity + " Months";
			
		   if(validity==12)
		   {
			   var showFreeSmsForPlan = document.getElementById('showFreeSms');
			   if(showFreeSmsForPlan!=null){
				   if(bills=="Unlimited"){showFreeSmsForPlan.value=1000;}
				   else{showFreeSmsForPlan.value = (bills/12);}   
			   }
		   }
		   else
		   {
			   var showFreeSmsForPlan = document.getElementById('showFreeSms');
			   if(showFreeSmsForPlan!=null){showFreeSmsForPlan.value=0;}
		   }
		}
		var showDiscount = document.getElementById('showDiscount');
		if(showDiscount!=null){showDiscount.value=discount + "%";}
		var showPlanUsers = document.getElementById('showPlanUsers');
		if(showPlanUsers!=null){showPlanUsers.value=users;}
		var showPlanBills = document.getElementById('showPlanBills');
		if(showPlanBills!=null){showPlanBills.value=bills;}
		var showSmsPack = document.getElementById('showSmsPack');
		if(showSmsPack!=null){showSmsPack.value = smsPack; }
		var showSmsPackAmount = document.getElementById('showSmsPackAmount');
		if(showSmsPackAmount!=null){showSmsPackAmount.value="INR " + smsPackAmount + ".00";}
		var netAmountOfPack = document.getElementById('netAmountOfPack');
		if(netAmountOfPack!=null){netAmountOfPack.value = "INR " + totalAmount + ".00"}
	}

function confirmPaymentForPlan()
{
	var planName='';
	var smsPlanName='';
	var validity='12 Months';
	var showSelectedPlan =  document.getElementById('showSelectedPlan');
	if(showSelectedPlan!=null){planName =showSelectedPlan.value; }
	var showSmsPack = document.getElementById('showSmsPack');
	if(showSmsPack!=null){smsPlanName = showSmsPack.value;}
	var showValidity = document.getElementById('showValidity');
	if(showValidity!=null){
		validity = showValidity.value;
	}
	if(planName=='None')
		var response=confirm("You have selected " + smsPlanName + ' plan. Click OK to proceed.');
	else if(smsPlanName=='None')
		var response=confirm("You have selected " + planName + ' plan for ' + validity + '. Click OK to proceed');	
	else
		var response=confirm("You have selected " + planName +' for ' + validity + ' and ' + smsPlanName + ' plan. Click OK to proceed');	
	if(response==true){
		submitData('planSelectionForm','selectedPlan');
		return false;
	}
}
 function submitFormToEBS()
 {
	
	 document.frmTransaction.submit();
	 
 }

function loadAutoSuggestForReport()
	{
		
		var options = {
				script:"/BillsReminder/public/index.php?url=getcustomerbyname&json=true&",
				varname:"input",
				json:true,
				callback: function (obj) {
					var hidField = document.getElementById('customername');
					if(hidField != null)
						hidField.value = obj.id;
					submitSingleField(null,'getcustomercontacts',obj.id); 
					}
				};	
		var as_json = new AutoSuggest('customernamenew', options);
		var options2 = {
				script:"/BillsReminder/public/index.php?url=getprojectbyname&json=true&",
				varname:"input",
				json:true,
				callback: function (obj) {
					//alert(obj.id); 
					var hidField = document.getElementById('projectname');
					//alert(hidField);
					if(hidField != null)
						hidField.value = obj.id;
				}
			};
		var as_json2 = new AutoSuggest('projectnamenew', options2);
		
				
			var options3 = {
					script:"/BillsReminder/public/index.php?url=getcustomercontactforreport&json=true&",
					varname:"input",
					extraField:"customername",
					json:true,
					callback: function (obj) {
						//alert(obj.id); 
						var hidField = document.getElementById('customercontact');
						//alert(hidField);
						if(hidField != null)
							hidField.value = obj.id;
					}
				};	
			var as_json2 = new AutoSuggest('customercontactname', options3);
		
	
	}

function cancelBillForUpdate()
{
	var editBill = document.getElementById('editBill');
	if(editBill!=null){editBill.style.display="none";}
	var selectedPeopleForBillForm = document.getElementById('selectedPeopleForBillForm');
	if(selectedPeopleForBillForm!=null){selectedPeopleForBillForm.style.display="none";}
	var updatePayment = document.getElementById('updatePayment');
	if(updatePayment!=null){updatePayment.style.display="none";}
	var billInfo = document.getElementById('billnformation');
	if(billInfo!=null){billInfo.style.display="";}
	var selectedPeopleForBillLab = document.getElementById('selectedPeopleForBillLabel');
	if(selectedPeopleForBillLab!=null){selectedPeopleForBillLab.style.display="";}
	var paymentListDiv = document.getElementById('paymentList');
	if(paymentListDiv!=null){paymentListDiv.style.display="";}
}
function cancelCustomerUpdateClick()
{
	var updateCustomer = document.getElementById('updateCustomer');
	if(updateCustomer!=null){updateCustomer.style.display="none";}
	var updateContacts = document.getElementById('updateContacts');
	if(updateContacts!=null){updateContacts.style.display="none";}
	
	var CustomerInformation=document.getElementById('CustomerInformation');
	if(CustomerInformation!=null){CustomerInformation.style.display="";}
	var custmerAccountSummaryDiv=document.getElementById('custmerAccountSummaryDiv');
	if(custmerAccountSummaryDiv!=null){custmerAccountSummaryDiv.style.display="";}
	var ContactList=document.getElementById('ContactList');
	if(ContactList!=null){ContactList.style.display="";}
}

function  deleteCustomer (obj,divId,newCreatedCustomer,customerNameDiv,contactDiv)
{
	
	var response=confirm("All Payments, Bills and Contacts (if any) of this Customer will be deleted. Are you sure you wish to delete this Customer?");
	
	//alert(obj);
	//alert(divId);
	if(response==true)
	{
		if(obj!=null)
		{
			//alert('del')
			submitSingleField([obj],'deleteCustomer');
		}
		
 
		var hideDiv=document.getElementById(divId);
		//alert(hideDiv);
		if(hideDiv!=null)
		{
		//	alert(hideDiv);
			hideDiv.style.display='none';
		}
		var hideCustomerDiv=document.getElementById(customerNameDiv);
		//alert(hideCustomerDiv);
		if(hideCustomerDiv!=null)
		{
		//	alert(hideCustomerDiv);
			hideCustomerDiv.style.display='none';
		}
		var hideCustomerDiv1=document.getElementById(newCreatedCustomer);
		//alert(hideCustomerDiv);
		if(hideCustomerDiv1!=null)
		{
			//alert(hideCustomerDiv1);
			hideCustomerDiv1.style.display='none';
		}
		var hideContactDiv=document.getElementById(contactDiv);
		//alert(hideCustomerDiv);
		if(hideContactDiv!=null)
		{
			//alert(hideCustomerDiv1);
			hideContactDiv.style.display='none';
		}
		 
	}else{
		 
		document.getElementById(obj).style.display='';
	}
	
}
function cancelCreateBillClick()
{
	var createBill = document.getElementById('createBill');
	if(createBill!=null){createBill.style.display="none"};
	var selectPeople = document.getElementById('selectPeople');
	if(selectPeople!=null){selectPeople.style.display="none";}
	clearInputTags('createBillForm',['projectName','customerName','custContactHid']);
	clearContactsForBill();
	clearMandatoryFieldsErrors(['customerNameNew','billNumber','billValue','billDate'],'createBillFormError');
	var billcreationError = document.getElementById('billCreationerrorDiv');
	if(billcreationError!=null){billcreationError.style.display="none";}	
	var contactCCList = document.getElementById('contactCCList');
	if(contactCCList!=null)
	{
		contactCCList.style.display="none";
	}
	
	
	
}

function canceladvPaymentpopupClick()
{
	clearInputTags('paymentForm',['paymentDate']);
	clearMandatoryFieldsErrors(['amountText'],'paymentErrorDiv');
//	var createPayment = document.getElementById('createPayment');
//	if(createPayment!=null){createPayment.style.display="none";}
	
	
}
function cancelPaymentClick()
{
	clearInputTags('paymentForm',['paymentDate']);
	clearMandatoryFieldsErrors(['amountText'],'paymentErrorDiv');
	var createPayment = document.getElementById('createPayment');
	if(createPayment!=null){createPayment.style.display="none";}
}
function cancelUpdatePaymentClick()
{
	var updatePayment = document.getElementById('updatePayment');
	if(updatePayment!=null){updatePayment.style.display="none";}
	var updatePaymentResultDiv =document.getElementById('updatePaymentResult');
	if(updatePaymentResultDiv !=null){updatePaymentResultDiv.style.display="none";}
	
}

function closeContactCreationPopup()
{
	 var contactPopUp =document.getElementById('contactpopup');
		if(contactPopUp !=null)
		{
			contactPopUp.style.display="none";
		}
}
function hideUpdateSalesRepDiV(updateSalesRep)
{
		var hideSalesRepDiv = document.getElementById(updateSalesRep);
		if(hideSalesRepDiv!=null)
		{
			hideSalesRepDiv.style.display="none";
		}
}
function searchFunction()
{
	try{
		var backtoSearch=document.getElementById('backtosearch')
        if(backtoSearch !=null)
        {
            backtoSearch.style.display="none";
        }
        var hideadvanceSearch=document.getElementById('hideadavncesearch')
        if(hideadvanceSearch !=null)
        {
            hideadvanceSearch.style.display="none";
        }
        var advancesearch=document.getElementById('adavncesearch')
        if(advancesearch !=null)
        {
            advancesearch.style.display="none";
        }
        

	
	}
catch(error)
{
	alert( error);
}
}
var ccCounter = 0;
function showContactCCList()
{
	var contactCcList  = document.getElementById("contactCCList");
	if(contactCcList==null){alert("You must add contacts to customers to send a CC mail");}
	if(contactCcList!=null)
	{
		contactCcList.style.display="";
		document.getElementById('showCcListLinkDiv').style.display="none";
	}
}
function selectedForCC(contactElemId,contactId,hiddenCustContact)
{
	
	var isPrimary = checkPrimaryContact(contactId,hiddenCustContact);
	if(isPrimary){
		var ccContactError = document.getElementById('ccContactError');
		if(ccContactError!=null){
			ccContactError.style.display="";
			ccContactError.innerHTML="<center> <label class='error' >Contact is Primary</label></center>";}
		return;
	}
	if(ccCounter>3)
	{
		var ccContactError = document.getElementById('ccContactError');
		if(ccContactError!=null){
			ccContactError.style.display="";
			ccContactError.innerHTML="<center> <label class='error' >Cannot Add More than 4</label></center>";}
		return;
	}
	ccCounter = ccCounter + 1;
	var ccContactError = document.getElementById('ccContactError');
	if(ccContactError!=null){
		ccContactError.style.display="none";
	}
	var contactElementId = document.getElementById(contactElemId);
	if(contactElementId!=null)
	{
	var ccContactDiv  = "ccContactDiv" + contactId;
	ccContactDivElem = document.getElementById(ccContactDiv);
	if(ccContactDivElem!=null){ccContactDivElem.style.display="none";}
	
	switch(ccCounter)
	{
		case 1:
			var contactsSelectedForCc = document.getElementById("selectedCcContact1");
			if(contactsSelectedForCc!=null){
				document.getElementById("selectedCcContactDiv1").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('ccToContact1').value=contactId;
				
			}
		break;
		case 2:
			var contactsSelectedForCc = document.getElementById("selectedCcContact2");
			if(contactsSelectedForCc!=null){
				document.getElementById("selectedCcContactDiv2").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('ccToContact2').value=contactId;
			}
			
			break;
		case 3:
			var contactsSelectedForCc = document.getElementById("selectedCcContact3");
			if(contactsSelectedForCc!=null){
				document.getElementById("selectedCcContactDiv3").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('ccToContact3').value=contactId;
			}
			
			break;
		case 4:
			var contactsSelectedForCc = document.getElementById("selectedCcContact4");
			if(contactsSelectedForCc!=null){
				document.getElementById("selectedCcContactDiv4").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('ccToContact4').value=contactId;
			}
			
			break;
	}
	
	}
	
}

function checkPrimaryContact(contactId,hiddenCustContact)
{
	var primaryId = null;
	if(hiddenCustContact==null){
	var primaryIdElem = document.getElementById("custContactHid");
	}else{var primaryIdElem =document.getElementById(hiddenCustContact); }
	if(primaryIdElem!=null){
		primaryId = primaryIdElem.value;
		if(primaryId==contactId)
		{
			
			return true;
		}
	}
	return false;

}
function disselectForCc(removalElemId,labelCounter)
{
	ccCounter = ccCounter -1;
	var idToBeRemoved = null;
	var ccContactError = document.getElementById('ccContactError');
	if(ccContactError!=null){
		ccContactError.style.display="none";
	}
	switch(labelCounter)
	{
		case 1:
			idToBeRemoved = document.getElementById("ccToContact1").value;
			adjustPositionsForCC("selectedCcContact1","selectedCcContact2","ccToContact2","ccToContact1");
			adjustPositionsForCC("selectedCcContact2","selectedCcContact3","ccToContact3","ccToContact2");
			adjustPositionsForCC("selectedCcContact3","selectedCcContact4","ccToContact4","ccToContact3");
			makeNone();
			break;
		case 2:
			idToBeRemoved = document.getElementById("ccToContact2").value;
			adjustPositionsForCC("selectedCcContact2","selectedCcContact3","ccToContact3","ccToContact2");
			adjustPositionsForCC("selectedCcContact3","selectedCcContact4","ccToContact4","ccToContact3");
			makeNone();
		break;
		
		case 3:
			idToBeRemoved = document.getElementById("ccToContact3").value;
			adjustPositionsForCC("selectedCcContact3","selectedCcContact4","ccToContact4","ccToContact3");
			makeNone();
		break;
		case 4:
			idToBeRemoved = document.getElementById("ccToContact4").value;
			makeNone();
		break;
		
	}
	
	if(idToBeRemoved!=null)
	{
		var ccContactDivStr  = "ccContactDiv" + idToBeRemoved;
		var ccContactDiv  = document.getElementById(ccContactDivStr);
		if(ccContactDiv!=null){
			ccContactDiv.style.display="";}
	}
}
function adjustPositionsForCC(targetDivId,currentDivId,contactCcIdShiftFrom,contactCcIdShiftTo)
{
	var currentDivIdElem  = document.getElementById(currentDivId);
	var targetDivIdElem  = document.getElementById(targetDivId);
	var contactCcIdShiftFromElem =document.getElementById(contactCcIdShiftFrom); 
	var contactCcIdShiftToElem =document.getElementById(contactCcIdShiftTo); 
	if(currentDivIdElem!=null && targetDivIdElem!=null){targetDivIdElem.innerHTML = currentDivIdElem.innerHTML;}
	if(contactCcIdShiftFromElem!=null && contactCcIdShiftToElem!=null)
	{
		contactCcIdShiftToElem.value = contactCcIdShiftFromElem.value;
	}
}	

function makeNone()
{
	switch(ccCounter)
	{
		case 0:
			document.getElementById("selectedCcContactDiv1").style.display="none";
			document.getElementById("selectedCcContactDiv2").style.display="none";
			document.getElementById("selectedCcContactDiv3").style.display="none";
			document.getElementById("selectedCcContactDiv4").style.display="none";
			document.getElementById("ccToContact1").value=null;
			document.getElementById("ccToContact2").value=null;
			document.getElementById("ccToContact3").value=null;
			document.getElementById("ccToContact4").value=null;
			break;
		case 1:
			document.getElementById("selectedCcContactDiv2").style.display="none";
			document.getElementById("selectedCcContactDiv3").style.display="none";
			document.getElementById("selectedCcContactDiv4").style.display="none";
			document.getElementById("ccToContact2").value=null;
			document.getElementById("ccToContact3").value=null;
			document.getElementById("ccToContact4").value=null;
			break;
		case 2:
			document.getElementById("selectedCcContactDiv3").style.display="none";
			document.getElementById("selectedCcContactDiv4").style.display="none";
			document.getElementById("ccToContact3").value=null;
			document.getElementById("ccToContact4").value=null;
			break;
		case 3:
			document.getElementById("selectedCcContactDiv4").style.display="none";
			document.getElementById("ccToContact4").value=null;
			break;
		
	}

}
////for update
var updateCcCounter = 0;

function selectedUpdateForCC(contactElemId,contactId)
{
 
	var isPrimary = checkPrimaryContactForUpdate(contactId);
 
	if(isPrimary){
		var ccContactError = document.getElementById('updateCcContactError');
		if(ccContactError!=null){
			ccContactError.style.display="";
			ccContactError.innerHTML="<center> <label class='error' >Contact is Primary</label></center>";}
		return;
	}
	if(updateCcCounter>3)
	{
		var ccContactError = document.getElementById('updateCcContactError');
		if(ccContactError!=null){
			ccContactError.style.display="";
			ccContactError.innerHTML="<center> <label class='error' >Cannot Add More than 4</label></center>"; }
		return;
	}
	updateCcCounter = updateCcCounter + 1;
	var ccContactError = document.getElementById('updateCcContactError');
	if(ccContactError!=null){
		ccContactError.style.display="none";
	}
	var contactElementId = document.getElementById(contactElemId);
	if(contactElementId!=null)
	{
	var ccContactDiv  = "updateCcContactDiv" + contactId;
	ccContactDivElem = document.getElementById(ccContactDiv);
	if(ccContactDivElem!=null){ccContactDivElem.style.display="none";}
	
	switch(updateCcCounter)
	{
		case 1:
			var contactsSelectedForCc = document.getElementById("updateSelectedCcContact1");
			if(contactsSelectedForCc!=null){
				document.getElementById("updateSelectedCcContactDiv1").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('updateCcToContact1').value=contactId;
				
			}
		break;
		case 2:
			var contactsSelectedForCc = document.getElementById("updateSelectedCcContact2");
			if(contactsSelectedForCc!=null){
				document.getElementById("updateSelectedCcContactDiv2").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('updateCcToContact2').value=contactId;
			}
			
			break;
		case 3:
			var contactsSelectedForCc = document.getElementById("updateSelectedCcContact3");
			if(contactsSelectedForCc!=null){
				document.getElementById("updateSelectedCcContactDiv3").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('updateCcToContact3').value=contactId;
			}
			
			break;
		case 4:
			var contactsSelectedForCc = document.getElementById("updateSelectedCcContact4");
			if(contactsSelectedForCc!=null){
				document.getElementById("updateSelectedCcContactDiv4").style.display="";
				contactsSelectedForCc.innerHTML = contactElementId.innerHTML;
				document.getElementById('updateCcToContact4').value=contactId;
			}
			
			break;
	}
	
	}
	
}

function checkPrimaryContactForUpdate(contactId)
{
	var primaryId = null;
	var primaryIdElem = document.getElementById("updateCustContactHidden");
	if(primaryIdElem!=null){
		primaryId = primaryIdElem.value;
		if(primaryId==contactId)
		{
			 
			return true;
		}
	}
	 
	return false;

}
function disselectUpdateForCc(removalElemId,labelCounter)
{
	updateCcCounter = updateCcCounter -1;
	var idToBeRemoved = null;
	var ccContactError = document.getElementById('updateCcContactError');
	if(ccContactError!=null){
		ccContactError.style.display="none";
	}
	switch(labelCounter)
	{
		case 1:
			idToBeRemoved = document.getElementById("updateCcToContact1").value;
			adjustPositionsUpdateForCC("updateSelectedCcContact1","updateSelectedCcContact2","updateCcToContact2","updateCcToContact1");
			adjustPositionsUpdateForCC("updateSelectedCcContact2","updateSelectedCcContact3","updateCcToContact3","updateCcToContact2");
			adjustPositionsUpdateForCC("updateSelectedCcContact3","updateSelectedCcContact4","updateCcToContact4","updateCcToContact3");
			makeNoneUpdate();
			break;
		case 2:
			idToBeRemoved = document.getElementById("updateCcToContact2").value;
			adjustPositionsUpdateForCC("updateSelectedCcContact2","updateSelectedCcContact3","updateCcToContact3","updateCcToContact2");
			adjustPositionsUpdateForCC("updateSelectedCcContact3","updateSelectedCcContact4","updateCcToContact4","updateCcToContact3");
			makeNoneUpdate();
		break;
		
		case 3:
			idToBeRemoved = document.getElementById("updateCcToContact3").value;
			adjustPositionsUpdateForCC("updateSelectedCcContact3","updateSelectedCcContact4","updateCcToContact4","updateCcToContact3");
			makeNoneUpdate();
		break;
		case 4:
			idToBeRemoved = document.getElementById("updateCcToContact4").value;
			makeNoneUpdate();
		break;
		
	}
	
	if(idToBeRemoved!=null)
	{
		var ccContactDivStr  = "updateCcContactDiv" + idToBeRemoved;
		var ccContactDiv  = document.getElementById(ccContactDivStr);
		if(ccContactDiv!=null){
			ccContactDiv.style.display="";}
	}
}
function adjustPositionsUpdateForCC(targetDivId,currentDivId,contactCcIdShiftFrom,contactCcIdShiftTo)
{
	var currentDivIdElem  = document.getElementById(currentDivId);
	var targetDivIdElem  = document.getElementById(targetDivId);
	var contactCcIdShiftFromElem =document.getElementById(contactCcIdShiftFrom); 
	var contactCcIdShiftToElem =document.getElementById(contactCcIdShiftTo); 
	if(currentDivIdElem!=null && targetDivIdElem!=null){targetDivIdElem.innerHTML = currentDivIdElem.innerHTML;}
	if(contactCcIdShiftFromElem!=null && contactCcIdShiftToElem!=null)
	{
		contactCcIdShiftToElem.value = contactCcIdShiftFromElem.value;
	}
}	

function makeNoneUpdate()
{
	switch(updateCcCounter)
	{
		case 0:
			document.getElementById("updateSelectedCcContactDiv1").style.display="none";
			document.getElementById("updateSelectedCcContactDiv2").style.display="none";
			document.getElementById("updateSelectedCcContactDiv3").style.display="none";
			document.getElementById("updateSelectedCcContactDiv4").style.display="none";
			document.getElementById("updateCcToContact1").value=null;
			document.getElementById("updateCcToContact2").value=null;
			document.getElementById("updateCcToContact3").value=null;
			document.getElementById("updateCcToContact4").value=null;
			break;
		case 1:
			document.getElementById("updateSelectedCcContactDiv2").style.display="none";
			document.getElementById("updateSelectedCcContactDiv3").style.display="none";
			document.getElementById("updateSelectedCcContactDiv4").style.display="none";
			document.getElementById("updateCcToContact2").value=null;
			document.getElementById("updateCcToContact3").value=null;
			document.getElementById("updateCcToContact4").value=null;
			break;
		case 2:
			document.getElementById("updateSelectedCcContactDiv3").style.display="none";
			document.getElementById("updateSelectedCcContactDiv4").style.display="none";
			document.getElementById("updateCcToContact3").value=null;
			document.getElementById("updateCcToContact4").value=null;
			break;
		case 3:
			document.getElementById("updateSelectedCcContactDiv4").style.display="none";
			document.getElementById("updateCcToContact4").value=null;
			break;
		
	}

}
function  backofficeDates()
{
	
	var poDateCal = new dhtmlxCalendarObject('instrumentdate');
	poDateCal.setDateFormat('%d %b %Y');
	
}
function hideExpirydiv(){
	var accPopup = null;
	accPopup = document.getElementById("expiryDatePupupMessage");
	accPopup.innerHTML = "";
	accPopup.style.display = "none";
}

function showExpirydate(billsLeft, daysLeft ){
	
		var expiryDaysLeft = 0;
		var expiryBillsLeft = 0;
		var showBills = false;
		//alert("days left "+daysLeft+" Bills Left "+billsLeft);
		
		if(billsLeft != "Tons"){
		expiryBillsLeft = Number(billsLeft);
		showBills=true;
		}
		expiryDaysLeft = Number(daysLeft);
		var accPopup = null;
		accPopup = document.getElementById("expiryDatePupupMessage");
		var errorMessage = "";
		
		if(showBills && expiryBillsLeft <= 5){
			errorMessage = "You can create only "+expiryBillsLeft+" more bills";
			if(expiryBillsLeft == 1){
				errorMessage = "You can create only "+expiryBillsLeft+" more bills";
			}
		}
		if(expiryDaysLeft <= 5){
			if(errorMessage == ""){
				
				errorMessage = "Your account will expire in "+expiryDaysLeft+" days ";
				if(expiryDaysLeft < 0){
					errorMessage = "Your account has expired";
				}else if(expiryDaysLeft == 1 ){
					errorMessage = "Your account will expire in "+expiryDaysLeft+" day ";
				}
			}else{
				
				if(expiryDaysLeft < 0){
					errorMessage = errorMessage+" and "+ "your account has expired";
				}else if(expiryDaysLeft == 1 ){
					errorMessage = errorMessage+" and "+ "your account will expire in "+expiryDaysLeft+" day ";
				}else{
					errorMessage = errorMessage+" and "+ "your account will expire in "+expiryDaysLeft+" days ";
				}
				
				
				
			}
		}
		
		if(accPopup != null){
			var accMessage = null;
			accMessage = document.getElementById("expiryDatePupupMessage");
			accMessage.innerHTML="<center> <label class='error' >"+errorMessage+"</label></center>";
			
			accMessage.style.display = "";
		}
		if(errorMessage ==""){
			accMessage.innerHTML="";
			accPopup.style.display = "none";
			return;
		}else{
			accPopup.style.display = "";
			dobj = accPopup;
		}
		
		setTimeout("hideExpirydiv()",10000);
		
		
	
}

function resetCheckDirtyForm()
{setTimeout("javascript:checkDirtyForm = false",1000);}
function checkForDirtyForm(){
	if(checkDirtyForm){
		//var response=confirm("Save/Update button was not clicked. Would you like to move away from this page without saving?");
		var response = true;
		if(response==false){return false;}
		else{checkDirtyForm = false;return true;}
	}
	return true;
}
function registerFormForDirtyCheck(formId)
{
	 new Form.Observer(formId, 0.1, function(form, value) {
		 checkDirtyForm = true;	
		 //alert(checkDirtyForm + " " + formId );
	});
}
	
function clearBillHiddenInputFields(id1,id2,id3,id4)
{
	//alert('inside clear function');
	try
	{
		if(id1!=null)
		{
			var inputHiddenField1 = document.getElementById(id1);
			if(inputHiddenField1.value!="")
			{
				//alert(inputHiddenField1.value);
				inputHiddenField1.value="";
			}else{
				//alert('1');
			}
		}	
		if(id2!=null)
		{
			var inputHiddenField2 = document.getElementById(id2);
			if(inputHiddenField2.value!="")
			{
				//alert(inputHiddenField2.value);
				inputHiddenField2.value="";
			}else{
				//alert('2');
			}
		}	
		if(id3!=null)
		{
			var inputHiddenField3 = document.getElementById(id3);
			
			if(inputHiddenField3.value!="")
			{
				//alert(inputHiddenField3.value);
				inputHiddenField3.value="";
			}else{
				//alert('3');
			}
		}	
		if(id4!=null)
		{
			var inputHiddenField4 = document.getElementById(id4);
			if(inputHiddenField4.value!="")
			{
				//alert(inputHiddenField4.value);
				inputHiddenField4.value="";
			}else{
				//alert('4');
			}
		}	
	
	}
	catch(error)
	{
		  alert(error);
	 }
 }	
function callLater()
{
	if(callLaterArray!=null){
		for(i=0;i<callLaterArray.length;i++)
		{
			callLaterArray[i]();
		}
	}
	callLaterArray = new Array();
}

function deleteContactConfirmation(contactDetailIds,callProcBy){
	
		if(contactDetailIds!=null)
		{
			submitSingleField(contactDetailIds,callProcBy);
			
		}
	
}

function shortClosePopUp(checkBoxId,divId)
{
	//alert(divId);
	
	var openShortClosePopUp = document.getElementById(divId);
	//alert(openShortClosePopUp);
	if(openShortClosePopUp !=null)
	{
		if(checkBoxId!=null)
		//	alert(checkBoxId);
		//	alert(checkBoxId.checked);
			if(checkBoxId.checked)
			{
				openShortClosePopUp.style.display="";
				dobj=openShortClosePopUp;
			}else{
				openShortClosePopUp.style.display="none";
				dobj=openShortClosePopUp;
			}
	}
	
}

function closeShortClosePopup(divId)
{
	var openShortClosePopUp = document.getElementById(divId);
	if(openShortClosePopUp !=null)
	{
		openShortClosePopUp.style.display="none";
	}
}








function replaceDeleteContact(formName,dest)
{
	
	submitData(formName,dest);
}
function deleteSalesRepresentatives(obj)
{
	
	var response=confirm("Are You Sure You Wish to Delete This Sales Representative?");
	
	//alert(obj);
	//alert(divId);
	if(response==true)
	{
		if(obj!=null)
		{
			submitSingleField([obj],'checkBeforeDeletionOfSalesRep');
		}	
	}else{
		
	}
}

 

function setValueOfAutoEmail(obj,buttonOffId,buttonOnId)
{
	//alert(obj);
	var valueOfautoEmailsbuttonInputVariable = document.getElementById('valueOfautoEmailsbuttonInputId');
	//alert(valueOfautoEmailsbuttonInputVariable);
	if(valueOfautoEmailsbuttonInputVariable !=null)
	{
		valueOfautoEmailsbuttonInputVariable.value=obj;
		//alert(valueOfautoEmailsbuttonInputVariable.value);
	}
	var buttonOffVariable= document.getElementById(buttonOnId);
	if(buttonOffVariable!=null)
	{
		buttonOffVariable.style.display="";
		
	}
	var buttonOnVariable= document.getElementById(buttonOffId);
	if(buttonOnVariable!=null)
	{
		buttonOnVariable.style.display="none";
		
	}
}
function setValueOfAutoSms(obj,buttonOffId,buttonOnId)
{
	//alert(obj);
	var valueOfautoSmsbuttonInputVariable = document.getElementById('valueOfautoSmsbuttonInputId');
	//alert(valueOfautoSmsbuttonInputVariable);
	if(valueOfautoSmsbuttonInputVariable !=null)
	{
		valueOfautoSmsbuttonInputVariable.value=obj;
		//alert(valueOfautoSmsbuttonInputVariable.value);
	}
	var buttonOffVariable= document.getElementById(buttonOnId);
	if(buttonOffVariable!=null)
	{
		buttonOffVariable.style.display="";
		
	}
	var buttonOnVariable= document.getElementById(buttonOffId);
	if(buttonOnVariable!=null)
	{
		buttonOnVariable.style.display="none";
		
	}
}

 function adjustPaymentSelected(obj)
 {
	 
	 var adjustPaymentHiddenId  = document.getElementById('adjustPaymentHiddenId');
	 if(adjustPaymentHiddenId!=null){
		 
		 if(obj.id="noAdjustment")
		 {
			 var errormsgDiv=document.getElementById('errormsgDiv');
			 
			 if(errormsgDiv !=null)
			 {					 
				 errormsgDiv.style.display="none";
				 errormsgDiv.innerHTML="";
				 var okbuton=document.getElementById('okButton');
				 if(okbuton !=null)
				 {
					 okbuton.disabled="";
				 }
				 
			 }
		 }
		 adjustPaymentHiddenId.value = obj.value;
		 }
 }
 function closeAdjustPayment()
 {
	 var adjustPaymentHiddenId  = document.getElementById('adjustPaymentHiddenId');
	 if(adjustPaymentHiddenId!=null){adjustPaymentHiddenId.value = "";}
	 var noAdjustment  = document.getElementById('noAdjustment');
	 if(noAdjustment!=null){noAdjustment.checked = "true";}
	 var openAdvPaymentPopupDiv  = document.getElementById('openAdvPaymentPopupDiv');
	 if(openAdvPaymentPopupDiv!=null){openAdvPaymentPopupDiv.style.display="none";}
 }
 function resetAdjusetPayment()
 {
	 var adjustPaymentHiddenId  = document.getElementById('adjustPaymentHiddenId');
	 if(adjustPaymentHiddenId!=null){adjustPaymentHiddenId.value = "";}
	 var noAdjustment  = document.getElementById('noAdjustment');
	 if(noAdjustment!=null){noAdjustment.checked = "true";}
}
 function okAdjustPayment()
 {
	 var openAdvPaymentPopupDiv  = document.getElementById('openAdvPaymentPopupDiv');
	
	 
	 if(openAdvPaymentPopupDiv!=null)
	 {
		 var amtrecevdpopup =document.getElementById("amountRecvdpopup");
		 if(amtrecevdpopup !=null)
		 {
			 var amtreceived4mpopup=amtrecevdpopup.value;
			 
			 var amountReceived =document.getElementById("amountRecvd");
			 amountReceived.value=amtreceived4mpopup;
			 //alert("amtrecevdpopup" + amtrecevdpopup.Value);
			 changeValuePending();
			 openAdvPaymentPopupDiv.style.display="none";
			 
		 }
		 
		 
		 
	 } 
 }
 
function setamount()
{
	 var amountReceivedText =document.getElementById("amountRecvd");
 	
	 if(amountReceivedText !=null  )
		{
		 var amtReceive=amountReceivedText.value;
		 
		 var amtrecevdpopup = document.getElementById("amountRecvdpopup");
		 amtrecevdpopup.value=amtReceive;
		 
		}

}


function validateamt(value1)
{
	if(value1 !=null)
	{
		 var amtrecevdpopup = document.getElementById("amountRecvdpopup");
		 if(amtrecevdpopup!=null)
		 {
			 var amtreceivedval=amtrecevdpopup.value;
			
			 if(amtreceivedval >value1)
			 {
					
				var errormsgDiv=document.getElementById('errormsgDiv');
				
				 if(errormsgDiv !=null)
				 {					 
					 errormsgDiv.style.display="";
					 errormsgDiv.innerHTML="<center> <label class='error' >mismatching values of amt received and adjustment amt selected</label></center>";
					 var okbuton=document.getElementById('okButton');
					 if(okbuton !=null)
					 {
						 okbuton.disabled="disabled";
					 }
					 
				 }
				
				 return false;
			 }
			 else  if(amtreceivedval ='')
			 {
				 var errormsgDiv=document.getElementById('errormsgDiv');
				 
				 if(errormsgDiv !=null)
				 {					 
					 errormsgDiv.style.display="";
					 errormsgDiv.innerHTML="<center> <label class='error'>Enter amount to be adjusted </label></center>";
					 
					 var okbuton=document.getElementById('okButton');
					 if(okbuton !=null)
					 {
						 okbuton.disabled="disabled";
					 }
				 }
				
				 return false;
			 }
			 else 
			 {
				 var errormsgDiv=document.getElementById('errormsgDiv');
				 
				 if(errormsgDiv !=null)
				 {					 
					 errormsgDiv.style.display="none";
					 errormsgDiv.innerHTML="";
					 var okbuton=document.getElementById('okButton');
					 if(okbuton !=null)
					 {
						 okbuton.disabled="";
					 }
					 
				 }
				 return true;
			 }
		 }
		 else
		 { 	 
			 var errormsgDiv=document.getElementById('errormsgDiv');
			 
			 if(errormsgDiv !=null)
			 {					 
				 errormsgDiv.style.display="";
				 errormsgDiv.innerHTML="<center> <label class='error' >Enter amount to be adjusted </label></center>";
				 var okbuton=document.getElementById('okButton');
				 if(okbuton !=null)
				 {
					 okbuton.disabled="disabled";
				 }
			 }
			 
			 return false;
		 } 
	}
	else
	{
		 var okbuton=document.getElementById('okButton');
		 if(okbuton !=null)
		 {
			 okbuton.disabled="";
		 }
		 return true;
	}
}


function noadjustmentselected()
{
	var radio_noadjust=document.getElementById('noAdjustment');
	if(radio_noadjust !=null)
	{
		radio_noadjust.checked="checked";
	
		 var errormsgDiv=document.getElementById('errormsgDiv');
		 
		 if(errormsgDiv !=null)
		 {					 
			 errormsgDiv.style.display="none";
			 errormsgDiv.innerHTML="";
			 var okbuton=document.getElementById('okButton');
			 if(okbuton !=null)
			 {
				 okbuton.disabled="";
			 }
			 
		 }
	}
}
function openAdvPaymentDiv(divId)
{
	var openAdvPaymentDivId = document.getElementById(divId);
	if(openAdvPaymentDivId!=null)
	{
		openAdvPaymentDivId.style.display="";
	}
	
}

function closeAdvPayDiv(divId)
{
	var openAdvPaymentDivId1 = document.getElementById(divId);
	if(openAdvPaymentDivId1!=null)
	{
		openAdvPaymentDivId1.style.display="none";
	}
}

function closeAdvPaymentDiv(divId)
{
	var openAdvPaymentDivId1 = document.getElementById(divId);
	if(openAdvPaymentDivId1!=null)
	{
		openAdvPaymentDivId1.style.display="none";
	}
	var noAdjustmentselected=document.getElementById('noAdjustment');
	if(noAdjustmentselected!=null)
	{
		noAdjustmentselected.checked = "true";
	}
	
	var amountentered=document.getElementById('amount');
	if(amountentered !=null)
	{
		amountentered.value="";
	}
	
	var errormsgDiv=document.getElementById('errormsgDiv');
	
	 if(errormsgDiv !=null)
	 {					 
		 errormsgDiv.style.display="none";
		 errormsgDiv.innerHTML="";
		 
		 var amtfield = document.getElementById('amount');
		 if(amtfield !=null)
		 {
		 clearMandatoryFieldsErrors(['amount'],'errormsgDiv');
		 }
		 
	 }
	 
	 
	
}

function validateAdvancePayment(value1,amtPending)
{
	
	if(value1 !=null)
	{
		 var amtrecevdpopup = document.getElementById("amount");
		 if(amtrecevdpopup!=null)
		 {
			 var amtreceivedval=amtrecevdpopup.value;

			
			 
			 if(amtreceivedval<= amtPending)
			 {
			 
				 if(amtreceivedval >value1)
				 {
						
					var errormsgDiv=document.getElementById('errormsgDiv');
					
					 if(errormsgDiv !=null)
					 {					 
						 errormsgDiv.style.display="";
						 errormsgDiv.innerHTML="<center> <label class='error' >mismatching values of amt received and adjustment amt selected</label></center>";
						 var okbuton=document.getElementById('okButton');
						 if(okbuton !=null)
						 {
							 okbuton.disabled="disabled";
						 }
						 
					 }
					
					 return false;
				 }
				 else  if(amtreceivedval ='')
				 {
					 var errormsgDiv=document.getElementById('errormsgDiv');
					 
					 if(errormsgDiv !=null)
					 {					 
						 errormsgDiv.style.display="";
						 errormsgDiv.innerHTML="<center> <label class='error'>Enter amount to be adjusted </label></center>";
						 
						 var okbuton=document.getElementById('okButton');
						 if(okbuton !=null)
						 {
							 okbuton.disabled="disabled";
						 }
					 }
					
					 return false;
				 }
				 else 
				 {
					 var errormsgDiv=document.getElementById('errormsgDiv');
					 
					 if(errormsgDiv !=null)
					 {					 
						 errormsgDiv.style.display="none";
						 errormsgDiv.innerHTML="";
						 var okbuton=document.getElementById('okButton');
						 if(okbuton !=null)
						 {
							 okbuton.disabled="";
						 }
						 
					 }
					 return true;
				 }
				
			 }
			 else if(amtreceivedval ='')
			 {
				 var errormsgDiv=document.getElementById('errormsgDiv');
				 
				 if(errormsgDiv !=null)
				 {					 
					 errormsgDiv.style.display="";
					 errormsgDiv.innerHTML="<center> <label class='error'>Enter amount to be adjusted </label></center>";
					 
					 var okbuton=document.getElementById('okButton');
					 if(okbuton !=null)
					 {
						 okbuton.disabled="disabled";
					 }
				 }
				
				 return false;
			 }
			 else // amount received cannot b greated than amount pending
			 {
				 var errormsgDiv=document.getElementById('errormsgDiv');
					
				 if(errormsgDiv !=null)
				 {					 
					 errormsgDiv.style.display="";
					 errormsgDiv.innerHTML="<center> <label class='error' >Payment cannot be more than the amount pending</label></center>";
					 var okbuton=document.getElementById('okButton');
					 if(okbuton !=null)
					 {
						 okbuton.disabled="disabled";
					 }
					 
				 }
				
				 return false;
				
			 }
			 
		 }
		 else //amount received is null
		 { 	 
			 var errormsgDiv=document.getElementById('errormsgDiv');
			 
			 if(errormsgDiv !=null)
			 {					 
				 errormsgDiv.style.display="";
				 errormsgDiv.innerHTML="<center> <label class='error' >Enter amount to be adjusted </label></center>";
				 var okbuton=document.getElementById('okButton');
				 if(okbuton !=null)
				 {
					 okbuton.disabled="disabled";
				 }
			 }
			 
			 return false;
		 } 
	}
	else // value1 is null i.e no adjustment amount selected
	{
		var errormsgDiv=document.getElementById('errormsgDiv');
		 
		 if(errormsgDiv !=null)
		 {					 
			 errormsgDiv.style.display="";
			 errormsgDiv.innerHTML="<center> <label class='error' >No adjustment amount selected...close if u don't want to adjust </label></center>";
			 var okbuton=document.getElementById('okButton');
			 if(okbuton !=null)
			 {
				 okbuton.disabled="disabled";
			 }
		 }
		 
		 return false;
		
		
//		 var okbuton=document.getElementById('okButton');
//		 if(okbuton !=null)
//		 {
//			 okbuton.disabled="";
//		 }
//		 return true;
	}
}






function submitadjustpaymentform()
{
	 if(checkForMandatoryFields(['amount'],null,'errormsgDiv'))
		 {
		 	
		 	//var adjustFromselId=document.getElementById('adjustFromId');
			var noadjustmentsel=document.getElementById('noAdjustment');
//		 	if(adjustFromselId == null)
//		 	{
//		 		alert ("aaaaaaaaaaaa adjustFromselId");
//		 		}
			
//		 	if(noadjustmentsel == null)
//		 	{
//		 		alert ("noadjustmentsel null");
//		 	}
			
			if(noadjustmentsel !=null)
			{
					if(noadjustmentsel.checked== false)
					{
						// alert("in submit form");		
						submitData('openAdvPaymentForm','adjustpayment');
						return true;
						
						
					 }
					 else if(noadjustmentsel.checked == true)
					 {					
						 var errormsgDiv=document.getElementById('errormsgDiv');
						
						 if(errormsgDiv !=null)
						 {	
							  // alert("in show eror msg ");			 
							 errormsgDiv.style.display="";
							 errormsgDiv.innerHTML="<center> <label class='error' >select some option to adjust</label></center>";
							
							return false;
						 }
										
								
					 }
					
				}
			
		 	
		 	
			 }
			
		 
}


function movepopup()
{

	var advPaymentPopupDiv  = document.getElementById('openAdvPaymentPopupDiv');
	if(advPaymentPopupDiv!=null)
	{
		advPaymentPopupDiv.style.display="";
		dobj = advPaymentPopupDiv;
	}
	
}


function movepopup_billpay()
{
	var advPaymentPopupDiv  = document.getElementById('openAdvPayment');
	if(advPaymentPopupDiv!=null)
	{
		advPaymentPopupDiv.style.display="";
		dobj = advPaymentPopupDiv;
	}
}


function moveshowadvancespopup()
{

	var advPaymentPopupDiv  = document.getElementById('show_AdvPaymentDetailsDiv');
	if(advPaymentPopupDiv!=null)
	{
		advPaymentPopupDiv.style.display="";
		dobj = advPaymentPopupDiv;
	}
	
}

function closeshowPayment()
{
	
	 var openAdvPaymentPopupDiv  = document.getElementById('show_AdvPaymentDetailsDiv');
	 if(openAdvPaymentPopupDiv!=null){openAdvPaymentPopupDiv.style.display="none";}
	 var msg= document.getElementById('errormsgDiv');
		if(msg !=null)
		{
		msg.style.display="none";
		msg.innerHTML="";
		}
}


function deleteadvpayment(advid)
{	var msg= document.getElementById('errormsgDiv');
	if(msg !=null)
	{
	msg.style.display="none";
	msg.innerHTML="";
	}
	var response=confirm('Are you sure you wish to delete this payment?');
	if(response = true)
	{	
		var advpayid=document.getElementById('advpaymentListDiv'+advid);
		if(advpayid !=null)
		{
			
		submitSingleField(['hiddenPaymentId'+advid],'deleteadvancepayment');
		
		advpayid.style.display="none";
		
			var msg1= document.getElementById('errormsgDiv');
			if(msg1 !=null)
			{	msg1.style.display="";
				msg1.innerHTML="<center> <label class='success' >Advance Deleted</label></center>";
			
			}
		
		}
	}
}

function makeFastPaymentJs()
{ 
	try{
	var billIdArray = new Array();
	var makePaymentForm= document.getElementById('makeFastPaymentFormId');
	if(makePaymentForm!=null)
	{
		for (var i =0; i < makePaymentForm.elements.length; i++) 
		{
			if(makePaymentForm.elements[i].checked)
			{
				var checkBoxId = makePaymentForm.elements[i].id;
			//	alert(checkBoxId);
				if(checkBoxId!=null)
				{
					//alert(checkBoxId);
					var cust=checkBoxId.lastIndexOf("_");
					if(cust!=-1)
					{
						var new_cust=cust+1;
						var bill_id = checkBoxId.substring(new_cust,1000);
						if(bill_id)
						{
						//	alert('billid--------'+bill_id);
							billIdArray[billIdArray.length]=bill_id
							//alert(billIdArray[billIdArray.length-1]);
						}
						// alert('bill_noArray---------'+billIdArray.length);
					}
				}
			}
		}
	
	  var hiddenBillIdMakeFastPayment = document.getElementById('makefastPaymentHiddenbillId');
		 
		if(hiddenBillIdMakeFastPayment!=null)
		{
			var billIdsToString= billIdArray.toString();
			//alert(billIdsToString);
			hiddenBillIdMakeFastPayment.value=billIdsToString;
		}
	}
	// submitData('makeFastPaymentFormId','makeFastPayment');
	submitSingleField(['makefastPaymentHiddenbillId'],'makeFastPayment');
	}
	catch(error)
	{
		alert(error.message);
	}
}
function selectAllBillsOfCustomer123(tableId)
{
	try{
	//	alert('hi');
		// alert(tableId);
		var checked = false;
		var checkBoxes = new Array();
		var table = document.getElementById(tableId);
		if(table.checked)
		{
		//	alert('checked');
			checked=true;
		}
		else{
		//	alert('not checked');
			checked = false;
		}
		var inputs = document.getElementsByTagName("input");
	//	alert('inputs-----'+inputs);
		
		if(inputs!=null)
		{
			// alert('inputs.length----'+inputs.length);
			
			for(var i=0;i<inputs.length;i++)
			{
				if(!inputs[i].length)
				{
					if(inputs[i].type=="checkbox")
					{
						 
						checkBoxes[checkBoxes.length]=inputs[i];
					}
					else
					{
						//alert('else me aaya');
						for(k=0;k<inputs[i].length;k++)
						{
							if(inputs[i][k].type=="checkbox")
							{
								 
								checkBoxes[checkBoxes.length]=inputs[i];
							}
						}
					}
				}
			}
			// alert('checkBoxes.length------'+checkBoxes.length);
			for(var z=0;z<checkBoxes.length;z++)
			{
				//alert(checkBoxes[z].id);
				var checkBoxIdOfCustomer= checkBoxes[z].id;
				if(checkBoxIdOfCustomer!=null)
				{
					var foundPosition = checkBoxIdOfCustomer.lastIndexOf("_");
					var customerId = checkBoxIdOfCustomer.substring(0,foundPosition);
					//alert('customerId-----'+customerId);
				}
				if(customerId==tableId)
				{
					//alert('hi');
					if(checked){
						checkBoxes[z].checked=true;
					}else{
						checkBoxes[z].checked=false;
					}
				}
			}
		}
	}
	catch(e)
	{
		alert('Js Error-----------------'+e.message);
	}
}

function refreshMakeFastPayment()
{
	submitSingleField(['makeFastPaymentLabel'],'getAllBillsForCustomers');
}

function selectAllCheckBoxes(formId,selectAll)
{
	var checked = false;
	var checkBoxArray = new Array();
	var makePaymentForm = document.getElementById(formId);
	var selectAllCheckBox = document.getElementById(selectAll);
	if(selectAllCheckBox.checked)
	{
		checked=true;
	}
	else{
		checked = false;
	}
	if(makePaymentForm!=null)
	{
		checkBoxArray = makePaymentForm.getElementsByTagName("input");
		if(checkBoxArray!=null)
		{
			for(var i=0;i<checkBoxArray.length;i++)
			{
				if(!checkBoxArray[i].length)
				{
					if(checkBoxArray[i].type=="checkbox")
					{
						checkBoxArray[checkBoxArray.length]=checkBoxArray[i];
					}
					else
					{
						//alert('else me aaya');
						for(k=0;k<checkBoxArray[i].length;k++)
						{
							if(checkBoxArray[i][k].type=="checkbox")
							{
								checkBoxArray[checkBoxes.length]=checkBoxArray[i];
							}
						}
					}
				}
			}
			for(var z=0;z<checkBoxArray.length;z++)
			{
				if(checked)
				{
					checkBoxArray[z].checked=true;
				}else{
					checkBoxArray[z].checked=false;
				}
		    }
			}
		}
	}
 


