var xmlHttp 
var origamount=0;
var jsonData;
var creditCardInfo;
var loopid;
var loopid1;
var echeckInfo;
var checkflag;
var cardStatus;
var wikipaySubmitStatus=0;
var loopid_card;
var mform;
var mform_documents;

function addbanklogic(url, divid, formobj)
{ 
	var params ="submit12="+formobj.submit.value+
				"&institution_name="+formobj.institution_name.value+
				"&account_type_id="+formobj.account_type_id.value+
				"&name_on_account="+formobj.name_on_account.value+
				"&secondname="+formobj.secondname.value+
				"&routing="+formobj.routing.value+
				"&account="+formobj.account.value+
				"&confirm_account="+formobj.confirm_account.value+
				"&address1="+formobj.address1.value+
				"&address2="+formobj.address2.value+
				"&city="+formobj.city.value+
				"&state="+formobj.state.value+
				"&zip="+formobj.zip.value+
				"&post="+formobj.post.value+
				"&id="+formobj.id.value	; 

	 xmlHttp=GetXmlHttpObject()		 
	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	

	var url =url+'?'+params;    
	url = url;	 
	xmlHttp.onreadystatechange=processResponse	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null) 
}

function processResponse()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{  
		document.getElementById('showdetails').innerHTML	= xmlHttp.responseText;
	}
}
function getCheckedRadioValue(radioObj)
{
	if(!radioObj)
			return "";
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				return radioObj.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
}

function ajaxPhotoSettings(formobj,id)
{
	mform=formobj;
	 mform.showdetails.value ="";
	var defa=getCheckedRadioValue(formobj.default1);
	var disp=getCheckedRadioValue(formobj.display);
	var des=formobj.description.value
	var params ="&caption="+formobj.photo_caption.value+"&default1="+defa+"&id="+id+"&display="+disp+"&description="+des;
	 xmlHttp=GetXmlHttpObject()		 
	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url = "/classifieds/edit_photo_settings";
	url =url+'?'+params;    
	url = url;	 
	xmlHttp.onreadystatechange=edit_photo_settings_processResponse	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)  
				

}
function edit_photo_settings_processResponse()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{  
		 mform.showdetails.value ="";
		 mform.showdetails.value	= xmlHttp.responseText;
		
	}
}


function ajaxDocumentSettings(formobj,id)
{
	mform_documents=formobj;
	mform_documents.showdetails_documents.value ="";
	var disp=getCheckedRadioValue(formobj.display);
	var des=formobj.description.value
	var params ="&caption="+formobj.photo_caption.value+"&id="+id+"&display="+disp+"&description="+des;
	 xmlHttp=GetXmlHttpObject()		 
	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url = "/classifieds/edit_document_settings";
	url =url+'?'+params;    
	url = url;	 
	xmlHttp.onreadystatechange=edit_document_settings_processResponse	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)  
				

}
function edit_document_settings_processResponse()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{  
		 mform_documents.showdetails_documents.value ="";
		 mform_documents.showdetails_documents.value	= xmlHttp.responseText;
		
	}
}


function ajaxtransferfunds(formobj)
{ 
	document.getElementById('showdetails').innerHTML ="Processing ...."; 

	var mode12 =0; 

	if(formobj.mode[0].checked == true)
	{
		 mode12 = formobj.mode[0].value;
	}
	else if(formobj.mode[1].checked == true)
	{
		mode12 = formobj.mode[1].value;
	}
	else if(formobj.mode[2].checked == true)
	{
		mode12 = formobj.mode[2].value;
	}
	else if(formobj.mode[3].checked == true)
	{
		mode12 = formobj.mode[3].value;
	}
	else if(formobj.mode[4].checked == true)
	{
		mode12 = formobj.mode[4].value;
	}
	
	
	var bankaccount_num =0;
	
	if(mode12 == "FROM_WIKI")
	{
		bankaccount_num = formobj.to_bankname.value;
	}
	else if (mode12 == "TO_WIKI")
	{
		bankaccount_num = formobj.from_bankname.value;
	}
	else if (mode12 == "WIKI_WIKI")
	{
		bankaccount_num = formobj.wiki_bankname.value;
	}
	else if(mode12 == "WIKI_WIKIPAY")
	{
	bankaccount_num = formobj.wiki_bankname.value;
	} 
	else if(mode12 == "WIKIPAY_WIKI")
	{
	bankaccount_num = formobj.wikipay_account_number.value;
	}

	var params ="submit12="+formobj.submit.value+
				"&total_amount="+formobj.total_amount.value+
				"&service_fee="+formobj.service_fee.value+
				"&paywhen="+formobj.paywhen.value+
				"&payfrom="+formobj.payfrom.value+
				"&payto="+formobj.payto.value+
				"&current_bal="+formobj.current_bal.value+
				"&balance="+formobj.balance.value+
				"&mode="+mode12+ 
				"&bank_finacial_account_id="+bankaccount_num+
				"&amount="+formobj.amount.value;
	
	
	
	
	
	
	xmlHttp=GetXmlHttpObject()		 
	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url = "/myaccount/transferfunds";
	url =url+'?'+params;    
	url = url;	 
	xmlHttp.onreadystatechange=transferfunds_processResponse	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)  
	 
}
function transferfunds_processResponse()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{    
		if(xmlHttp.responseText==1)
		{  
			window.location.href="/myaccount/edit_bank";
		}
		else
		{  
			document.getElementById('showdetails').innerHTML ="";
			document.getElementById('showdetails').innerHTML= xmlHttp.responseText;
		}
	}
}











function discountfunc(discountcode,a)
{   
	origamount=a; 
	if(discountcode.length==0)
	{  
		document.getElementById("ccamount").value	= a;  
		document.getElementById("Echeckamt").value	= a;  
		document.getElementById("discountcode_status").innerHTML	= "";
		return
	}
  
	xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="myaccount/retrive_discountamount?discountcode="+discountcode;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChanged	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
	
}  
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			document.getElementById("ccamount").value					= origamount;
			document.getElementById("Echeckamt").value					= origamount; 
			document.getElementById("discountcode_status").innerHTML	= "Invalid Discount Code or Discount Code Already Used.";
			
		}
		else
		{
			var disc_deducted_amount = origamount - xmlHttp.responseText; 
			
			document.getElementById("ccamount").value					= disc_deducted_amount ;
			document.getElementById("Echeckamt").value					= disc_deducted_amount ; 
			document.getElementById("discountcode_status").innerHTML	= "<font color='green' >Price :<strike>$"+origamount+"</strike>   $"+disc_deducted_amount+"<font>";    

		}
	} 
}  

function retrive_service_fee(amount,purpose)
{
xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="/myaccount/retrive_service_fee?amount="+amount+"&purpose="+purpose;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedServiceFee;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
}
function stateChangedServiceFee()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{
			var  myString = xmlHttp.responseText;
			jsonData=eval('('+myString+')');
			var service_fee=jsonData.service_fee;
			var s_fee=jsonData.service_fee;
			var amount=jsonData.amount;
			var trans_amount=jsonData.transcation_amount;
			var total_amount=jsonData.total_amount;
		
			if(document.getElementById("to_wiki").checked==true)
			{
				document.getElementById("payto").value="swapadebt";
				document.getElementById("payfrom").value="";
				
				var roundbal2	= parseFloat(document.getElementById("current_bal").value)+parseFloat(amount);
				var bal			= roundbal2.toFixed(2);
				 
			
			}
			if(document.getElementById("from_wiki").checked==true)
			{
				
				document.getElementById("payfrom").value="swapadebt";
				document.getElementById("payto").value="";

				var roundba23	= parseFloat(document.getElementById("current_bal").value)-parseFloat(amount)-parseFloat(service_fee);
				var bal			= roundba23.toFixed(2);
				
			}
			if(document.getElementById("wiki_wiki").checked==true)
			{ 	 
				var roundba34	= parseFloat(document.getElementById("current_bal").value)-parseFloat(amount)-parseFloat(service_fee);
				var bal			= roundba34.toFixed(2); 
			}
			if(document.getElementById("wiki_wikipay").checked==true)
			{ 	
				document.getElementById("payfrom").value="swapadebt";
				document.getElementById("payto").value="";

				var roundba23	= parseFloat(document.getElementById("current_bal").value)-parseFloat(amount)-parseFloat(service_fee);
				var bal			= roundba23.toFixed(2);
				
			}
			if(document.getElementById("wikipay_wiki").checked==true)
			{ 	
				document.getElementById("payto").value="swapadebt";
				document.getElementById("payfrom").value="";
				
				var roundbal2	= parseFloat(document.getElementById("current_bal").value)+parseFloat(amount);
				var bal			= roundbal2.toFixed(2);
				
			}
			  
					
			if(amount!=0)
			{
			document.getElementById("amount").value	= amount;
			document.getElementById("total_amount_display").innerHTML	= '$'+total_amount;
		
			document.getElementById("s_fee").innerHTML	= '$'+s_fee;
			document.getElementById("t_amount").innerHTML	= '$'+trans_amount;
			document.getElementById("bal").innerHTML	= '$'+bal;
			document.getElementById("total_amount_display").style.display = 'block';
			document.getElementById("total_amount").value	= total_amount;
			document.getElementById("service_fee").value	= service_fee;
			document.getElementById("s_fee").style.display 	= 'block'; 
			document.getElementById("t_amount").style.display = 'block'; 
			document.getElementById("bal").style.display = 'block'; 
			}
			else
			{
			document.getElementById("total_amount_display").style.display = 'none';
			document.getElementById("s_fee").style.display 	= 'none'; 
			document.getElementById("t_amount").style.display = 'none'; 
			document.getElementById("bal").style.display = 'none'; 
			}
		}
	}
}

function wikipayemi(loanid)
{
xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="/myaccount/retrive_wikipay?loan_id="+loanid;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedwikipay;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)

} 

function stateChangedwikipay()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{
			var  myString = xmlHttp.responseText;
			jsonData=eval('('+myString+')');
			var emi_loan_amount=jsonData.payoff_amount;
			var emi_loan_balance=jsonData.balance;
			var emi_loan_due_date=jsonData.payment_due_date;
			var service_fee=jsonData.service_fee;
			var notify=jsonData.notify;
			if(notify!=null)
			{
			document.getElementById("notification").innerHTML	= "WikiPay Pereference Notification<br> set  to "+notify+"  Days before due date  "; 
			}
			document.getElementById("payment_due_date").innerHTML= emi_loan_due_date+'of every month' ;     
			document.getElementById("emi_loan_amount1").innerHTML	= "$"+emi_loan_amount; 
			document.getElementById("amount").value	= emi_loan_amount; 
			document.getElementById("service_fee").value = service_fee; 
		}
	}
}

  function credit_card_submit(carddata)
  {
	xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="/makepayment/retrive_creditcard_submit?cardData="+carddata;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedCardSubmit;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
	
  }
function stateChangedCardSubmit()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{
			var  myCardData = xmlHttp.responseText;
			 cardStatus=eval('('+myCardData+')');
			 
			 if(cardStatus.status=='F')
			{
			payment_creditcard();
			}
			else if(cardStatus.status=='S')
			{
			document.getElementById('transactionid').value=cardStatus.transactionid;
			cardSubmitStatus=1;
			funSubmitDone();
			}
			
		}
	}
}

function wikipay_submit(amount,service_fee)
  {
	xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="/myaccount/retrive_wikipay_submit?amount="+amount+"&service_fee="+service_fee;   
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedWikipaySubmit;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
	
  }
function stateChangedWikipaySubmit()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{
			var  myWikipayData = xmlHttp.responseText;
			 mywikipayStatus=eval('('+myWikipayData+')');
			 if(mywikipayStatus.status=='F')
			{
			alert( mywikipayStatus.wikipayfail);
			}
			else if(mywikipayStatus.status=='S')
			{
			wikipaySubmitStatus=1;
			alert(myWikipayData);
			document.getElementById('transactionid').value= mywikipayStatus.transactionid;
			funSubmitDone();
			}
			
		}
	}
}


function funSubmitDone()
{
document.getElementById("makePaymentForm").submit();
}
function loanemi(loanid)
{
	
	xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	//var url ="/myaccount/retrive_loanamount?loan_id="+loanid;    
	var url ="/makepayment/retrive_loanamount?loan_id="+loanid;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedloan;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
}

function stateChangedloan()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{
		var  myString = xmlHttp.responseText;
		 jsonData=eval('('+myString+')');
		if(jsonData.emiMonthly=="0.00")
		{
		document.getElementById("payment2").disabled=true;
		document.getElementById("payment2").checked=false;
		}
		document.getElementById('emiMonthly').innerHTML=jsonData.emiMonthly;
		document.getElementById('overDueDisplay').innerHTML=jsonData.overDueAmount;
		document.getElementById('paymentDueDate').innerHTML=jsonData.paymentDueDate;
		document.getElementById('outStandingBalance').innerHTML=jsonData.loanOutstandingBalance;
		document.getElementById('currentDate').innerHTML=jsonData.current_date;
		
		}
	}
}
function checkNotNull(element,msg)
{
	var item=document.getElementById(element).value;

	if(item=='')
	{
	alert(msg);
	document.getElementById(element).focus();

	}
	else
	{
	
	}
}
function checkNumber(element,msg)
{
	var item=document.getElementById(element).value;
	if(!isNaN(item))
	{
	alert(msg);
	document.getElementById(element).value='';
	}
	else
	{
	}
}
function checkSelection(element,msg)
{
	var item=document.getElementById(element).value;
	if(!isNaN(item))
	{
	alert(msg);
	document.getElementById(element).value='';
	return false;
	}
	else
	{
	return true;
	}
}
function unCheckHtmlEcheck()
{
var i=1;
for (i=1;i<12;i++)
{
	var element="echeck_error_"+i;
	document.getElementById(element).innerHTML="";
}
}
function unCheckHtmlCard()
{
var i=1;
for (i=1;i<13;i++)
{
	var element="card_error_"+i;
	document.getElementById(element).innerHTML="";
}
}

function setEcheckInfo()
{								
			if(document.getElementById('Echeckname').value=='')
				{
				document.getElementById("echeck_error_1").innerHTML="<font color='red'> * Enter  name</font>";
				document.getElementById('Echeckname').focus();
				return 
				}
				else if(document.getElementById('Echecklandph').value=='')
				{
				unCheckHtmlEcheck();
				//document.getElementById("echeck_error_1").innerHTML="";
				document.getElementById("echeck_error_2").innerHTML="<font color='red'> * Enter phone number</font>";
				document.getElementById('Echecklandph').focus();
				return 
				}
				else if(isNaN(document.getElementById('Echecklandph').value))
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_2").innerHTML="<font color='red'> *  valid phone number</font>";
				document.getElementById('Echecklandph').value="";
				document.getElementById('Echecklandph').focus();
				return
				}
				else if(document.getElementById('Echecknumber').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_3").innerHTML="<font color='red'> * Enter check number</font>";
				document.getElementById('Echecknumber').focus();
				return
				}
				else if(isNaN(document.getElementById('Echecknumber').value))
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_3").innerHTML="<font color='red'> * valid check number</font>";
				document.getElementById('Echecknumber').value="";
				document.getElementById('Echecknumber').focus();
				return 
				}
				else if(document.getElementById('Echeckaddr').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_4").innerHTML="<font color='red'> *Enter address</font>";
				document.getElementById('Echeckaddr').focus();
				return 
				}
				else if(document.getElementById('Echeckcity').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_5").innerHTML="<font color='red'> * Enter city</font>";
				document.getElementById('Echeckcity').focus();
				return 
				}
				else if(document.getElementById('Echeckstate').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_6").innerHTML="<font color='red'> * Select state</font>";
				document.getElementById('Echeckstate').focus();
				return 
				}
				else if(document.getElementById('Echeckzip').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_7").innerHTML="<font color='red'> * Enter zip code</font>";
				document.getElementById('Echeckzip').focus();
				return 
				}
				else if(document.getElementById('Echeckfullname').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_8").innerHTML="<font color='red'> * Enter full name</font>";
				document.getElementById('Echeckfullname').focus();
				return 
				}
				else if(document.getElementById('Echeckbankroutingcode').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_9").innerHTML="<font color='red'> * Enter bank routing number </font>";
				document.getElementById('Echeckbankroutingcode').focus();
				return 
				}
				else if(isNaN(document.getElementById('Echeckbankroutingcode').value))
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_9").innerHTML="<font color='red'> * Enter valid bank routing number</font>";
				document.getElementById('Echeckbankroutingcode').value="";
				document.getElementById('Echeckbankroutingcode').focus();
				return 
				}
				else if(document.getElementById('Echeckbankaccno').value=='')
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_10").innerHTML="<font color='red'> *Enter bank account</font>";
				document.getElementById('Echeckbankaccno').focus();
				return ;
				}
				else if(isNaN(document.getElementById('Echeckbankaccno').value))
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_10").innerHTML="<font color='red'> * Enter valid bank account</font>";
				document.getElementById('Echeckbankaccno').value="";
				document.getElementById('Echeckbankaccno').focus();
				return ;
				}
				else if(document.getElementById('Echeckaccount_type_id').value==0)
				{
				unCheckHtmlEcheck();
				document.getElementById("echeck_error_11").innerHTML="<font color='red'> *Select account type</font>";
				document.getElementById('Echeckaccount_type_id').focus();
				return ;
				}
				else
				{
				unCheckHtmlEcheck();
				echeckInfo={	
				Echeckname:document.getElementById("Echeckname").value,
				Echecklandph:document.getElementById("Echecklandph").value,
				Echecknumber:document.getElementById("Echecknumber").value,
				Echeckaddr:document.getElementById("Echeckaddr").value,
				Echeckcity:document.getElementById("Echeckcity").value,
				Echeckstate:document.getElementById("Echeckstate").value,
				Echeckzip	:document.getElementById("Echeckzip").value,
				Echeckpayorderof:document.getElementById("Echeckpayorderof").value,
				EcheckMemo:document.getElementById("EcheckMemo").value,
				Echeckfullname:document.getElementById("Echeckfullname").value,
				Echeckbankroutingcode:document.getElementById("Echeckbankroutingcode").value,
				Echeckbankaccno:document.getElementById("Echeckbankaccno").value,
				Echeckaccount_type_id:document.getElementById("Echeckaccount_type_id").value
					};
				ajaxwin.hide();
				}
				
				
}				
function getEcheckInfo()
{
			if(document.getElementById("Echeckname"))
			{
				document.getElementById("Echeckname").value=echeckInfo.Echeckname;
				document.getElementById("Echecklandph").value=echeckInfo.Echecklandph;
				document.getElementById("Echecknumber").value=echeckInfo.Echecknumber;
				document.getElementById("Echeckaddr").value=echeckInfo.Echeckaddr;
				document.getElementById("Echeckcity").value=echeckInfo.Echeckcity;
				document.getElementById("Echeckstate").value=echeckInfo.Echeckstate;
				document.getElementById("Echeckzip").value=echeckInfo.Echeckzip	;
				document.getElementById("Echeckpayorderof").value=echeckInfo.Echeckpayorderof;
				document.getElementById("EcheckMemo").value=	echeckInfo.EcheckMemo;
				document.getElementById("Echeckfullname").value=echeckInfo.Echeckfullname;
				document.getElementById("Echeckbankroutingcode").value=echeckInfo.Echeckbankroutingcode;
				document.getElementById("Echeckbankaccno").value=echeckInfo.Echeckbankaccno;
				document.getElementById("Echeckaccount_type_id").value=echeckInfo.Echeckaccount_type_id;
					clearInterval(loopid1);	
			};
	
}

function setCreditCardInfo()
{
		
			if(document.getElementById('firstname').value=='')
				{
				//alert('Enter first name');
				document.getElementById("card_error_1").innerHTML="<font color='red'> * Enter first name</font>";
				document.getElementById('firstname').focus();
				return 
				}
				else if(document.getElementById('lastname').value=='')
				{
				//alert('Enter last name');
				 unCheckHtmlCard()
				document.getElementById("card_error_2").innerHTML="<font color='red'> * Enter last name</font>";
				document.getElementById('lastname').focus();
				return 
				}
				else if(document.getElementById('cardtype').value==0)
				{
				//alert('Select card type');
				 unCheckHtmlCard()
				document.getElementById("card_error_3").innerHTML="<font color='red'> * Select card type</font>";
				document.getElementById('cardtype').focus();
				return
				}
				else if(document.getElementById('cardnumber').value=="")
				{
				//alert('Enter  card number');
				 unCheckHtmlCard()
				document.getElementById("card_error_4").innerHTML="<font color='red'> * Enter  card number</font>";
				document.getElementById('cardnumber').value="";
				document.getElementById('cardnumber').focus();
				return 
				}
				else if(isNaN(document.getElementById('cardnumber').value))
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_4").innerHTML="<font color='red'> *Enter valid  card number</font>";
				document.getElementById('cardnumber').value="";
				document.getElementById('cardnumber').focus();
				return 
				}
				else if(document.getElementById('expdate').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_4").innerHTML="";
				document.getElementById("card_error_5").innerHTML="<font color='red'> * Enter expiration date</font>";
				document.getElementById('expdate').focus();
				return 
				}
				else if(document.getElementById('cvvnumber').value=="")
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_5").innerHTML="";
				document.getElementById("card_error_6").innerHTML="<font color='red'> * Enter cvv number</font>";
				document.getElementById('cvvnumber').value="";
				document.getElementById('cvvnumber').focus();
				return 
				}
				else if(isNaN(document.getElementById('cvvnumber').value))
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_6").innerHTML="";
				document.getElementById("card_error_6").innerHTML="<font color='red'> * Enter valid cvv number</font>";
				document.getElementById('cvvnumber').value="";
				document.getElementById('cvvnumber').focus();
				return 
				}
				else if(document.getElementById('billingaddr').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_6").innerHTML="";
				document.getElementById("card_error_7").innerHTML="<font color='red'> * Enter address</font>";
				document.getElementById('billingaddr').focus();
				return 
				}
				else if(document.getElementById('billingaddr2').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_7").innerHTML="";
				document.getElementById("card_error_8").innerHTML="<font color='red'> * Enter address</font>";
				document.getElementById('billingaddr2').focus();
				return 
				}
				else if(document.getElementById('billingcity').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_8").innerHTML="";
				document.getElementById("card_error_9").innerHTML="<font color='red'> * Enter billing city</font>";
				document.getElementById('billingcity').focus();
				return 
				}
				else if(document.getElementById('billingstate').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_9").innerHTML="";
				document.getElementById("card_error_10").innerHTML="<font color='red'> * Enter billing state</font>";
				document.getElementById('billingstate').focus();
				return 
				}
				else if(document.getElementById('billingzip').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_10").innerHTML="";
				document.getElementById("card_error_11").innerHTML="<font color='red'> * Enter billing zip code</font>";
				document.getElementById('billingzip').focus();
				return 
				}
				else if(isNaN(document.getElementById('billingzip').value))
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_11").innerHTML="";
				document.getElementById("card_error_11").innerHTML="<font color='red'> * Enter zip code</font>";
				document.getElementById('billingzip').value="";
				document.getElementById('billingzip').focus();
				return ;
				}
				else if(document.getElementById('phnumber').value=='')
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_11").innerHTML="";
				document.getElementById("card_error_12").innerHTML="<font color='red'> * Enter phone number</font>";
				document.getElementById('phnumber').focus();
				return ;
				}
				else if(isNaN(document.getElementById('phnumber').value))
				{
				 unCheckHtmlCard()
				document.getElementById("card_error_12").innerHTML="";
				document.getElementById("card_error_12").innerHTML="<font color='red'> * Enter valid phone numbere</font>";
				document.getElementById('phnumber').value="";
				document.getElementById('phnumber').focus();
				return ;
				}
				else
				{
				 unCheckHtmlCard()
		creditCardInfo={
				firstname:document.getElementById("firstname").value,
				lastname:document.getElementById("lastname").value,
				cardtype:document.getElementById("cardtype").value,
				cardnumber:document.getElementById("cardnumber").value,
				expdate:document.getElementById("expdate").value,
				cvvnumber:document.getElementById("cvvnumber").value,
				ccamount:document.getElementById("ccamount").value,
				billingaddr:document.getElementById("billingaddr").value,
				billingaddrr:document.getElementById("billingaddr2").value,
				billingcity:document.getElementById("billingcity").value,
				billingstate:document.getElementById("billingstate").value,
				billingzip:document.getElementById("billingzip").value,
				phnumber:document.getElementById("phnumber").value
				}
				ajaxwin.hide();
				}
}
function getCreditCardInfo()
{
				if(document.getElementById("firstname"))
				{
				document.getElementById("firstname").value=creditCardInfo.firstname;
				document.getElementById("lastname").value=creditCardInfo.lastname;
				document.getElementById("cardtype").value=creditCardInfo.cardtype;
				document.getElementById("cardnumber").value=creditCardInfo.cardnumber;
				document.getElementById("expdate").value=creditCardInfo.expdate;
				document.getElementById("cvvnumber").value=creditCardInfo.cvvnumber;
				document.getElementById("billingaddr").value=creditCardInfo.billingaddr;
				document.getElementById("billingaddr2").value=creditCardInfo.billingaddrr;
				document.getElementById("billingcity").value=creditCardInfo.billingcity;
				document.getElementById("billingstate").value=creditCardInfo.billingstate
				document.getElementById("billingzip").value=creditCardInfo.billingzip;
				document.getElementById("phnumber").value=creditCardInfo.phnumber;
				 
				 if(cardStatus.status=='F')
				{
				document.getElementById("card_error_submit").innerHTML="<font color='red'>"+cardStatus.cardfailure+"</font>";
				}
				clearInterval(loopid);	
				}
}
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 
	
 function retrive_due(pdate,loan_id)
{
xmlHttp=GetXmlHttpObject()		

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//navigation
	var url ="/adminloancalc/overdue?id="+loan_id+"&pdate="+pdate;    
	url = url;	 
	xmlHttp.onreadystatechange=stateChangedOverdue;	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
}

 function stateChangedOverdue()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{      
		if(xmlHttp.responseText == 0)
		{
 			
		}
		else
		{

			var  myString = xmlHttp.responseText;
			jsonData=eval('('+myString+')');
			var dueFlag=jsonData.due_flag;
			var dueFrom=jsonData.due_from;
			var dueDate=jsonData.due_date;
			var dueAmount=jsonData.due_amount;
			var totalDueAmount=jsonData.total_due_amount;
			var newBalance=jsonData.balance;
			var mothlyPaymentAmount=jsonData.monthly_payment_amount;
			var mothlyPaymentWithDue=jsonData.due_with_emi;
			var newbal;
		
		if (dueFlag=='YES')
		{
		document.getElementById("dueDisplay").style.display="block";		
		}
		else
		{
		document.getElementById("dueDisplay").style.display="none";		
		}
			
		document.getElementById("payment_due_from_display").innerHTML	= jsonData.due_from;	
		document.getElementById("over_due_display").innerHTML	= '$'+roundNumber(dueAmount,2);		
		document.getElementById("over_due_without_emi_display").innerHTML	= '$'+roundNumber(totalDueAmount,2);		
		document.getElementById("monthly_payment_display").innerHTML	= '$'+roundNumber(mothlyPaymentAmount,2);		
		document.getElementById("over_due_with_emi_display").innerHTML	= '$'+roundNumber(mothlyPaymentWithDue,2);	
		document.getElementById("monthly_payment").value	= roundNumber(mothlyPaymentAmount,2);	
		newbal	= roundNumber(parseFloat(jsonData.balance)+parseFloat(dueAmount),2);
		document.getElementById("bal_display").innerHTML	=newbal;
		}
	}
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber; // Output the result to the form field (change for your purposes)
}

 
 
