function stripBlanks(fld) 
	{
		var result = "";
		var c = 0;
		for (i=0; i<fld.length; i++) 
		{
			if (fld.charAt(i) != " " || c > 0) 
			{
				result += fld.charAt(i);
				if (fld.charAt(i) != " ") c = result.length;
			}
		}
		
		return result.substr(0,c);
	} 
	

function ValidateThis()
	{
		if (stripBlanks(document.frmMerchant.business_name.value) == "") 
		{
			alert("Please enter Business Name.");
			document.frmMerchant.business_name.focus();
			return false;
		}
		if (stripBlanks(document.frmMerchant.business_address1.value) == "")
		{
			alert("Please enter Business Address1.");
			document.frmMerchant.business_address1.focus();
			return false;
		}
		
		/*if (stripBlanks(document.frmMerchant.business_address2.value) == "")
		{
			alert("Please enter the Business Address2.");
			document.frmMerchant.business_address2.focus();
			return false;
		}*/
		if (stripBlanks(document.frmMerchant.txtBizPhone1.value) == "" || stripBlanks(document.frmMerchant.txtBizPhone2.value) == "" || stripBlanks(document.frmMerchant.txtBizPhone3.value) == "")
		{
			alert("Please enter the Bussiness Phone.")
			document.frmMerchant.txtBizPhone1.focus();
			return false;
		}
		else
		{
			var txtBizPhone=document.frmMerchant.txtBizPhone1.value+document.frmMerchant.txtBizPhone2.value+document.frmMerchant.txtBizPhone3.value;
		   
		}
		if (txtBizPhone.length < 10 )
		{
			alert("Please enter a correct Bussiness Phone.");
			document.frmMerchant.txtBizPhone1.focus();
			return false;
		}	
		
		if (stripBlanks(document.frmMerchant.merchant_name.value) == "")
		{
			alert("Please enter the Merchant Name.");
			document.frmMerchant.merchant_name.focus();
			return false;
		}
		
		if (stripBlanks(document.frmMerchant.merchant_email.value) == "")
		{
			alert("Please enter the E-Mail");
			document.frmMerchant.merchant_email.focus();
			return false;
		}
		if (validMail(stripBlanks(document.frmMerchant.merchant_email.value)) !=true)
		{
			
			document.frmMerchant.merchant_email.focus();
			return false;
		}
		
		/*if (stripBlanks(document.frmMerchant.merchant_address.value) == "")
		{
			alert("Please enter the Merchant Address.");
			document.frmMerchant.merchant_address.focus();
			return false;
		}*/
		
		if (stripBlanks(document.frmMerchant.txtMerchantPhone1.value) == "" || stripBlanks(document.frmMerchant.txtMerchantPhone2.value) == "" || stripBlanks(document.frmMerchant.txtMerchantPhone3.value) == "")
		{
			alert("Please enter the Merchant Phone.")
			document.frmMerchant.txtMerchantPhone1.focus();
			return false;
		}
		else
		{
			var txtMerchantPhone=document.frmMerchant.txtMerchantPhone1.value+document.frmMerchant.txtMerchantPhone2.value+document.frmMerchant.txtMerchantPhone3.value;
		   
		}
		
		if (txtMerchantPhone.length < 10 )
		{
			alert("Please enter a correct Merchant Phone.");
			document.frmMerchant.txtMerchantPhone1.focus();
			return false;
		}
		
		/*if (stripBlanks(document.frmMerchant.website_url.value) == "")
		{
			alert("Please enter the Website Url.");
			document.frmMerchant.website_url.focus();
			return false;
		}
		
	    var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
	
		if(!(tomatch.test(stripBlanks(document.frmMerchant.website_url.value))))
	    {
		   alert("URL invalid.");
		   return false; 
	    }
		*/
		
		return true;
}	
function validate_frm()
{
		if (stripBlanks(document.frmMerchant.name.value) == "") 
		{
			alert("Please enter Your Name");
			document.frmMerchant.name.focus();
			return false;
		}
		
		if (stripBlanks(document.frmMerchant.email.value) == "")
		{
			alert("Please enter the E-Mail")
			document.frmMerchant.email.focus();
			return false;
		}
		if (validMail(stripBlanks(document.frmMerchant.email.value)) !=true)
		{
			
			document.frmMerchant.email.focus();
			return false;
		}
		return true;
}

function validate_frm_step2()
{
		
		if (document.frmMerchant.bankrupt.value == "")
		{
			alert("Please select the Desired Financial Amount")
			document.frmMerchant.bankrupt.focus();
			return false;
		}
		

		if (document.frmMerchant.desired_financial_amount.value == "")
		{
			alert("Please select the Desired Financial Amount")
			document.frmMerchant.desired_financial_amount.focus();
			return false;
		}
		
		if (stripBlanks(document.frmMerchant.business_name.value) == "")
		{
			alert("Please enter Business Name");
			document.frmMerchant.business_name.focus();
			return false;
		}
		
		if (stripBlanks(document.frmMerchant.business_type.value) == "")
		{
			alert("Please enter the Business Type");
			document.frmMerchant.business_type.focus();
			return false;
		}
		if (stripBlanks(document.frmMerchant.country.value) == "")
		{
			alert("Please enter the Bussiness Country")
			document.frmMerchant.country.focus();
			return false;
		}
		if (document.frmMerchant.state1.value == "")
		{
			alert("Please select the Bussiness State")
			document.frmMerchant.state1.focus();
			return false;
		}
		if (document.frmMerchant.gross_monthly_revenue.value == "")
		{
			alert("Please select the Gross Monthly Revenue")
			document.frmMerchant.gross_monthly_revenue.focus();
			return false;
		}
		if (stripBlanks(document.frmMerchant.txtBizPhone1.value) == "" || stripBlanks(document.frmMerchant.txtBizPhone2.value) == "" || stripBlanks(document.frmMerchant.txtBizPhone3.value) == "")
		{
			alert("Please enter the Bussiness Phone")
			document.frmMerchant.txtBizPhone1.focus();
			return false;
		}
		else
		{
			var txtBizPhone=document.frmMerchant.txtBizPhone1.value+document.frmMerchant.txtBizPhone2.value+document.frmMerchant.txtBizPhone3.value;
		   
		}
		if (txtBizPhone.length < 10 )
		{
			alert("Please enter a correct Bussiness Phone");
			document.frmMerchant.txtBizPhone1.focus();
			return false;
		}	
	
		
		if (stripBlanks(document.frmMerchant.call_time.value) == "")
		{
			alert("Please enter the Call Time");
			document.frmMerchant.call_time.focus();
			return false;
		}
	
			if (document.frmMerchant.bankrupt.value == "")
		{
			alert("Please select the Bankrupt Status")
			document.frmMerchant.bankrupt.focus();
			return false;
		}
		
		if (document.frmMerchant.start_month.value == "")
		{
			alert("Please select the Bussiness Start Month")
			document.frmMerchant.start_month.focus();
			return false;
		}
		if (document.frmMerchant.start_year.value == "")
		{
			alert("Please select the Start Year")
			document.frmMerchant.start_year.focus();
			return false;
		}
		
		if (document.frmMerchant.accept_credit_cards.value == "")
		{
			alert("Please select the Accept Credit Card")
			document.frmMerchant.accept_credit_cards.focus();
			return false;
		}
		if (document.frmMerchant.monthly_cc_sales.value == "")
		{
			alert("Please select the Monthly Credit Card Sales")
			document.frmMerchant.monthly_cc_sales.focus();
			return false;
		}

	
		return true;

}

function validate()
{
	if (stripBlanks(document.frm.to.value) == "") 
		{
			alert("Please enter email address of recepient.");
			document.frm.to.focus();
			return false;
		}
		if (stripBlanks(document.frm.subject.value) == "")
		{
			alert("Please enter the subject.");
			document.frm.subject.focus();
			return false;
		}
		
		/*if (stripBlanks(document.frm.message.value) == "")
		{
			alert("Please enter the message.");
			document.frm.message.focus();
			return false;
		}*/
		return true;
}
	
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

function onlyDigits(e) 
{
	var _ret = true;
	if (isIE) 
	{
		if (window.event.keyCode != 13)
		{
			if (window.event.keyCode < 46 || window.event.keyCode > 57) 
				{
					window.event.keyCode = 0;
					_ret = false;
				}
		}
	}
	if (isNS) 
		{
			if (e.which < 46 || e.which > 57) 
			{
				e.which = 0;
				_ret = false;			
			}
		}
	return (_ret); 
}

function onlyMoney(e) 
{
	var _ret = true;
	if (isIE) 
	{
		if (window.event.keyCode != 13   )
		{
			if (window.event.keyCode < 45 || window.event.keyCode > 57) 
				{
					window.event.keyCode = 0;
					_ret = false;
				}
		}
	}
	if (isNS) 
		{
			if (e.which < 46 || e.which > 57) 
			{
				e.which = 0;
				_ret = false;			
			}
		}
	return (_ret); 
}
function validMail(emailad) 
{
	a = emailad.split(";")
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	for(i=0;i<a.length;i++)
	{
		emailadd = a[i];
		if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
			{
				alert("Incorrect email address!");
				return false
			}
		else 
			{   
				return true
			}
	}
}

function numberonly(field)
	{
	var digits="0123456789"
	var alpha="abcdefghijklmnopqrstuvwxyz!@#$%^&*()_-+=|\,.:/'<>?`~ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var temp		
	var ret
	ret = true
	for (var i=0;i<field.value.length;i++) 
		{
		temp=field.value.substring(i,i+1)
		if ((alpha.indexOf(temp)!==-1) && (digits.indexOf(temp)==-1))		
			{
			alert("Please Enter Numbers Only !")
			//field.select();
			//field.focus();
			ret = false;
			break;
			}			
		}
	return ret
	}
var theform;
var isIE;
var isNS;

/*
Function to detect the Browser type.
*/
function detectBrowser()
{
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) 
		theform = document.forms["Form1"];
	else 
		theform = document.Form1;
		
	//browser detection
	var strUserAgent = navigator.userAgent.toLowerCase();
	isIE = strUserAgent.indexOf("msie") > -1;
	isNS = strUserAgent.indexOf("netscape") > -1;
	
}

/*
This function will fire when the control leaves the Text Box.
The function is responsible for formating the numbers to amount type.
*/
function FormatAmtControl(ctl){
	var vMask ;
	var vDecimalAfterPeriod ;
	var ctlVal;
	var iPeriodPos;
	var sTemp;
	var iMaxLen 
	var ctlVal;
	var tempVal;
	ctlVal = ctl.value;
	vDecimalAfterPeriod  = 2
	iMaxLen  = ctl.maxLength;

	if (isNaN(ctlVal))
	{
		// clear the control as this is not a num
		ctl.value=""
	}
	else{
		ctlVal =  ctl.value;
		iPeriodPos =ctlVal.indexOf(".");
		if (iPeriodPos<0)
		{
			if (ctl.value.length > (iMaxLen-3))
			{
				sTemp = ctl.value
				 tempVal = sTemp.substr(0,(iMaxLen-3)) + ".00";
			}
			else
			tempVal = ctlVal + ".00"
		}
		else{
			if ((ctlVal.length - iPeriodPos -1)==1)
				tempVal = ctlVal + "0"
			if ((ctlVal.length - iPeriodPos -1)==0)
				tempVal = ctlVal + "00"
			if ((ctlVal.length - iPeriodPos -1)==2)
				tempVal = ctlVal;
			if ((ctlVal.length - iPeriodPos -1)>2){
				tempVal = ctlVal.substring(0,iPeriodPos+3);
			}


		}
		ctl.value=tempVal;
	}
}

/*
This function is responsible for filtering the keys pressed and the maintain the amount format of the 
value in the Text box
*/
	function HandleAmountFiltering(ctl){
	var iKeyCode, objInput;
	var iMaxLen 
	var reValidChars = /[0-9.]/;
	var strKey;
	var sValue;
	var event = window.event || arguments.callee.caller.arguments[0];
	iMaxLen  = ctl.maxLength;
	sValue = ctl.value;
	detectBrowser();

	if (isIE) {
		iKeyCode = event.keyCode;
			objInput = event.srcElement;
	} else {
		iKeyCode = event.which;
		objInput = event.target;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (reValidChars.test(strKey))
	{
		if(iKeyCode==46)
		{
			if(objInput.value.indexOf('.')!=-1)
				if (isIE)
					event.keyCode= 0;
				 else
				 {
				 	 if(event.which!=0 && event.which!=8 && event.which!=13)
					return false;
				 }
		}
		else
		{
			if(objInput.value.indexOf('.')==-1)
			{
				
				if (objInput.value.length>=(iMaxLen-3))
				{
					if (isIE)
						event.keyCode= 0;
					 else
					 {
					 	 if(event.which!=0 && event.which!=8 && event.which!=13)
						return false;
					 }
	
				}
			}
			if ((objInput.value.length==(iMaxLen-3)) && (objInput.value.indexOf('.')==-1))
			{
				objInput.value = objInput.value +'.';
			
			}

	
		}

	}
	else{
		if (isIE)
			if  (event.keyCode!=13)
			{
			
			event.keyCode= 0;
			}
		 else
		 {
			if (event.which!=13)
				return true;
			 if(event.which!=0 && event.which!=8)
			 return false;
		 }
	}

}
function stateForCountry(coun)
{
	//var coun=form1.getElementById("country").value;
	//alert("Country ID : " + coun);
	strUrl="get_result.php?id="+coun;
	xmlhttpPost(strUrl,"state");
}

function CheckAll()
{
	var count = document.adminForm.elements.length;
	for (i=0; i < count; i++) 
	{
		if(document.adminForm.elements[i].type == 'checkbox')
			document.adminForm.elements[i].checked = document.adminForm.chkall.checked;
	}
}

function doAction(action)
{
	var count = document.adminForm.elements.length;
	var flag=false;
	var msg = "";
	for (i=0; i < count; i++) 
	{
		if(document.adminForm.elements[i].type == 'checkbox')
		{
			if(document.adminForm.elements[i].checked == 1)
			flag=true;
		}
	}
	if(flag==true)
	{
		if(action == "delete")
		{
			msg = "";			
		}
		if(window.confirm("Are you sure to " + action + " the selected record.\n"+msg))
		{
			document.adminForm.action.value=action;
			document.adminForm.submit();
		}
	}
	else
		alert("Please select at least one checkbox to perform action.");
}

function changeImage(obj,img)
  {
	obj.src=img;
  }


function phone(obj,ln)
{
	if(obj.name=='txtBizPhone1' && ln==3)
		document.getElementById('txtBizPhone2').focus();
	if(obj.name=='txtBizPhone2' && ln==3)
		document.getElementById('txtBizPhone3').focus();
	if(obj.name=='txtMerchantPhone1' && ln==3)
		document.getElementById('txtMerchantPhone2').focus();
	if(obj.name=='txtMerchantPhone2' && ln==3)
		document.getElementById('txtMerchantPhone3').focus();	
} 
 