function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}
function fnPaste(){event.returnValue=false;}
function isNull(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please enter the " +msg);
		obj.focus();
		return true;
	}else	
		return false;
}

function chkSpeicalChar(obj,msg){

  var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

  for (var i = 0; i < obj.value.length; i++) {
  	if (iChars.indexOf(obj.value.charAt(i)) != -1) {
  	alert ("Special Characters Not Allowed");
	obj.focus();
  	return true;
  	}
  }
}



function isNull1(obj,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if (obj1==""){
		alert("Please select the " +msg);
		obj.focus();
		return true;
	}else
		return false;
}
function isLen(obj,siz,msg){
	if(msg!="Password")
		obj1=Trim(obj.value);
	else
		obj1=obj.value;
	if(obj1!=""){
		var strLen=obj.value;
		if(strLen.length < siz){
			alert(msg+" should have atleast " + siz + " characters");
			obj.focus();
			return true;  
		} 
	}else
		return false;
}
function isSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))==(Trim(obj2.value))){
		alert(msg1+" is matched with the "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
function isNotSame(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value))!=(Trim(obj2.value))){
		alert(msg1+" and "+msg2+" should be same ");
		obj2.focus();
		return true;
	}else
		return false;
}	
function isCorrect(obj1,obj2,msg1,msg2){
	if((Trim(obj1.value)) >= (Trim(obj2.value))){
		alert(msg1+" should be less than "+msg2);
		obj2.focus();
		return true;
	}else
		return false;
}	
/*function isTxtareaNull(obj,msg){
	if(Trim(obj.innerText) == ""){
		alert("Please enter the " + msg);
		obj.focus();
		return true;
	}else
		return false;
}*/

function isTxtareaNull(obj,msg){
	//alert(obj.value);
if(Trim(obj.value)==''){
		alert("Please enter " + msg);
		
		obj.focus();
		return true;
				
	}else
		return false;
}

function isTxtareaLen(obj,msg){
	if(obj.innerHTML.length > 255){
		alert("Please enter below 256 characters in " + msg);
		obj.focus();
		return true;
	}else
		return false;
}

function notEmail(obj,msg){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notZipcode(obj,msg){
	exp = /[a-zA-Z|\d]-{1}/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notChecked(obj,msg){
	checked = false;
	if(obj.length){
		for(i=0;i<obj.length;i++){
			if(obj[i].checked){
				checked = true;break;
			}
		}
	}else if(obj.checked)
		checked = true;
	if(!(checked)){
		alert("Please select the "+msg);
		if(obj.length)
			obj[0].focus();
		else
			obj.focus();
		return true;
	}
}
function notSelected(obj,msg){
	if (obj.options[obj.selectedIndex].value == 0){
		alert("Please select the "+ msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notImageFile(obj,msg){
	var exp = /^.+\.(jpg|gif|jpeg|JPG|JPEG|GIF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg or gif file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function notJpgFile(obj,msg){
	var exp = /^.+\.(jpg|jpeg|JPG|JPEG)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose jpg file for "+msg);
		obj.focus();
		return true;
	}else
		return false;
}

function notDocFile(obj,msg){
	if(Trim(obj.value)!=""){
		var exp = /^.+\.(DOC|doc|TXT|txt)$/;
		if (!exp.test((obj.value).toLowerCase())){
			alert("Please choose doc or txt file for "+msg);
			obj.value="";
			obj.focus();
			return true;
		}else
			return false;	
	}else
		return false;
}

function notCsvFile(obj,msg){
	if(Trim(obj.value)!=""){
		var exp = /^.+\.(CSV|csv)$/;
		if (!exp.test((obj.value).toLowerCase())){
			alert("Please choose csv file ");
			obj.value="";
			obj.focus();
			return true;
		}else
			return false;	
	}else
		return false;
}



function notPdfDocFile(obj,msg){
	var exp = /^.+\.(pdf|doc|PDF|DOC)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf or doc file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}

function notMediaFile(obj,msg){
	var exp = /^.+\.(mp3|mp4|MP3|MP4)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose MP3 or MP4 file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}


function notPdfFile(obj,msg){
	var exp = /^.+\.(pdf|PDF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}
function notPrice(obj,msg){
	exp = /^[\d]*[\.]{0,1}[\d]{1,2}$/;
	if (!exp.test(obj.value)){
		alert("Please enter valid "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkNum(obj,msg){
	exp = /^[\d]/;
	if (!exp.test(obj.value)){
		alert("Please enter only numeric values in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkAlpha(obj,msg)
{
	exp = (/(^([a-z]|[A-Z]|["."]|[\s])*$)/);
	if (!exp.test(obj.value))
	{
		alert("Please enter only alphabets in "+msg);
		obj.focus();
		return true;
	}
	else
		return false;
}	

function fnChkAlphaNum(obj,msg){
	exp = (/(^([a-z]|[A-Z]|[0-9])*$)/);
	if (!exp.test(obj.value)){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}
function fnChkAlphaNumeric(obj,msg){
	var alpha = /[a-zA-Z|]/;
	var Num = /[\d]/;
	if (!(Alpha.test(obj.value) && Num.test(obj.value))){
		alert("Please enter only alphanumeric in "+msg);
		obj.focus();
		return true;
	}else
		return false;
}




	
function notPdfJpgFile(obj,msg){
	var exp = /^.+\.(pdf|jpg|PDF|JPG)$/;
	if (!exp.test((obj.value).toLowerCase())){
		alert("Please choose pdf or doc file for "+msg);
		obj.value="";
		obj.focus();
		return true;
	}else
		return false;
}
function fun_edit_fee()
{
	if(isNull(document.thisForm.txt_fee1,"Level I Membership Price")){return false;}	
	if(notPrice(document.thisForm.txt_fee1,"Level I Membership Price")){return false;}	
	
	if(isNull(document.thisForm.txt_fee2,"Level II Membership Price")){return false;}	
	if(notPrice(document.thisForm.txt_fee2,"Level II Membership Price")){return false;}	
	
	if(isNull(document.thisForm.txt_fee3,"Level III Membership Price")){return false;}	
	if(notPrice(document.thisForm.txt_fee3,"Level III Membership Pricee")){return false;}	
	
}

function fun_product()
{
	if(isNull(document.thisForm.txt_price,"Product Price")){return false;}	
	if(notPrice(document.thisForm.txt_price,"Product Price")){return false;}	
	
}


function fnPromo_Validate()  
{
			if(isNull(document.thisForm.promocode,"Promocode")){ return false; }
			if(fnChkAlphaNum(document.thisForm.promocode,"Promocode")){ return false; }
			if(notChecked(document.thisForm.promo_type,"Promotion Type")){return false; }
			if (document.thisForm.never_expire[1].checked)   {
				if(isNull(document.thisForm.txtstart,"From Date")){return false;}
				if(isNull(document.thisForm.txtend,"To Date")){return false;}
				if(document.thisForm.txtend.value!="")
				{
				   Addate=document.thisForm.txtend.value;
				   tDate=Addate.split("/");
				   orgDate=Addate
				   Addate1=document.thisForm.txtstart.value;
				   tDate1=Addate1.split("/");
				   orgDate1=tDate1[0]+"/"+tDate1[1]+"/"+tDate1[2];         
				   if(Date.parse(orgDate1)> Date.parse(orgDate))
				   {
					alert("Please enter valid Expire To Date");
					document.thisForm.txtend.value="";
					return false;
				   }
				 }
			}
			if (document.thisForm.promo_type[1].checked)   {
				if(isNull(document.thisForm.prod_price,"Product Price")){ return false; }
				if(notPrice(document.thisForm.prod_price,"Product Price")){ return false; }
		   }
			
	
}

function fnDelete_promo(){
	if(notChecked(document.thisForm.elements["chk[]"],"Promocodes to delete")) {return false;}
	if(confirm("Are you sure to delete the selected Promocodes?")){
		document.thisForm.action="promocodes.php";
		document.thisForm.submit();
	} else {
		return false;
	}
}
function fnDelete_lead_price(){
	if(notChecked(document.thisForm.elements["chk[]"],"Lead Purchase Prices to delete")) {return false;}
	if(confirm("Are you sure to delete the selected Lead Purchase Prices?")){
		document.thisForm.action="lead_price.php";
		document.thisForm.submit();
	} else {
		return false;
	}
}

function fnFillAddress()
{

	if(document.thisForm.chk_same.checked==true)
	{
		document.thisForm.txtBillAddress1.value =  document.thisForm.txtMailAddress1.value;
		document.thisForm.txtBillAddress2.value =  document.thisForm.txtMailAddress2.value;
		document.thisForm.txtBillCity.value =  document.thisForm.txtMailCity.value;
		document.thisForm.txtBillState.value =  document.thisForm.txtMailState.value;
		document.thisForm.txtBillZip.value = document.thisForm.txtMailZip.value;
		//document.thisForm.txtBillCountry.value=document.thisForm.txtMailCountry.value;
	}
	else
	{
		document.thisForm.txtBillAddress1.value ="";
		document.thisForm.txtBillAddress2.value ="";
		document.thisForm.txtBillCity.value ="";
		document.thisForm.txtBillState.value ="";
		document.thisForm.txtBillZip.value ="";
		//document.thisForm.txtBillCountry.value="";
	}
}

function fnChkNum_only(e)
{
   // return false;
    var ObjBrowser = navigator.appName; 
    if (ObjBrowser == "Microsoft Internet Explorer")
    {
       var keyno = window.event.keyCode;
    }
    else
    {
       var keyno = e.which || e.keyCode;
    }   
	//alert(keyno)
 	if ((keyno != 8) && (keyno != 46) && (keyno != 13) &&(keyno < 48) || (keyno > 57))
 	{
		//alert("please enter only numbers");
		if (e.preventDefault)
    		e.preventDefault();
		e.returnValue = false;
		return false;
	}
	else
	{
	  return true;
	}
}


function fnlead_price_Validate() {
		if(isNull(document.thisForm.block,"No of Leads")){ return false; }
		if(isNull(document.thisForm.price,"Product Price")){ return false; }
		if(notPrice(document.thisForm.price,"Price")){ return false; }
}