var isResponseCampaign = "true";
var sourceId;

var responseAjaxleadData;
// for ajax call to JAVA URL

function xmlhttpPostApp(strMethod, strURL, myFun, dataToSend) {
//	alert(strURL);
	var xmlHttpReq2 = false;
    // Mozilla/Safari Http Request
    if (window.XMLHttpRequest) {
        xmlHttpReq2 = new XMLHttpRequest();
    }
    // IE Http Request
    else if (window.ActiveXObject) {
        xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
    }

	 if (!xmlHttpReq2) {
            alert('ERROR AJAX: Cannot create an XMLHTTP instance');
            return false;
        }
    xmlHttpReq2.open(strMethod, strURL, true);
    xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if(strMethod=="POST")
    {
    	xmlHttpReq2.send(dataToSend);
    }
    else
    {
    	xmlHttpReq2.send('null');
    }
    xmlHttpReq2.onreadystatechange = function() {
        if(xmlHttpReq2.readyState == 4)
        {
           responseAjaxleadData = xmlHttpReq2.responseText;
		//	alert('inAJAXFunction----'+responseAjaxleadData);
           if(myFun!="noFun"){
				eval(myFun)(responseAjaxleadData);

           }
		 /*if(myFun=="noFun")
		   {
		    //document.getElementById('infoBox').style.display='none';
		   alert(responseAjaxData);
		   //document.getElementById('GET_SECURITY').disabled=true;
		   //document.getElementById('SECURITY').disabled=false;

		   }*/
        }
     }
}



/****************Ajax Xml Http Request Start***************/
function xmlhttpPost(strMethod, strURL, myFun, dataToSend) {
/*	//alert(strURL);
	var xmlHttpReq = false;
    // Mozilla/Safari Http Request
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE Http Request
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlHttpReq.open(strMethod, strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    if(strMethod=="POST")
    {
    	xmlHttpReq.send(dataToSend);
    }
    else
    {
    	xmlHttpReq.send('null');
    }
    xmlHttpReq.onreadystatechange = function() {
        if(xmlHttpReq.readyState == 4)
        {
           responseAjaxData = xmlHttpReq.responseText;
           if(myFun!="noFun"){
				eval(myFun)(responseAjaxData);
           }
        }
     }   */
}
/****************Ajax Xml Http Request End***************/
function Trim(s) {
   var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
   return (m == null) ? "" : m[1];
}


function isNullOrUndefined(a,value)
{
    if(typeof value != 'undefined'){
                if (typeof a == 'undefined'){
                    return value;
                }else{
                    if(a==null){
                        return value;
                    }else{
                        return a;
                    }
                }
        }else{
            if(typeof a == 'undefined'){
                    return true;
            }else{
                if(a==null){
                        return true;
                }else{
                        return false;
                }
            }
       }
}


function fillSubProductForMoneyControl(prodObject)
{
    var intProdId = prodObject.toString();
	var homeLoanProdId = document.getElementById('hdnHomeLoanProdId').value;
	var personalLoanProdId = document.getElementById('hdnPersonalLoanProdId').value;
	var carLoanProdId = document.getElementById('hdnCarLoanProdId').value;
	var creditCardProdId = document.getElementById('hdnCreditCardProdId').value;
	var educationLoanProdId = document.getElementById('hdnEducationLoanProdId').value;
	var loanAgainstSecurityProdId = document.getElementById('hdnLoanAgainstSecurityProdId').value;
	var businessLoanProdId = document.getElementById('hdnBusinessLoanProdId').value;
	var loanAgainstPropertyProdId = document.getElementById('hdnLoanAgainstPropertyProdId').value;

	var tempURL='';
	var productName = '';
	if(intProdId>0)
	{
		//alert("prod id : "+intProdId+" ==  hdn bus id : "+ typeof(businessLoanProdId));
		if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
			tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';

		switch(intProdId)
		{
		/* case '1':
		             xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break;
		    case '2':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break;
		    case '3':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");

		          break;
		    case '4':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break;
			case '5':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break;
			case '6':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break;

			case '99':
		              xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          break; */
		    case homeLoanProdId:
		          if(homeLoanArray!="")
		          {
		             fillSubProductForMoneyControlHandler(homeLoanArray);
		          }else{
		             xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
		    case personalLoanProdId:
		          if(personalLoanArray!="")
		          {
		              fillSubProductForMoneyControlHandler(personalLoanArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
		    case creditCardProdId:
		          if(creditCardArray!="")
		          {
		              fillSubProductForMoneyControlHandler(creditCardArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
		    case carLoanProdId:
		          if(carLoanArray!="")
		          {
		              fillSubProductForMoneyControlHandler(carLoanArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
		    case educationLoanProdId:
		          if(educationLoanArray!="")
		          {
		              fillSubProductForMoneyControlHandler(educationLoanArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
			 case loanAgainstSecurityProdId:
		          if(loanAgainstSecurityArray!="")
		          {
		              fillSubProductForMoneyControlHandler(loanAgainstSecurityArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
             case loanAgainstPropertyProdId:
		          if(loanAgainstPropertyArray!="")
		          {
		              fillSubProductForMoneyControlHandler(loanAgainstPropertyArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;
		     case businessLoanProdId:
				  //alert("in bus case");
		          if(businessLoanArray!="")
		          {
		              fillSubProductForMoneyControlHandler(businessLoanArray);
		          }else
		          {
                      xmlhttpPost("GET", tempURL+'getSubProduct.php?productId='+intProdId, fillSubProductForMoneyControlHandler, "");
		          }
		          break;




		}
	}
	else
	{
		document.getElementById('SUB_PRODUCT_ID').options.length=1;
	}

}

function fillSubProductForMoneyControlHandler(ajaxData)
{
	//alert('ajaxData==>'+ajaxData);
	var strStyle = '';
	arrSubProd = new Array();
	arrSubProd = ajaxData.split('|');


	intProductId = document.getElementById('PRODUCT_ID').value;

	document.getElementById('SUB_PRODUCT_ID').options.length=1;


	//alert("Product:"+intProductId);

	for(i=0;i<arrSubProd.length;i++)
	{

		subProduct = arrSubProd[i].split('~~');

		document.getElementById('SUB_PRODUCT_ID').options.length=document.getElementById('SUB_PRODUCT_ID').options.length+1;
		document.getElementById('SUB_PRODUCT_ID').options[i+1].value = subProduct[0];
		document.getElementById('SUB_PRODUCT_ID').options[i+1].text = subProduct[1];

	}

	if((intProductId == document.getElementById('hdnLoanAgainstSecurityProdId').value) || (intProductId == document.getElementById('hdnBusinessLoanProdId').value))
	{
		for(i = 0;i < (document.getElementById('SUB_PRODUCT_ID').options.length);i ++)
		{
			if(document.getElementById('SUB_PRODUCT_ID').options[i].value == "35")//for removing Business loan option from the smart appy menu
			{
				document.getElementById('SUB_PRODUCT_ID').remove(i);
			}
		}
	}
	//intProductId = document.getElementById('PRODUCT_ID').value;

	switch (intProductId)
	{
		case document.getElementById('hdnCarLoanProdId').value:
			strSubProdMsg ="Car Details";
			strSelectProdMsg ="Select Car Details";
			break;

		case document.getElementById('hdnCreditCardProdId').value:
			strSubProdMsg ="Type of Card";
			strSelectProdMsg ="Select Card Type";
			break;
		case document.getElementById('hdnBusinessLoanProdId').value:
			strSubProdMsg ="Nature of Security";
			strSelectProdMsg ="Select Security Type";
			break;
		case document.getElementById('hdnLoanAgainstSecurityProdId').value:
			strSubProdMsg ="Nature of Security";
			strSelectProdMsg ="Select Security Type";
			break;
		default:
			strSubProdMsg ="Purpose of Loan";
			strSelectProdMsg ="Select Loan Type";
			break;


	}

	if(!isNullOrUndefined(document.getElementById('SubProdMsg')))
	{
		document.getElementById('SubProdMsg').innerHTML=strSubProdMsg;
	}
	document.getElementById('SUB_PRODUCT_ID').options[0].value = 0;
	document.getElementById('SUB_PRODUCT_ID').options[0].text = '--'+strSelectProdMsg+'--';

	if(intProductId==document.getElementById('hdnCreditCardProdId').value)
	{
			if(!isNullOrUndefined(document.getElementById('HIDE_FOR_CREDIT_CARD')))
			{
				document.getElementById('HIDE_FOR_CREDIT_CARD').style.display='none';
				document.getElementById('HIDE_FOR_CREDIT_CARD').style.visibility='hidden';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME')))
			{
				document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME').style.display='none';
				document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME').style.visibility='hidden';
			}
	}
	else
	{		if(!isNullOrUndefined(document.getElementById('HIDE_FOR_CREDIT_CARD')))
			{
				document.getElementById('HIDE_FOR_CREDIT_CARD').style.display='';
				document.getElementById('HIDE_FOR_CREDIT_CARD').style.visibility='visible';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME')))
			{
				document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME').style.display='';
				document.getElementById('HIDE_FOR_CREDIT_CARD_GENHOME').style.visibility='visible';
			}
	}
	if(intProductId==document.getElementById('hdnEducationLoanProdId').value)
	{
			if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME').style.display='none';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME').style.visibility='hidden';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME').style.display='none';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME').style.visibility='hidden';
			}

			// For Employment Type For Education loan
			if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP').style.display='none';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP').style.visibility='hidden';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME').style.display='none';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME').style.visibility='hidden';
			}
	}
	else
	{		if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME').style.display='';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME').style.visibility='visible';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME').style.display='';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_INCOME_GENHOME').style.visibility='visible';
			}

			// For Employment Type For Education loan
			if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP').style.display='';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP').style.visibility='visible';
			}
			else if(!isNullOrUndefined(document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME')))
			{
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME').style.display='';
				document.getElementById('HIDE_FOR_EDUCATION_LOAN_EMP_GENHOME').style.visibility='visible';
			}
	}
}

function cityGetother(selectField,txtField,txt2Field)
{
		selectField = selectField.value.toLowerCase();
		 if(selectField=="other")
		 {
			txtField.style.display='';
			txtField.style.visibility='visible';
			//txt2Field.style.display='';

		 }
	     else
		 {
			txtField.style.display='none';
			txtField.style.visibility='hidden';
			//txt2Field.style.display="none";
		 }
}

function validateReusableForm2(element)
{
	//alert ("name:"+document.getElementById('COUNTRY_CODE').value);

	var formRegistration=new Object();

	var isNRIValue;

	var resuableFlagVal;

	//alert(document.getElementById('PL2').value);

	if(!isNullOrUndefined(document.getElementById('RESUABLEFLAG')))
	{
  		resuableFlagVal=document.getElementById('RESUABLEFLAG').value;

  	}


	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			var isNRIValue='N';
	}else
	{
			var isNRIValue='Y';
	}

	formRegistration["CUST_NAME"] = {blank:true,valid:true, validateFunction:[fullNameValidation],label:"your Full Name"};

	formRegistration["COUNTRY_CODE"] = {blank:true,valid:true, validateFunction:[digitValidation],label:"Country Code No."};

		formRegistration["EMAIL"] = {blank:true,valid:true, validateFunction:[emailValidation],label:"Email Address"};


	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			formRegistration["TEL_MOBILE"] = {blank:true,valid:true, validateFunction:[mobilenumberValidation],param:{isNRI:isNRIValue},label:"your Mobile-Number (10-Digit Number)"};
	}else
	{
			formRegistration["TEL_MOBILE"] = {blank:true,valid:true, validateFunction:[mobilenumberValidation],param:{isNRI:isNRIValue},label:"your Mobile-Number"};
	}


	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			formRegistration["CITY_ID"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Residence City"};
			if(document.getElementById('CITY_ID').value=='other')
			{

				formRegistration['OTHER_CITY_NAME'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"other city"};
			}
	}else
	{
			formRegistration["NRI_CITY_ID"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Residence City"};


			if(!isNullOrUndefined(document.getElementById('NRI_CITY_ID')))
			{
				if(document.getElementById('NRI_CITY_ID').value=='other')
				{

					formRegistration['OTHER_CITY_NAME'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"other city"};
				}
			}
	}

	fieldMap["formRegistration"]=formRegistration;

	var errorStatus = validation(document.formRegistration);
		if(errorStatus)
		{
			if(document.getElementById('checkTerms').checked)
			{
				if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
					tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';

				/*qstr = "PRODUCT_ID="+document.getElementById('PRODUCT_ID').value;

				if(document.getElementById('IS_NRI_YN').value=="N")
				{
					if(document.getElementById('CITY_ID').value=='other')
					{
							qstr += "&OTHER_CITY_NAME="+document.getElementById('OTHER_CITY_NAME').value;

					}else
					{
							qstr += "&CITY_ID="+document.getElementById('CITY_ID').value;
					}
				}
				else
				{
					if(document.getElementById('NRI_CITY_ID').value=='other')
					{
							qstr += "&OTHER_CITY_NAME="+document.getElementById('OTHER_CITY_NAME').value;
							qstr += "&CITY_ID=0";
					}else
					{
								qstr += "&CITY_ID="+document.getElementById('NRI_CITY_ID').value;
					}

				}
				qstr += "&CUST_NAME="+document.getElementById('CUST_NAME').value;
				mobileNo = document.getElementById('COUNTRY_CODE').value + "-" + document.getElementById('TEL_MOBILE').value
				qstr += "&TEL_MOBILE="+mobileNo;
				TEL_RES = document.getElementById('OFF_LAND_LINE_AREACODE').value + "-" + document.getElementById('TEL_OFF').value + "-" + document.getElementById('OFF_LAND_LINE_EXT').value
				qstr += "&TEL_RES="+TEL_RES;
				qstr += "&EMAIL="+document.getElementById('EMAIL').value;
				qstr += "&SUB_PRODUCT_ID="+document.getElementById('SUB_PRODUCT_ID').value;

				if(document.getElementById('PRODUCT_ID').value==document.getElementById('hdnCreditCardProdId').value)
				{
						qstr += "&LOAN_AMT=''";

						if(resuableFlagVal=='campaignPages')
						{

							if(document.getElementById('monthlyIncomeSalaried').style.display=="")
							{
								qstr += "&INCOME="+document.getElementById('INCOME_SALARIED').value;
							}else if(document.getElementById('monthlyIncomeSelfEmployed').style.display=="")
							{
								qstr += "&INCOME="+document.getElementById('INCOME_SELF').value;
							}
						}else
						{
							qstr += "&INCOME="+document.getElementById('INCOME').value;
						}

				}
				else{
						qstr += "&LOAN_AMT="+document.getElementById('LOAN_AMT').value;
						qstr += "&INCOME="+document.getElementById('INCOME').value;
				}
				DOB = document.getElementById('DOB_YEAR').value + "-" + document.getElementById('DOB_MONTH').value + "-" + document.getElementById('DOB_DAY').value
				qstr += "&DOB="+DOB;
				qstr += "&PROFESSION_ID="+document.getElementById('PROFESSION_ID').value;

				if(!isNullOrUndefined(document.getElementById('SOURCE_ID')))
				{

					sourceId=document.getElementById('SOURCE_ID').value;
					qstr += "&sourceId="+sourceId;

				}
				qstr += "&IS_NRI_YN="+isNRIValue;
				*/
				//alert('qstr::'+qstr)

				/******* Loading  Image Start ********
				if(navigator.userAgent.indexOf("Firefox") > -1){
				   if(document.getElementById('RESUABLEFLAG').value=='campaignPages')
					{
						gapX=-530;gapY=-15;
					}else
					{
						gapX=-230;gapY=-15;
					}
				}else{
					if(document.getElementById('RESUABLEFLAG').value=='campaignPages')
					{
						gapX=-60;gapY=-8;
					}else
					{
						gapX=-60;gapY=-8;
					}
				}
				posX = element.offsetLeft
				posY = element.offsetTop;
				width = element.clientWidth;
				if(!width){
					width = element.offsetWidth;
				}

				TheElement = element.offsetParent;
				while(TheElement != null){
					posX += TheElement.offsetLeft
					posY += TheElement.offsetTop;
					TheElement = TheElement.offsetParent;
				}
				posX += gapX;
				posY += gapY;

				document.getElementById('infoBox').style.left=posX+'px';
				document.getElementById('infoBox').style.top=posY+'px';
				document.getElementById('infoBox').style.visibility='visible';
				document.getElementById('infoBox').style.display='';
				/******* Loading  Image End ********/

			/* if(isResponseCampaign == "true" && document.getElementById('LEAD_ID').value =='0')
	        {
	          xmlhttpPost("GET",tempURL+"reusableAjax.php?"+qstr,"reusableQuickApply","");
	          isResponseCampaign = false;
	        }*/
			document.getElementById('TEL_MOBILE').value=document.getElementById('COUNTRY_CODE').value + "-" + document.getElementById('TEL_MOBILE').value;
			document.formRegistration.action = tempURL+"reusableQuickApplyProcess.php?checkPL=PL2";
			document.formRegistration.submit();
			document.getElementById('submitHref').onclick = "";
			document.getElementById('submitHref').href = "javascript: void(0)";
			}
			else
			{
				alert("Please,Check terms and conditions for apnaloan.com. ");
			}
		}
}





function validateReusableForm(element)
{
	//alert("test "+element);
	//alert ("name:"+document.getElementById('CUST_NAME').value)
	var formRegistration=new Object();

	var isNRIValue;

	var resuableFlagVal;

	if(document.getElementById('ERR_NAME'))
	{
		document.getElementById('ERR_NAME').style.display="none";
	}
	if(document.getElementById('ERR_CITY'))
	{
		document.getElementById('ERR_CITY').style.display="none";
	}
	if(document.getElementById('ERR_OTHER_CITY'))
	{
		document.getElementById('ERR_OTHER_CITY').style.display="none";
	}
	if(document.getElementById('ERR_DATE'))
	{
		document.getElementById('ERR_DATE').style.display="none";
	}
	if(document.getElementById('ERR_SUB_PROD'))
	{
		document.getElementById('ERR_SUB_PROD').style.display="none";
	}
	if(document.getElementById('ERR_LOAN_AMT'))
	{
		document.getElementById('ERR_LOAN_AMT').style.display="none";
	}
	if(document.getElementById('ERR_INCOME'))
	{
		document.getElementById('ERR_INCOME').style.display="none";
	}
	if(document.getElementById('ERR_INCOME_DOCS'))
	{
		document.getElementById('ERR_INCOME_DOCS').style.display="none";
	}
	if(document.getElementById('ERR_PROFESSION'))
	{
		document.getElementById('ERR_PROFESSION').style.display="none";
	}
	if(document.getElementById('ERR_EMAIL'))
	{
		document.getElementById('ERR_EMAIL').style.display="none";
	}
	if(document.getElementById('ERR_MOBILE'))
	{
		document.getElementById('ERR_MOBILE').style.display="none";
	}
	if(document.getElementById('ERR_TERMS'))
	{
		document.getElementById('ERR_TERMS').style.display="none";
	}


	//var responseAjaxleadData;
	if(!isNullOrUndefined(document.getElementById('RESUABLEFLAG')))
	{
  		resuableFlagVal=document.getElementById('RESUABLEFLAG').value;
	}


	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			var isNRIValue='N';
	}else
	{
			var isNRIValue='Y';
	}
	//alert(document.getElementById("RESUABLEFLAG").value);


//alert(document.getElementById("PRODUCT_ID").value);

	formRegistration["product"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Type of Product you are looking for"};

	formRegistration[""] = {blank:true,valid:true, validateFunction:[fullNameValidation],label:"your Full Name"};
	formRegistration["COUNTRY_CODE"] = {blank:true,valid:true, validateFunction:[digitValidation],label:"Country Code No."};
	formRegistration["OFF_LAND_LINE_AREACODE"] = {blank:true,valid:true, validateFunction:[digitValidation],label:" Landline STD code."};
	formRegistration["TEL_OFF"] = {blank:true,valid:true, validateFunction:[digitValidation],label:" Landline phone no."};
	formRegistration["OFF_LAND_LINE_EXT"] = {valid:true, validateFunction:[digitValidation],label:" Landline extension."};
	formRegistration["EMAIL"] = {blank:true,valid:true, validateFunction:[emailValidation],label:"Email Address"};

	if(document.getElementById('product').value==document.getElementById('hdnCreditCardProdId').value)
	{
		formRegistration["subProduct"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Type of Card you are looking for"};
	}
	else
	{
		formRegistration["subProduct"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Type of Loan you are looking for"};
		formRegistration["LOAN_AMT"] = {blank:true,valid:true,validateFunction:[rangeValidation],label:"Desired Loan Amount",param:{min:1,max:999999999}};
	}

	// For Education Loan Start
	if(document.getElementById('product').value!=document.getElementById('hdnEducationLoanProdId').value)
	{
		formRegistration["INCOME"] = {blank:true,valid:true,validateFunction:[rangeValidation],label:"Monthly Income",param:{min:1,max:999999999}};

		formRegistration["PROFESSION_ID"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Employment Type"};

	}

	// For Education Loan End


	var dayValue = document.getElementById('dobDay').value;
	var monthValue = document.getElementById('dobMonth').value;
	var yearValue = document.getElementById('dobYear').value;

	formRegistration['dobMonth'] = {blank:true, valid:true, validateFunction:[DateValidation],label:'Date of birth',param:{day:dayValue,month:monthValue,year:yearValue}};



	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			formRegistration["TEL_MOBILE"] = {blank:true,valid:true, validateFunction:[mobilenumberValidation],param:{isNRI:isNRIValue},label:"your Mobile-Number (10-Digit Number)"};
	}else
	{
			formRegistration["TEL_MOBILE"] = {blank:true,valid:true, validateFunction:[mobilenumberValidation],param:{isNRI:isNRIValue},label:"your Mobile-Number"};
	}


	if(document.getElementById('IS_NRI_YN').value=="N")
	{
			formRegistration["city"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Residence City"};
			if(document.getElementById('city').value=='other')
			{

				formRegistration['OTHER_CITY_NAME'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"other city"};
			}
	}else
	{
			formRegistration["NRI_CITY_ID"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Residence City"};

			if(!isNullOrUndefined(document.getElementById('NRI_CITY_ID')))
			{
				if(document.getElementById('NRI_CITY_ID').value=='other')
				{

					formRegistration['OTHER_CITY_NAME'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"other city"};
				}
			}
	}

	/*code for  salary account*/
	//alert(document.getElementById('SALARY_AC').value);
	/*if(document.getElementById('SALARY_AC').value=='other')
	{
	formRegistration['OTHER_SALARY_AC'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"other Salary Account"};
	}
	else
	{
	formRegistration["SALARY_AC"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Salary Account"};

	}*/

	/* sal ac ends*/

	/* INCOME docs validations */
	//alert(document.getElementsByTagName("input").value);
	var e=document.getElementsByTagName("tr");

	for(var i=0;i<e.length;i++)
	{
		if(e[i].id=='INCOME_DOCS')
		{
			if(document.getElementById('checkSalSlip').checked == false && document.getElementById('checkBankStmt').checked == false && document.getElementById('checkFrm16').checked == false && document.getElementById('checkITR').checked == false)
				{
					//alert(document.getElementById('checkSalSlip').value);
					formRegistration['checkSalSlip'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"Income Document"};
				}

		}
	}

/*	if(document.getElementById('checkSalSlip').checked == false && document.getElementById('checkBankStmt').checked == false && document.getElementById('checkFrm16').checked == false && document.getElementById('checkITR').checked == false)
	{
		//alert(document.getElementById('checkSalSlip').value);
		formRegistration['checkSalSlip'] = {blank:true,valid:true, validateFunction:[firstnameValidation],label:"Income Documnet"};
	}
	else
	{
		document.getElementById('checkSalSlip').value="Y";
		alert(document.getElementById('checkSalSlip').value);

	}*/

	/*  income docs validation ends */


	if(document.getElementById('product').value==document.getElementById('hdnCreditCardProdId').value)
		{

				if(resuableFlagVal=='campaignPages')
				{

					if(document.getElementById('monthlyIncomeSalaried').style.display=="")
					{
						formRegistration["INCOME_SALARIED"] = {valid:true, validateFunction:[selectValidation],label:"Monthly Income"};
					}else if(document.getElementById('monthlyIncomeSelfEmployed').style.display=="")
					{

						formRegistration["INCOME_SELF"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Monthly Income"};
					}
				}
		}


	/*code added for 3508	*/
	formRegistration["SALARY_AC"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Salary Account"};



	//formRegistration["SALARY_AC"] = {blank:true,valid:true, validateFunction:[selectValidation],label:"Salary Account"};




	fieldMap["formRegistration"]=formRegistration;

	var errorStatus = validation(document.formRegistration);

		if(errorStatus)
		{
			if(document.getElementById('checkTerms').checked)
			{
				if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
					tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';

				/*qstr = "PRODUCT_ID="+document.getElementById('PRODUCT_ID').value;

				if(document.getElementById('IS_NRI_YN').value=="N")
				{
					if(document.getElementById('city').value=='other')
					{
							qstr += "&OTHER_CITY_NAME="+document.getElementById('OTHER_CITY_NAME').value;

					}else
					{
							qstr += "&city="+document.getElementById('city').value;
					}
				}
				else
				{
					if(document.getElementById('NRI_CITY_ID').value=='other')
					{
							qstr += "&OTHER_CITY_NAME="+document.getElementById('OTHER_CITY_NAME').value;
							qstr += "&city=0";
					}else
					{
								qstr += "&city="+document.getElementById('NRI_CITY_ID').value;
					}

				}
				qstr += "&CUST_NAME="+document.getElementById('CUST_NAME').value;
				mobileNo = document.getElementById('COUNTRY_CODE').value + "-" + document.getElementById('TEL_MOBILE').value
				qstr += "&TEL_MOBILE="+mobileNo;
				TEL_RES = document.getElementById('OFF_LAND_LINE_AREACODE').value + "-" + document.getElementById('TEL_OFF').value + "-" + document.getElementById('OFF_LAND_LINE_EXT').value
				qstr += "&TEL_RES="+TEL_RES;
				qstr += "&EMAIL="+document.getElementById('EMAIL').value;
				qstr += "&SUB_PRODUCT_ID="+document.getElementById('SUB_PRODUCT_ID').value;

				if(document.getElementById('PRODUCT_ID').value==document.getElementById('hdnCreditCardProdId').value)
				{
						qstr += "&LOAN_AMT=''";

						if(resuableFlagVal=='campaignPages')
						{

							if(document.getElementById('monthlyIncomeSalaried').style.display=="")
							{
								qstr += "&INCOME="+document.getElementById('INCOME_SALARIED').value;
							}else if(document.getElementById('monthlyIncomeSelfEmployed').style.display=="")
							{
								qstr += "&INCOME="+document.getElementById('INCOME_SELF').value;
							}
						}else
						{
							qstr += "&INCOME="+document.getElementById('INCOME').value;
						}

				}
				else{
						qstr += "&LOAN_AMT="+document.getElementById('LOAN_AMT').value;
						qstr += "&INCOME="+document.getElementById('INCOME').value;
				}
				DOB = document.getElementById('DOB_YEAR').value + "-" + document.getElementById('DOB_MONTH').value + "-" + document.getElementById('DOB_DAY').value
				qstr += "&DOB="+DOB;
				qstr += "&PROFESSION_ID="+document.getElementById('PROFESSION_ID').value;

				if(!isNullOrUndefined(document.getElementById('SOURCE_ID')))
				{

					sourceId=document.getElementById('SOURCE_ID').value;
					qstr += "&sourceId="+sourceId;

				}
				qstr += "&IS_NRI_YN="+isNRIValue;
				*/
				//alert('qstr::'+qstr)

				/******* Loading  Image Start ********
				if(navigator.userAgent.indexOf("Firefox") > -1){
				   if(document.getElementById('RESUABLEFLAG').value=='campaignPages')
					{
						gapX=-530;gapY=-15;
					}else
					{
						gapX=-230;gapY=-15;
					}
				}else{
					if(document.getElementById('RESUABLEFLAG').value=='campaignPages')
					{
						gapX=-60;gapY=-8;
					}else
					{
						gapX=-60;gapY=-8;
					}
				}
				posX = element.offsetLeft
				posY = element.offsetTop;
				width = element.clientWidth;
				if(!width){
					width = element.offsetWidth;
				}

				TheElement = element.offsetParent;
				while(TheElement != null){
					posX += TheElement.offsetLeft
					posY += TheElement.offsetTop;
					TheElement = TheElement.offsetParent;
				}
				posX += gapX;
				posY += gapY;

				document.getElementById('infoBox').style.left=posX+'px';
				document.getElementById('infoBox').style.top=posY+'px';
				document.getElementById('infoBox').style.visibility='visible';
				document.getElementById('infoBox').style.display='';
				/******* Loading  Image End ********/

			/* if(isResponseCampaign == "true" && document.getElementById('LEAD_ID').value =='0')
	        {
	          xmlhttpPost("GET",tempURL+"reusableAjax.php?"+qstr,"reusableQuickApply","");
	          isResponseCampaign = false;
	        }*/
			/*new code to use JAVA  URL */

			var elements=document.getElementsByTagName("input");
			var found=false;

			for(var i=0;i<elements.length;i++)
			{
				if(elements[i].id=='txtflagPlInd' || elements[i].id=='txtflagInd' || elements[i].id=='txtflagHlIndx4' || elements[i].id=='txtflagPLindx4') //INCOME_DOCS
				{
					var flagType=elements[i].id;
					found=true;
					break;
				}

			}

			if(found==true)
			{

			if(document.getElementById('city').value=='other')
			{
			var custCityId=0 //cityId=0 if OTHER City is selected
			var otherCityName=document.getElementById('OTHER_CITY_NAME').value;
			}
			else
			{
			var custCityId=document.getElementById('city').value;
			}

			var W3URL=document.getElementById('SITE_W3_URL').value;

			var appProductId=document.getElementById('PRODUCT_ID').value;
			var custName=document.getElementById('CUST_NAME').value;
			var custTelMobile=document.getElementById('TEL_MOBILE').value;

			var custEmail=document.getElementById('EMAIL').value;
			var appSubProductId=document.getElementById('SUB_PRODUCT_ID').value;
			var appLoanAmt=document.getElementById('LOAN_AMT').value;

			var custIncome=document.getElementById('INCOME').value;
			var custDOB=document.getElementById('DOB_YEAR').value+'-'+document.getElementById('DOB_MONTH').value+'-'+document.getElementById('DOB_DAY').value;

			var custProfessionId=document.getElementById('PROFESSION_ID').value; //PROFESSION_ID

			if(document.getElementById('checkSalSlip').checked)
			{
				var hasSalarySlip='Y'
			}
			else if(!document.getElementById('checkSalSlip').checked)
			{
				var hasSalarySlip='N'
			}

			if(document.getElementById('checkBankStmt').checked)
			{
				var hasBankStatement='Y'
			}
			else if(!document.getElementById('checkBankStmt').checked)
			{
				var hasBankStatement='N'
			}

			if(document.getElementById('checkFrm16').checked)
			{
				var hasForm16='Y'
			}
			else if(!document.getElementById('checkFrm16').checked)
			{
				var hasForm16='N'
			}

			if(document.getElementById('checkITR').checked)
			{
				var hasIncomeTaxReturns='Y'
			}
			else if(!document.getElementById('checkITR').checked)
			{
				var hasIncomeTaxReturns='N'
			}

				document.getElementById("submitHref").disabled=true;
				if(navigator.userAgent.indexOf("Firefox") > -1){
					   gapX=50;gapY=-20;
					}else{
					   gapX=70;gapY=-10;
					}
					posX = element.offsetLeft
					posY = element.offsetTop;
					width = element.clientWidth;
					if(!width){
						width = element.offsetWidth;
					}

					TheElement = element.offsetParent;
					while(TheElement != null){
						posX += TheElement.offsetLeft
						posY += TheElement.offsetTop;
						TheElement = TheElement.offsetParent;
					}
					posX += gapX;
					posY += gapY;

					document.getElementById('infoBox').style.left=posX+'px';
					document.getElementById('infoBox').style.top=posY+'px';
					document.getElementById('infoBox').style.visibility='visible';
					document.getElementById('infoBox').style.display='';

		//code for correct insertion of cities e.g. ither or mumbai..etc...
		if(document.getElementById('city').value!='other')
		{

var qstr="javaURL=Y&otherCity=N&appProductId="+appProductId+"&custName="+custName+"&custTelMobile=91-"+custTelMobile+"&custCityId="+custCityId+"&custEmail="+custEmail+"&appSubProductId="+appSubProductId+"&appLoanAmount="+appLoanAmt+"&custMonthlyIncome="+custIncome+"&custdateOfBirth="+custDOB+"&custProfessionId="+custProfessionId+"&custhasSalarySlip="+hasSalarySlip+"&custhasBankStatement="+hasBankStatement+"&custhasForm16="+hasForm16+"&custhasIncomeTaxReturns="+hasIncomeTaxReturns+"&appNri=N";

//orig call
//xmlhttpPostApp("GET",W3URL+"als/transient/createApplication.htm?"+qstr,"checkCreateResponse","");

//NEW CALL thru PHP
xmlhttpPostApp("GET",tempURL+"javaURL.php?"+qstr,"checkCreateResponse","");

		}
		else if(document.getElementById('city').value=='other')
		{

	var qstr="javaURL=Y&otherCity=Y&appProductId="+appProductId+"&custName="+custName+"&custTelMobile=91-"+custTelMobile+"&custCityId="+custCityId+"&custEmail="+custEmail+"&appSubProductId="+appSubProductId+"&appLoanAmount="+appLoanAmt+"&custMonthlyIncome="+custIncome+"&custdateOfBirth="+custDOB+"&custProfessionId="+custProfessionId+"&custhasSalarySlip="+hasSalarySlip+"&custhasBankStatement="+hasBankStatement+"&custhasForm16="+hasForm16+"&custhasIncomeTaxReturns="+hasIncomeTaxReturns+"&custotherCityName="+otherCityName+"&appNri=N";

//orig call
//xmlhttpPostApp("GET",W3URL+"als/transient/createApplication.htm?"+qstr,"checkCreateResponse","");

//NEW CALL thru PHP
xmlhttpPostApp("GET",tempURL+"javaURL.php?"+qstr,"checkCreateResponse","");
		}

		//NEED TO HANDLE 'OTHER CITY' CASE

			//alert(newURL);
			//"/als/transient/createUnvalidatedApplication.htm?appProductId=".."&custName=".."";
			//document.formRegistration.submit();
			document.getElementById('submitHref').onclick = "";
			document.getElementById('submitHref').href = "javascript: void(0)";


			}
			else
			{
				//alert('found false');
				//use ORIGINAL CODE here

			document.formRegistration.action = tempURL+"reusableQuickApplyProcess.php";
			document.formRegistration.submit();
			document.getElementById('submitHref').onclick = "";
			document.getElementById('submitHref').href = "javascript: void(0)";
			}

			}
			else
			{
				alert("Please,Check terms and conditions for apnaloan.com. ");
			}
		}

}

function checkCreateResponse(responseAjaxleadData)
{

	var tempResp= responseAjaxleadData.toLowerCase();

			if(document.getElementById('city').value=='other')
			{
			var custCityId=0 //cityId=0 if OTHER City is selected
			var otherCityName=document.getElementById('OTHER_CITY_NAME').value;
			}
			else
			{
			var custCityId=document.getElementById('city').value;
			}

			var W3URL=document.getElementById('SITE_W3_URL').value;

			var appProductId=document.getElementById('PRODUCT_ID').value;
			var custName=document.getElementById('CUST_NAME').value;
			var custTelMobile=document.getElementById('TEL_MOBILE').value;

			var custEmail=document.getElementById('EMAIL').value;
			var appSubProductId=document.getElementById('SUB_PRODUCT_ID').value;
			var appLoanAmt=document.getElementById('LOAN_AMT').value;

			var custIncome=document.getElementById('INCOME').value;
			var custDOB=document.getElementById('DOB_YEAR').value+'-'+document.getElementById('DOB_MONTH').value+'-'+document.getElementById('DOB_DAY').value;
			var custProfessionId=document.getElementById('PROFESSION_ID').value; //PROFESSION_ID

			if(document.getElementById('checkSalSlip').checked)
			{
				var hasSalarySlip='Y'
			}
			else if(!document.getElementById('checkSalSlip').checked)
			{
				var hasSalarySlip='N'
			}

			if(document.getElementById('checkBankStmt').checked)
			{
				var hasBankStatement='Y'
			}
			else if(!document.getElementById('checkBankStmt').checked)
			{
				var hasBankStatement='N'
			}

			if(document.getElementById('checkFrm16').checked)
			{
				var hasForm16='Y'
			}
			else if(!document.getElementById('checkFrm16').checked)
			{
				var hasForm16='N'
			}

			if(document.getElementById('checkITR').checked)
			{
				var hasIncomeTaxReturns='Y'
			}
			else if(!document.getElementById('checkITR').checked)
			{
				var hasIncomeTaxReturns='N'
			}

			//foll code to retrieve FLAGTYPE for interactive avenue's URL
			var elements=document.getElementsByTagName("input");
			var found=false;

			for(var i=0;i<elements.length;i++)
			{
				if(elements[i].id=='txtflagPlInd' || elements[i].id=='txtflagInd' || elements[i].id=='txtflagHlIndx4'  || elements[i].id=='txtflagPLindx4') //INCOME_DOCS
				{
					var flagType=elements[i].id;
					break;
				}

			}

			/*foll var to use add grp id to retrieve referrer site n send to interactive avenue's URL*/
			var adGroupId=document.getElementById('SOURCE_ID').value

	var check_status=responseAjaxleadData.split(":");

	if(check_status[0].toLowerCase()=="success")
	{

	var appId=check_status[1];
	document.getElementById('infoBox').style.display='none';

		if(document.getElementById('city').value!='other')
		{
			//alert('listed city');
			window.location.href = tempURL+"reusableQuickApplyProcess.php?javaURL=Y&otherCity=N&appProductId="+appProductId+"&custName="+custName+"&custTelMobile=91-"+custTelMobile+"&custCityId="+custCityId+"&custEmail="+custEmail+"&appSubProductId="+appSubProductId+"&appLoanAmount="+appLoanAmt+"&custMonthlyIncome="+custIncome+"&custDateOfBirth="+custDOB+"&custProfessionId="+custProfessionId+"&custhasSalarySlip="+hasSalarySlip+"&custhasBankStatement="+hasBankStatement+"&custhasForm16="+hasForm16+"&custhasIncomeTaxReturns="+hasIncomeTaxReturns+"&appId="+appId+"&flagType="+flagType+"&adGroupId="+adGroupId;
		}
		else if(document.getElementById('city').value=='other')
		{
		//	alert('other city');
			window.location.href = tempURL+"reusableQuickApplyProcess.php?javaURL=Y&otherCity=Y&appProductId="+appProductId+"&custName="+custName+"&custTelMobile=91-"+custTelMobile+"&custCityId="+custCityId+"&custEmail="+custEmail+"&appSubProductId="+appSubProductId+"&appLoanAmount="+appLoanAmt+"&custMonthlyIncome="+custIncome+"&custDateOfBirth="+custDOB+"&custProfessionId="+custProfessionId+"&custhasSalarySlip="+hasSalarySlip+"&custhasBankStatement="+hasBankStatement+"&custhasForm16="+hasForm16+"&custhasIncomeTaxReturns="+hasIncomeTaxReturns+"&custotherCityName="+otherCityName+"&appId="+appId+"&flagType="+flagType+"&adGroupId="+adGroupId;
		}
	}
	else
	{
	alert(check_status[1]);
	//alert('prodId '+appProductId);
//	window.location.href=tempURL+"personal-loan-india/apply/index-3.php";
		/*if(appProductId==1)
		{
			window.location.href=tempURL+"home-loan-india/apply/index-3.php";
		}
		else if(appProductId==2)
		{
			window.location.href=tempURL+"personal-loan-india/apply/index-3.php";
		}*/

				if(document.getElementById('hdnPhpValidations') )
				{
				window.history.go(-1); //added this code for html based forms
				}
				else
				{
				window.location.href=window.location.href;
				}
	}

}
function reusableQuickApply(ajaxData)
{
	//alert('ajaxData for reusableQuickApply::'+ajaxData);
	arrResponse = responseAjaxData.split(":");
	if(!isNaN(arrResponse[0]) && arrResponse[0] > 0 && !isNaN(arrResponse[1]) && arrResponse[1] > 0)
	{
		document.getElementById('CUST_ID').value = arrResponse[0];
		document.getElementById('LEAD_ID').value = arrResponse[1];
		raiseDelightCallForReusableQuickApply(arrResponse[1]);
		//parent.location.href="registration.php?flag=otherSite";
	}
}


function raiseDelightCallForReusableQuickApply(applicationId)
{

		var tempURL='';
		if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
			tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';

		intProdId = document.getElementById('PRODUCT_ID').value;
		intSubProdId = document.getElementById('SUB_PRODUCT_ID').value;
		intCityId = document.getElementById('city').value;
		strIsNri = document.getElementById('IS_NRI_YN').value;

		xmlhttpPost("GET",tempURL+"getPriorityQueue.php?PRODUCT_ID="+intProdId+"&city="+intCityId+"&IS_NRI_YN="+strIsNri+"&SUB_PRODUCT_ID="+intSubProdId,"PriorityQueueForReusableQuickApply","");

		//qstr = 'activity=DelightCall&applicationid='+applicationId;
		//xmlhttpPost("GET",tempURL+"sms.php?"+qstr,"smsVerification","");
}

function PriorityQueueForReusableQuickApply(ajaxData)
{
	var priority = "";
	priority = ajaxData;
    //alert('priority==='+priority);
	//return;
	//priority = "DelightCall";

	applicationId = document.getElementById('LEAD_ID').value;

	var tempURL='';
	if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
		tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';

	qstr = 'activity='+priority+'&applicationid='+applicationId;
	xmlhttpPost("GET",tempURL+"sms.php?"+qstr,"smsVerificationForReusableQuickApply","");
}

function smsVerificationForReusableQuickApply(ajaxData){
	var dbCaseId="";
	//alert('ajaxData==>'+ajaxData);
	ajaxData = ajaxData.split('Status:');
	caseId = ajaxData[0];

	if(ajaxData.length>1)
		ajaxData = ajaxData[1].split('*');

	if(!isNullOrUndefined(document.getElementById('CASE_ID')))
	{
  		dbCaseId = document.getElementById('CASE_ID').value;
  	}
  	//alert('caseId::'+caseId+'\n dbCaseId => '+dbCaseId);
	if(ajaxData[0]=='SUCCESS')
	{
		if(Trim(dbCaseId)=='0' || dbCaseId==0 || Trim(dbCaseId)=='')
		{
			if(!isNullOrUndefined(document.getElementById('CASE_ID')))
			{
				document.getElementById('CASE_ID').value = caseId;
				//alert('caseId'+document.getElementById('CASE_ID').value);
				if(document.getElementById('CUST_ID').value>0 && document.getElementById('LEAD_ID').value>0)
				{
					//alert('smsVerificationForReusableQuickApply CASE ID::'+document.getElementById('CASE_ID').value);
					insertIntoDBForReusableQuickApply();
				}
			}
		}
	}else{
		if(ajaxData[1]=='SendSMS'){
			alert("Problem in sending SMS Code");
		}else if(ajaxData[1]=='SendEmail'){
			alert("Problem in sending Email");
		}
	}
}

function insertIntoDBForReusableQuickApply() {

	var qstr='';

	var tempURL='';
	if(!isNullOrUndefined(document.getElementById('SITE_HOME_URL')))
	{
  		if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
			tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';
  	}
	qstr = "CUST_ID="+document.getElementById('CUST_ID').value;
			qstr += "&LEAD_ID="+document.getElementById('LEAD_ID').value;
			qstr += "&CASE_ID="+document.getElementById('CASE_ID').value;
	//alert(qstr);
  	xmlhttpPost("POST",tempURL+"registerP.php", "insertIntoDBForReusableQuickApplyPost", qstr);
}

function insertIntoDBForReusableQuickApplyPost(ajaxData)
{
	//alert('ajaxData After Case Id::'+ajaxData);
	document.getElementById('infoBox').style.visibility='hidden';
	document.getElementById('infoBox').style.display='none';
	/*if(document.getElementById('product').value==document.getElementById('hdnHomeLoanProdId').value)
	{
		AdGroupId = "15401";

	}else if(document.getElementById('product').value==document.getElementById('hdnPersonalLoanProdId').value)
	{
		AdGroupId = "14401";
	}else if(document.getElementById('product').value==document.getElementById('hdnCarLoanProdId').value)
	{
		AdGroupId = "18401";
	}else if(document.getElementById('product').value==document.getElementById('hdnCreditCardProdId').value)
	{
		AdGroupId = "16401";

	}*/

	var tempURL='';
	var flag='';
	var resuableFlagVal='';
	if(!isNullOrUndefined(document.getElementById('SITE_HOME_URL')))
	{
  		if(Trim(document.getElementById('SITE_HOME_URL').value)!="")
			tempURL = Trim(document.getElementById('SITE_HOME_URL').value) + '/';
  	}
	if(!isNullOrUndefined(document.getElementById('FLAG')))
	{
  		flag=document.getElementById('FLAG').value;

  	}

	if(!isNullOrUndefined(document.getElementById('SOURCE_ID')))
	{
  		sourceId=document.getElementById('SOURCE_ID').value;

  	}
	if(!isNullOrUndefined(document.getElementById('RESUABLEFLAG')))
	{
  		resuableFlagVal=document.getElementById('RESUABLEFLAG').value;

  	}
	if(resuableFlagVal=='quickApply')
	{
		parent.location.href=tempURL+"registration.php?applicationId="+document.getElementById('LEAD_ID').value;
	}
	else
	{
		parent.location.href=tempURL+"registration.php?sourceId="+sourceId+"&applicationId="+document.getElementById('LEAD_ID').value+"&flag="+flag;
	}


}


function selectNRIStatus(val)
{

	var resuableFlagVal;

	if(!isNullOrUndefined(document.getElementById('RESUABLEFLAG').value))
	{
  				resuableFlagVal=document.getElementById('RESUABLEFLAG').value;

  	}

  if(val=='N')
	{
		document.getElementById('indianCity').style.display="";
		document.getElementById('nriCity').style.display="none";
		document.getElementById('TBL_OTHER_CITY_NAME').style.display="none";
		//document.getElementById('is_nri_yn').value="N";
		document.getElementById('country_code').value="91";
		document.getElementById('country_code').disabled = true;
			if(resuableFlagVal=='quickApply')
			{
				var arrProdId = new Array();
				var arrProdText = new Array();
				var j=0;
				var productLen=document.getElementById('product').options.length;

				document.getElementById('SUB_PRODUCT_ID').options.length=1;

				for(productCnt=1;productCnt<productLen;productCnt++)
				{
						arrProdId[j] = document.getElementById('product').options[productCnt].value;
						arrProdText[j] = document.getElementById('product').options[productCnt].text;
						j++;
				}
				document.getElementById('product').options.length=1;
				document.getElementById('product').options.length=document.getElementById('product').options.length+1;
				document.getElementById('product').options[1].value = document.getElementById('hdnCreditCardProdId').value;
				document.getElementById('product').options[1].text = document.getElementById('hdnCreditCard').value;

				for(i=0;i<arrProdId.length;i++)
				{
					document.getElementById('product').options.length=document.getElementById('product').options.length+1;
					document.getElementById('product').options[i+2].value = arrProdId[i];
					document.getElementById('product').options[i+2].text = arrProdText[i];
				}

				/*if(document.getElementById('QR-column-header').innerHTML!='')
				{
					document.getElementById('QR-column-header').innerHTML="<span class='mainheading1'>QUICK APPLY</span>";
				}*/
			}



	}else
	{

		document.getElementById('indianCity').style.display="none";
		document.getElementById('nriCity').style.display="";
		document.getElementById('TBL_OTHER_CITY_NAME').style.display="none";

		//document.getElementById('is_nri_yn').value="Y";
		document.getElementById('country_code').value="0";
		document.getElementById('country_code').disabled = false;

		if(resuableFlagVal=='quickApply')
		{

			var arrProdId = new Array();
			var arrProdText = new Array();
			var j=0;
			var productLen=document.getElementById('product').options.length;

			document.getElementById('SUB_PRODUCT_ID').options.length=1;

			for(productCnt=1;productCnt<productLen;productCnt++)
			{
				if(document.getElementById('product').options[productCnt].value!=document.getElementById('hdnCreditCardProdId').value)
				{
					arrProdId[j] = document.getElementById('product').options[productCnt].value;
					arrProdText[j] = document.getElementById('product').options[productCnt].text;
					j++;
				}
			}
			document.getElementById('product').options.length=1;
			for(i=0;i<arrProdId.length;i++)
			{
				document.getElementById('product').options.length=document.getElementById('product').options.length+1;
				document.getElementById('product').options[i+1].value = arrProdId[i];
				document.getElementById('product').options[i+1].text = arrProdText[i];
			}

			/*if(document.getElementById('QR-column-header').innerHTML!='')
			{
				document.getElementById('QR-column-header').innerHTML="<span class='mainheading1'>NRI QUICK APPLY</span>";
			}*/
		}

	}
}

function selectMonthlyIncome(val)
{
	 if(val=='1')
	{
		document.getElementById('monthlyIncomeSelfEmployed').style.display="none";
		document.getElementById('monthlyIncomeSalaried').style.display="";


	}else
	{
		document.getElementById('monthlyIncomeSelfEmployed').style.display="";
		document.getElementById('monthlyIncomeSalaried').style.display="none";
	}
}

function disableDropDown(status1)
{
	alert("In It");
	document.getElementById('country_code').disabled = status1;
	alert("Out of It");
	return true;
}

function validateCampaignForm(productId)
{
    if(document.getElementById('is_nri_y').checked == true)
    {
        if(document.getElementById("nri_city").value == "0")
        {
            alert("Please choose your city");
            document.getElementById("nri_city").focus();
            return false;
        }
    }else
    {
        if(document.getElementById("city").value == "0")
        {
            alert("Please choose your city");
            document.getElementById("city").focus();
            return false;
        }
        if(document.getElementById('country_code').value != 91){
        alert("Please Enter Correct Country Code");
		document.getElementById("country_code").focus();
		return false;
        }

    }
	if(document.getElementById("name").value == "" || !isNaN(document.getElementById("name").value))
	{
	    alert("Please enter your name");
	    document.getElementById("name").focus();
	    return false;
	}
	if(document.getElementById('is_nri_y').checked == true && (document.getElementById('country_code').value ==0 || document.getElementById('country_code').value == 91))
	{
	    alert("Please enter Country Code");
		document.getElementById("country_code").focus();
		return false;
	}
	if(document.getElementById('is_nri_y').checked == true)
    {
        if(document.getElementById('mobile').value =='' || isNaN(document.getElementById('mobile').value))
        {
            alert("Please enter valid mobile number");
            document.getElementById("mobile").value ='';
            return false;
        }
    }else
    {
        if(document.getElementById('mobile').value =='' || isNaN(document.getElementById('mobile').value) || document.getElementById('mobile').value.length <10 || (document.getElementById("mobile").value.indexOf(9)!=0 && document.getElementById("mobile").value.indexOf(8)!=0))
        {
            alert("Please enter valid mobile number");
            document.getElementById("mobile").value ='';
            return false;
        }
    }
	if(document.getElementById("landlineCode").value == "" || isNaN(document.getElementById("landlineCode").value))
	{
	    alert("Please enter residence code number properly");
	    document.getElementById("landlineCode").focus();
	    return false;
	}
	if(document.getElementById("landlineNumber").value=="" || isNaN(document.getElementById("landlineNumber").value))
	{
	    alert("Please enter residence number properly");
	    document.getElementById("landlineNumber").focus();
	    return false;
	}
	if(!validateEmail(document.getElementById("email").value))
	{
	    document.getElementById("email").focus();
	    return false;
	}
	if(document.getElementById("subProduct").value == 0)
	{
	    alert("Please choose the subproduct");
	    document.getElementById("subProduct").focus();
	    return false;
	}
	if(productId!=3)
	{
        if(document.getElementById("loanAmount").value=="" || isNaN(document.getElementById("loanAmount").value))
        {
            alert("Please enter the Loan Amount");
            document.getElementById("loanAmount").focus();
            return false;
        }
    }
	if(document.getElementById("monthlyIncome").value=="" || isNaN(document.getElementById("monthlyIncome").value))
	{
	    alert("Please enter Your monthly Income");
	    document.getElementById('monthlyIncome').focus();
	    return false;
	}
	if(document.getElementById("dobDay").value=="0" || document.getElementById("dobMonth").value=="0" || document.getElementById("dobYear").value=="0")
	{
	    alert("Please select Your date of Birth properly");
	    return false;
	}
	if(document.getElementById("professionType").value=="0")
	{
	    alert("Please choose your Profession Type");
	    document.getElementById('professionType').focus();
	    return false;
	}
	if(document.getElementById("checkTerms").checked==false)
	{
	    alert("Please checked Terms & condition check box");
	    document.getElementById('checkTerms').focus();
	    return false;
	}
	document.getElementById('campaignId').value=getURLParam('AdGroupId');
	document.formRegistration.submit();
}

function validateHomeLoanIndex3Campaign()
{
	if(document.getElementById("name").value == "" || !isNaN(document.getElementById("name").value))
	{
	    alert("Please enter your name");
	    document.getElementById("name").focus();
	    return false;
	}
	if(document.getElementById("city").value == "0")
	{
		alert("Please choose your city");
		document.getElementById("city").focus();
		return false;
	}
	if(document.getElementById("dobDay").value=="0" || document.getElementById("dobMonth").value=="0" || document.getElementById("dobYear").value=="0")
	{
	    alert("Please select Your date of Birth properly");
	    return false;
	}
	if(document.getElementById("subProduct").value == 0)
	{
	    alert("Please choose the subproduct");
	    document.getElementById("subProduct").focus();
	    return false;
	}
	if(document.getElementById("loanAmount").value=="" || isNaN(document.getElementById("loanAmount").value))
	{
		alert("Please enter the Loan Amount");
		document.getElementById("loanAmount").focus();
		return false;
	}
	if(document.getElementById("monthlyIncome").value=="" || isNaN(document.getElementById("monthlyIncome").value))
	{
	    alert("Please enter Your monthly Income");
	    document.getElementById('monthlyIncome').focus();
	    return false;
	}
	if(document.getElementById("professionType").value=="0")
	{
	    alert("Please choose your Profession Type");
	    document.getElementById('professionType').focus();
	    return false;
	}
	if(!validateEmail(document.getElementById("email").value))
	{
	    document.getElementById("email").focus();
	    return false;
	}
	if(document.getElementById('mobile').value =='' || isNaN(document.getElementById('mobile').value) || document.getElementById('mobile').value.length <10 || (document.getElementById("mobile").value.indexOf(9)!=0 && document.getElementById("mobile").value.indexOf(8)!=0))
	{
		alert("Please enter valid mobile number");
		document.getElementById("mobile").value ='';
		return false;
	}
	if(document.getElementById("checkTerms").checked==false)
	{
	    alert("Please checked Terms & condition check box");
	    document.getElementById('checkTerms').focus();
	    return false;
	}
	document.getElementById('campaignId').value=getURLParam('AdGroupId');
	document.formRegistration.submit();
}
function getURLParam(strParamName)
{
    var strReturn = "";
    var strHref = window.location.href;
    if( strHref.indexOf("?") > -1 )
    {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
        {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
            {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return decodeURI(strReturn);
}

function validateCampaignFormInsure(productId)
{
	    if(document.getElementById('subProduct').value == "0")
		{
			alert("Please choose a benefit!!");
			return false;
		}
		if(document.getElementById("city").value == "0")
		{
		    alert("Please choose your city");
			document.getElementById("city").focus();
			return false;
		}
			 	
		if(document.getElementById("name").value == "" || !isNaN(document.getElementById("name").value))
		{
			alert("Please enter your name");
			document.getElementById("name").focus();
			return false;
		}
		if(document.getElementById('country_code').value ==0)
		{
			alert("Please enter Country Code");
			document.getElementById("country_code").focus();
			return false;
		}
						
		if(document.getElementById('mobile').value =='' || isNaN(document.getElementById('mobile').value) || document.getElementById('mobile').value.length <10 || (document.getElementById("mobile").value.indexOf(9)!=0 && document.getElementById("mobile").value.indexOf(8)!=0))
		{
			alert("Please enter valid mobile number");
			document.getElementById("mobile").value ='';
			return false;
		}
		if(!validateEmail(document.getElementById("email").value))
		{
			document.getElementById("email").focus();
			return false;
		}
		if(document.getElementById("dobDay").value=="0" || document.getElementById("dobMonth").value=="0" || document.getElementById("dobYear").value=="0")
		{
		    alert("Please select Your date of Birth properly");
		    return false;
		}
		if(document.getElementById("checkTerms").checked==false)
		{
			alert("Please checked Terms & condition check box");
			document.getElementById('checkTerms').focus();
			return false;
		}
		document.getElementById('campaignId').value=getURLParam('AdGroupId');
		document.formRegistration.submit();
}
