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 fnselectall(){
	obj = document.thisForm.elements['chkSelect[]'];

	chkSelectAll = document.thisForm.chkSelectAll;
	if(obj.length){
		if(chkSelectAll.checked == true){
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == false){
					obj[i].checked = true;
				}
			}
		}else{
			for(i=0;i<obj.length;i++){
				if(obj[i].checked == true){
					obj[i].checked = false;
				}
			}
		}
	}else{
		if(chkSelectAll.checked == true){
			obj.checked = true;
		}else{
			obj.checked = false;
		}
	}		
}
function fnselect(){
	obj = document.thisForm.elements['chkSelect[]'];
	chkSelectAll = document.thisForm.chkSelectAll;
	if(obj.length){
		chkSelectAll.checked = true;
		for(i=0;i<obj.length;i++){
			if(obj[i].checked == false){
				chkSelectAll.checked = false;
				break;
			}
		}
	}else{
		if(obj.checked == true){
			chkSelectAll.checked = true;
		}else{
			chkSelectAll.checked = 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 fnDelete(){
	if(notChecked(document.thisForm.elements["chk[]"],"Buyer(s) to delete")) {return false;}
	if(confirm("Are you sure to delete the selected buyers?")){
		document.thisForm.action="delete_members.php";
		document.thisForm.submit();
	} else {
		return false;
	}
}



function GetCountry(defaultValue,isNotWithSelect){
	var sCountry="Afghanistan,Albania,Algeria,American Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaidjan,Bahamas,Bahrain,Bangladesh,Barbados,Belarus,Belgium,Belize,Benin,Bermuda,Bolivia,Bosnia-Herzegovina,Botswana,Bouvet Island,Brazil,British Indian O. Terr.,Brunei Darussalam,Bulgaria,Burkina Faso,Burundi,Bhutan,Cambodia,Cameroon,Canada,Cape Verde,Cayman Islands,Central African Rep.,Chad,Chile,China,Christmas Island,Cocos (Keeling) Isl.,Colombia,Comoros,Congo,Cook Islands,Costa Rica,Croatia,Cuba,Cyprus,Czech Republic,Czechoslovakia,Denmark,Djibouti,Dominica,Dominican Republic,East Timor,Ecuador,Egypt,El Salvador,Equatorial Guinea,Estonia,Ethiopia,Falkland Isl.(Malvinas),Faroe Islands,Fiji,Finland,France,France (European Ter.),French Southern Terr.,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Great Britain (UK),Greece,Greenland,Grenada,Guadeloupe (Fr.),Guam (US),Guatemala,Guinea,Guinea Bissau,Guyana,Guyana (Fr.),Haiti,Heard & McDonald Isl.,Honduras,Hong Kong,Hungary,Iceland,India,Indonesia,Iran,Iraq,Ireland,Israel,Italy,Ivory Coast,Jamaica,Japan,Jordan,Kazakhstan,Kenya,kyrgyzstan,Kiribati,Korea (North),Korea (South),Kuwait,Laos,Latvia,Lebanon,Lesotho,Liberia,Libya,Liechtenstein,Lithuania,Luxembourg,Macau,Madagascar,Malawi,Malaysia,Maldives,Mali,Malta,Marshall Islands,Martinique (Fr.),Mauritania,Mauritius,Mexico,Micronesia,Moldavia,Monaco,Mongolia,Montserrat,Morocco,Mozambique,Myanmar,Namibia,Nauru,Nepal,Netherland Antilles,Netherlands,Neutral Zone,New Caledonia (Fr.),New Zealand,Nicaragua,Niger,Nigeria,Niue,Norfolk Island,Northern Mariana Isl.,Norway,Oman,Pakistan,Palau,Panama,Papua New,Paraguay,Peru,Philippines,Pitcairn,Poland,Polynesia (Fr.),Portugal,Puerto Rico (US),Qatar,Reunion (Fr.),Romania,Russian Federation,Rwanda,Saint Lucia,Samoa,San Marino,Saudi Arabia,Senegal,Seychelles,Sierra Leone,Singapore,Slovak Republic,Slovenia,Solomon Islands,Somalia,South Africa,Spain,Sri Lanka,St. Helena,St. Pierre & Miquelon,St. Tome and Principe,St.Kitts Nevis Anguilla,St.Vincent & Grenadines,Sudan,Suriname,Svalbard & Jan Mayen Is,Swaziland,Sweden,Switzerland,Syria,Tadjikistan,Taiwan,Tanzania,Thailand,Togo,Tokelau,Tonga,Trinidad & Tobago,Tunisia,Turkey,Turkmenistan,Turks & Caicos Islands,Tuvalu,Uganda,Ukraine,United Arab Emirates,United Kingdom,United States,Uruguay,US Minor outlying Isl.,Uzbekistan,Vanuatu,Vatican City State,Venezuela,Vietnam,Virgin Islands (British)";
	var xCountry=sCountry.split(",");
	var str="";
	if (!isNotWithSelect)str+="<option value='' selected>Select Country</option>\n";else str+="<option value='' selected>Doesn't Matter</option>\n";
	for(i=0;i<xCountry.length; i++)
	if(xCountry[i]==defaultValue)str+="<option value='"+xCountry[i]+"' selected>"+xCountry[i]+"</option>\n";else str+="<option value='"+xCountry[i]+"'>"+xCountry[i]+"</option>\n";
	document.write(str);
}


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 isNullA(obj){
	obj1=Trim(obj.value);
	if (obj1==""){
		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 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 notAtEmail(obj){
	var exp=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!exp.test(obj.value)){
		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 == ""){
		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 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 fnShowCalendar(tObj)
{
	objDateHolder = tObj;
	if(document.all)
	{
		var getIt=window.showModalDialog("includes/calender1.htm","","dialogHeight: 283px; dialogWidth: 276px;  center: Yes; help: No; resizable: No; status: No;titlebar:No; scrollbar:No");
	}
	else
	{
		var getIt=window.open("includes/calender1.htm",'','width=267,height=235,left=200,top=100,resizable=no, toolbar=no,menubar=no,location=no,scrollbar=no');	
	}
	if(document.all)
		if (getIt !='xyz')tObj.value = getIt;	

}

function val_buyer_search()
{
	
	/*if(document.thisForm.txtStartDate.value=="" && document.thisForm.txtEndDate.value=="" && document.thisForm.txt_zip.value=="" && 	document.thisForm.txtMailState.value=="")
	{
		alert("Please select the conditions")
	}
	else
	{*/
		if(document.thisForm.txtStartDate.value!="")
			if(isNull(document.thisForm.txtEndDate,"End Date"))	{ return false; }
		if(document.thisForm.txtEndDate.value!="")
			if(isNull(document.thisForm.txtStartDate,"Start Date"))	{ return false; }
		document.thisForm.action="view_users.php";
		document.thisForm.submit();	
	}

function clear_search()
{
		
		document.thisForm.txtStartDate.value=""
		document.thisForm.txtEndDate.value=""
		document.thisForm.txt_zip.value=""
		document.thisForm.txtMailState.value=""
		document.thisForm.action="view_users.php";
		document.thisForm.submit();	
}


function quickLinks(linkid)
{
	var strOptions="";
	strOptions+='<select name="cmbLinks" class="cmbbox" onchange="fnGo(this)">';
	strOptions+="<option value=''>---Select---</option>";
	strOptions+="<option value='2'>Menu Management</option>";
	strOptions+="<option value='4'>View Sub Menu</option>";
	strOptions+="<option value='5'>Add Sub Menu</option>";
	strOptions+="<option value='3'>View CMS Pages</option>";
	strOptions+="<option value='6'>Add Content Pages</option>";
	strOptions+="</select>"; 
	if(linkid!="")	{
		strOptions=strOptions.replace("<option value='"+linkid+"'>","<option value='"+linkid+"' selected>");
	}
	document.write(strOptions);
	
}

function fnGo(obj) {
	if(obj.value=="1")	window.location.replace("home.php");
	else if(obj.value=="2")	window.location.replace("sections.php");
	else if(obj.value=="3")	window.location.replace("cmspages.php");
	else if(obj.value=="4")	window.location.replace("submenu_section.php");
	else if(obj.value=="5")	window.location.replace("add_submenu.php?site=1");
	else if(obj.value=="6")	window.location.replace("add_cms_content.php");
	
}



function fnSiteChange(obj,pname)	{
	window.location.replace(pname+"?site="+obj.value);
}


function fnValidate_product()
{
	if(isNull(document.thisForm.txt_price,"Product Price")){return false;}	
	if(notPrice(document.thisForm.txt_price,"Product Price")){return false;}	
	
	if(isNull(document.thisForm.txt_pro_price,"Product Promotion Price ")){return false;}	
	if(notPrice(document.thisForm.txt_pro_price,"Product Promotion Price ")){return false;}	
	
	if(isNull(document.thisForm.txt_pro_code,"Product Promotion Code")){return false;}	
	
	
	
	
	
}

function fnValidate_buyer()
{
	if(isNull(document.thisForm.txtFirstName,"First Name")){return false;}
	if(fnChkAlpha(document.thisForm.txtFirstName,"First Name")){return false;}						
	if(isNull(document.thisForm.txtLName,"Last Name")){return false;}
	if(fnChkAlpha(document.thisForm.txtLName,"Last Name")){return false;}						
	if(isNull(document.thisForm.txtEmailAddress,"Email Address")){return false;}						
	if(notEmail(document.thisForm.txtEmailAddress,"Email Address")){return false;}						
	if(isNull(document.thisForm.txtPassword,"Password")){return false;}
	if(document.thisForm.txtPassword.value.length<5 || document.thisForm.txtPassword.value.length>10  ){
		alert("your password must contain 5-10 characters");
		document.thisForm.txtPassword.value="";
		document.thisForm.txtPassword.focus();
		return false;
	}
	
	if(isNull(document.thisForm.txtMailAddress1,"Mailing Address1")){return false;}
	if(isNull(document.thisForm.txtMailCity,"Mailing City")){return false;}
	if(notSelected(document.thisForm.txtMailState,"Mailing State")){return false;}
	if(isNull(document.thisForm.txtMailZip,"Mailing Zip Code")){return false;}						
	if(fnChkNum(document.thisForm.txtMailZip,"Mailing Zip Code")){return false;}						
	if(isNull(document.thisForm.txtBillAddress1,"Billing Address1")){return false;}
	if(isNull(document.thisForm.txtBillCity,"Billing City")){return false;}
	if(notSelected(document.thisForm.txtBillState,"Billing State")){return false;}
	if(isNull(document.thisForm.txtBillZip,"Billing Zip Code")){return false;}						
	if(fnChkNum(document.thisForm.txtBillZip,"Billing Zip Code")){return false;}						
	if(isNull(document.thisForm.txtPrimaryPhone,"Phone Number")){return false;}	
	if(notSelected(document.thisForm.sel_buyer_level,"Buyer Level")){return false;}
	
	
}

function fun_edit_fee()
{
	if(isNull(document.thisForm.txt_fee1,"Level 1 fee")){return false;}	
	if(notPrice(document.thisForm.txt_fee1,"Level 1 fee")){return false;}	
	
	if(isNull(document.thisForm.txt_fee2,"Level 2 fee")){return false;}	
	if(notPrice(document.thisForm.txt_fee2,"Level 2 fee")){return false;}	
	
	if(isNull(document.thisForm.txt_fee3,"Level 3 fee")){return false;}	
	if(notPrice(document.thisForm.txt_fee3,"Level 3 fee")){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;}	
	
	if(isNull(document.thisForm.txt_pro_price,"Level 2 fee")){return false;}	
	if(notPrice(document.thisForm.txt_pro_price,"Level 2 fee")){return false;}
	
}

function fnValidateChangePassword(){
  	if(isNull(document.thisForm.TxtOld,"old password")) return false;
	if(fnChkAlphaNum(document.thisForm.TxtOld,"old password")) return false;
	if(isLen(document.thisForm.TxtOld,5,"old password")){
	    document.thisForm.TxtOld.value="";
	    return false;
	 }
	if(isNull(document.thisForm.TxtNew,"new password")) return false;
	if(fnChkAlphaNum(document.thisForm.TxtNew,"new password")) return false;
    if(isLen(document.thisForm.TxtNew,5,"new password")){ 
	   document.thisForm.TxtNew.value="";
	   return false;
	}
	if(Trim(document.thisForm.TxtOld.value)==Trim(document.thisForm.TxtNew.value)){
		alert("Old and new password should not be the same");
		document.thisForm.TxtNew.value="";
		document.thisForm.TxtConfirm.value="";
		document.thisForm.TxtNew.focus();
		return false;
	}	
	if(isNull(document.thisForm.TxtConfirm,"confirm password")) return false;
	if(fnChkAlphaNum(document.thisForm.TxtConfirm,"confirm password"))
	if(isLen(document.thisForm.TxtConfirm,5,"confirm password")){
       document.thisForm.TxtConfirm.value="";
	   return false;
	}
  	if(isNotSame(document.thisForm.TxtNew,document.thisForm.TxtConfirm,"New","Confirm Password")){
      document.thisForm.TxtConfirm.value="";
	  return false;	  
	}
	if(isSame(document.thisForm.TxtNew,document.thisForm.TxtOld,"New Password","Old Password")) return false;
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function notImageFileA(obj){
	var exp = /^.+\.(jpg|gif|png|jpeg|PNG|JPG|JPEG|GIF)$/;
	if (!exp.test((obj.value).toLowerCase())){
		obj.focus();
		return true;
	}else
		return false;
}
function notSelectedA(obj){
	if (obj.options[obj.selectedIndex].value == ""){
		obj.focus();
		return true;
	}else
		return false;
}
function forceNumber(event){
	
var keyCode = event.keyCode ? event.keyCode : event.charCode;
if((keyCode < 48 || keyCode > 58) && keyCode != 8 && keyCode != 9 && keyCode != 32 && keyCode != 37 && keyCode != 39 && keyCode != 40 && keyCode != 41 && keyCode != 43 && keyCode != 46)
return false;
}
