  var tableElementName = "tableElement";
  var rowElementName = "rowElement";

   //var c = 0;

  function addRow()
  {
	/*searchObj = window.location.search;
	if(searchObj!=null && searchObj!=undefined)
	{
		if(searchObj.indexOf('balanceCount') != -1)
		{
			BALANCE_LIMIT = searchObj.substring(searchObj.indexOf('balanceCount')+13);
			MAX_LIMIT_ALLOWED = 'false';
		}
	}*/
	if(MAX_LIMIT_ALLOWED == 'true' || BALANCE_LIMIT > 1)
	{
  		if(document.getElementById(tableElementName) != null && document.getElementById(rowElementName) != null)
  		{
			var rowNodeClone = document.getElementById(rowElementName).cloneNode(true);
			var tableNode 	= document.getElementById(tableElementName).getElementsByTagName("TBODY").item(0);
			tableNode.appendChild(rowNodeClone);
			BALANCE_LIMIT = BALANCE_LIMIT-1;
		}
	}
	else
	{
		alert('Sorry, You have already reached the limit of max entries for the day.');		
		document.getElementById("SAVCON").style.display='none';
		//document.getElementById("ADDROW").style.display='none';
	}
  }
  function deleteRow()
  {
  	if(document.getElementById(tableElementName) != null)
  	{
		tableNode 	= document.getElementById(tableElementName).getElementsByTagName("TBODY").item(0);
	  	if(tableNode.rows.length > 1)
		{
			tableNode.deleteRow(tableNode.rowIndex);
			BALANCE_LIMIT = BALANCE_LIMIT+1;
			if(BALANCE_LIMIT > 1)
			{
				document.getElementById("SAVCON").style.display='block';
				//document.getElementById("ADDROW").style.display='block';
			}
		}
	}
  }
  function parseURL()
  {
	// To make the theValue hidden as 0 in Add Row Option in Usage Entry
	if(document.getElementById('theValue') != null && document.getElementById('theValue') != undefined)
		document.getElementById('theValue').value=0;

	// For parsing the URL
	searchObj = window.location.search;
	if(searchObj!=null && searchObj!=undefined)
	{
		if(searchObj.indexOf('balanceCount') != -1)
		{
			BALANCE_LIMIT = searchObj.substring(searchObj.indexOf('balanceCount')+13);
			MAX_LIMIT_ALLOWED = 'false';
			if(BALANCE_LIMIT <= 1)
			{
				document.getElementById("SAVCON").style.display='none';
				//document.getElementById("ADDROW").style.display='none';
			}
		}
	}
  }

  function callImageCaptcha(frm)
  {
  	 //c++;
       var c=Math.floor(Math.random()*1000);
   	 frm.captchaImg.src = renderImageURL + "&cid=" + c;
	 frm.jcaptcha_response.value="";
  }
  
   function multipleEntryReg(form,multiEntries,butType,captchaAvailable) 
	{
		var urlMultiple;
		var multiEntryFieldcheck = "false";
		//processOpt = butOpt;
		if(multiEntries != ''  && multiEntries!=null)
		{
		    multiEntriesArr = multiEntries.split(",");
			for(multiEntryCnt = 0; multiEntryCnt < multiEntriesArr.length; multiEntryCnt++)
			{
				multiEntry = multiEntriesArr[multiEntryCnt];
				mutiEntryVal = eval('form.'+multiEntry);
				if(mutiEntryVal.value != '') // Atleast one value has value
				{
					multiEntryFieldcheck = "true";
					break;
				}
			}
		}
		if(butType == 'SC')
		{
			if(multiEntryFieldcheck == 'true')
			{
				urlMultiple = "regandcontinue.do";
			}
			else
			{
				urlMultiple = "registerandcont.do";
			}
		}
		else
		{
			if(multiEntryFieldcheck == 'true')
			{
				urlMultiple = "multiple.do";
			}
			else
			{
				urlMultiple = "register.do";
			}
		}
		if(captchaAvailable == 'true')
		{
			submitPage(urlMultiple, form, butType);
		}
		else
		{
			validatePage(urlMultiple,form, butType);
		}
    }

	function singleEntryReg(form,captchaAvailable) 
	{
		var urlSingle = 'register.do';
		if(captchaAvailable == 'false')
		{
	        validatePage(urlSingle,form);
		}
		else
		{
	        submitPage(urlSingle,form);
		}
    }

	function openWindow(url, name) {
		//alert("URL" + url);
		window.open(url, name); 
	}

// function for add the row
	function addEvent(frm,formElements)
	{
		if(MAX_LIMIT_ALLOWED == 'true' || BALANCE_LIMIT > 1)
		{
			if(document.getElementById('myDiv') != null && document.getElementById('toAdd') != null && document.getElementById('theValue') != null)
			{
				var rowDiv = document.getElementById('myDiv');
				var toAd = document.getElementById('toAdd');
				var hidValue = document.getElementById('theValue');
				var num = (document.getElementById("theValue").value -1)+ 2;
				hidValue.value = num;
				var divIdName = "my"+num+"Div";
				var newdiv = document.createElement('div');
				newdiv.setAttribute("id",divIdName);
				newdiv.innerHTML = "<div>&nbsp;"+toAd.innerHTML+"<input type=button value='Remove' onclick=\"removeEvent(\'"+divIdName+"\')\"></div>";
				rowDiv.appendChild(newdiv);
				formElementsArr = formElements.split(',');
				for(paramCount=0;paramCount<formElementsArr.length;paramCount++)
				{
					var test = eval('frm.'+formElementsArr[paramCount]);
					test(num).value = '';
				}
				BALANCE_LIMIT = BALANCE_LIMIT-1;
			}
		}
		else
		{
			alert('Sorry, You have already reached the limit of max entries for the day.');		
			document.getElementById("SAVCON").style.display='none';
			//document.getElementById("ADDROW").style.display='none';
		}
	}
// function for delete the row
	function removeEvent(divNum)
	{
		var num = document.getElementById("theValue").value -1;
		document.getElementById('theValue').value = num;
		var rowDiv = document.getElementById('myDiv');
		var olddiv = document.getElementById(divNum);
		rowDiv.removeChild(olddiv);
	}
	
	   function multipleEntry(frm,multiChk,butType,cptaAvlbl) {
	    var pwdVal = document.frm.password.value;
		var cnfrmPwdVal = document.frm.cnfmPassword.value;
		var nickNameVal = document.frm.nickName.value;
		var boolCheck = false;
		var passwordMsgDisplay = '';
        document.getElementById("message").innerHTML = passwordMsgDisplay;	
		document.getElementById("HeaderMessage").innerHTML = "";
		if(nickNameVal != '' && pwdVal != '')
		{
			if(pwdVal == nickNameVal) 
			{
				boolCheck = true;
				passwordMsgDisplay = "<LI><font style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color:#990000'>Por favor, ingrese una contrase&ntilde;a que sea diferente de su nombre de Apodo.</FONT></LI>";
				document.getElementById("nickNameId").style.color = "#990000";
				document.getElementById("passwordId").style.color = "#990000";
			}
		}
        if(pwdVal !=""  ||   cnfrmPwdVal != "") 
		{
			if(pwdVal !=cnfrmPwdVal) 
			{
				boolCheck = true;
				passwordMsgDisplay += "<LI><font style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color:#990000'>Tanto Contrase&ntilde;a como su confirmaci&oacute;n deben ser iguales</FONT></LI>";
				document.getElementById("passwordId").style.color = "#990000";
				document.getElementById("cnfmPasswordId").style.color = "#990000";
			} 
		} 
		if(!boolCheck)
		{
			document.getElementById("HeaderMessage").innerHTML = "";			
			changeFontColor(frm); // To change the form field colors when initial load		
			multipleEntryReg(document.frm,multiChk,butType,cptaAvlbl);
		}
		else
		{
			changeFontColor(frm); // To change the form field colors when initial load
			document.getElementById("HeaderMessage").innerHTML = "<font style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color:#990000'>Uno o m&aacute;s de los campos contienen informaci&oacute;n incompleta. Corrija los campos destacados en rojo para continuar.</font><br><br>";
			document.getElementById("message").innerHTML = passwordMsgDisplay;
		}
	}

	function sendMails(frm)
	{
  frm.actual_sender_name.value = encodeURI(frm.actual_sender_name.value);
	frm.recipient_name.value = encodeURI(frm.recipient_name.value);

		url="/EmailApp/sendEmail.do";
		var urlContent = decodeURI(buildMailRequest(frm));


		if (window.XMLHttpRequest) 
		{
			req = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{ // IE
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if(req) 
		{		  
			try
			{	
				var message = encodeURI(urlContent);

				req.onreadystatechange = processStateChangeMail;
				req.open("POST", url, true);	
			
				req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
				req.send(message);

				if(req.onreadystatechange == null)  {
				
					processStateChangeMail();
				}
				//document.location.href = "hr_euro08_thankyou.html";	
			}
		catch(exception)
		{
			
		}
	  }
	}
	function buildMailRequest(frm)
	{
		controlParams = "";	    
		for(paramCount=0;paramCount<frm.elements.length;paramCount++)
		{
			controlParams += frm.elements[paramCount].name+"=";
			controlParams += frm.elements[paramCount].value+"&";
		}
		if(controlParams != "")
			controlParams = controlParams.substring(0,controlParams.lastIndexOf("&"));	    	
		return controlParams;      	
	}
	function processStateChangeMail() 
	{
		if (req.readyState == 4) 
		{		
			if (req.status == 200) 
			{
				
	mailData = req.responseText;
				if (mailData!= null && mailData.indexOf('success') != -1)
				{
					document.location.href = "thankyou.html";
				}
			}
		}
	}

function sendMailForRegistration(frm)
	{
		url="/EmailApp/sendEmail.do";
		//url = "http://www.stage.mastercard.com/EmailApp/sendEmail.do";
		var urlContent = buildMailRequest(frm);
		
		if (window.XMLHttpRequest) 
		{
			req = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) 
		{ // IE
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if(req) 
		{		  
			try
			{			
				req.onreadystatechange = processStateChangeMailReg;
				req.open("POST", url, true);				
				req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				req.send(urlContent);
				if(req.onreadystatechange == null)  {
					processStateChangeMailReg();
				}
				
			}
		catch(exception)
		{			
		}
	  }
	}
function processStateChangeMailReg() 
	{
		if (req.readyState == 4) 
		{	
			if (req.status == 200) 
			{
				mailData = req.responseText;
				if (mailData!= null && mailData.indexOf('success') != -1)
				{
					//document.location.href = "thankyou.html";
				}
			}
		}
	}
