function right(e){
	if (navigator.appName == 'Netscape' && 	(e.which == 3 || e.which == 2))
		return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)){
		alert("Right Click and View Source have been disabled on this page");
		return false;
	}
	return true;
}
function rightCALL(){
	document.onmousedown=right;
	document.onmouseup=right;
	if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	if (document.layers) window.captureEvents(Event.MOUSEUP);
	window.onmousedown=right;
	window.onmouseup=right;
}

String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function IsValidEmail1(NForm){
        NForm.email1.focus();
        var str = NForm.email1.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Email Address");
                return false; 
        } 
}

function IsValidReviewForm(f3){ 
	
	        	var cnt = -1;
	        	for (var i=0; i < f3.length; i++) {
			   if (f3[i].checked) 
			   	cnt = i; 
			   }
			if (cnt == -1) {
	        		alert("choose a rating");
				return false;
			}
			else{
				return true;
			}
}

function IsValidEmail2(NForm){ 
        NForm.email2.focus();
        var str = NForm.email2.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Confirm Email Address");
                return false; 
        } 
}


function validatemailstogother(Nform){
	if(Nform.email1.value!=Nform.email2.value){
		Nform.lname.focus();
		alert("Please Check your e-mails!");
		return false;
	}
	return true;
}
function validatefirstname(Nform){
	if(!Nform.fname.value.trim()||Nform.fname.value.length <4 ){
		Nform.fname.focus();
		alert("First name must be more than 4 characters!");
		return false;
	}
	return true;
}

function validatelastname(Nform){
	if(!Nform.lname.value.trim()||Nform.lname.value.length <4){
		Nform.lname.focus();
		alert("Last name must be more than 4 characters!!");
		return false;
	}
	return true;
}

function validategender(Nform){
	if(Nform.Gender[0].checked == false && Nform.Gender[1].checked == false){
		alert("Select your gender");
		return false;
	}
	return true;
}

function validateMobileNumber(Nform){
	if(!Nform.mobileNumber.value.trim()||Nform.mobileNumber.value.length < 8){
		Nform.mobileNumber.focus();
		alert("Mobile number must be 8 digits!");
		return false;
	}
	return true;
}

function validateAddress(Nform){
	if(!Nform.address.value.trim()){
		Nform.address.focus();
		alert("Please enter your address!");
		return false;
	}
	return true;
}

function validateCountry(Nform){
	if(Nform.country.value == ""){
		Nform.country.focus();
		alert("Please select a Country!");
		return false;
	}else{
		if(Nform.country.value == 'Lebanon'){
			if(!validateCityLeb(Nform))
				return false;
		}else{
			if(!validateCity(Nform))
				return false;
		}
	}
	return true;
}

function validateCityLeb(Nform){
	if(!Nform.city_leb.value.trim()){
		Nform.city_leb.focus();
		alert("Please enter your city!");
		return false;
	}
	return true;
}

function validateCity(Nform){
	if(!Nform.city.value.trim()){
		Nform.city.focus();
		alert("Please enter your city!");
		return false;
	}
	return true;
}

function validateusercheck(Nform){
	if(Nform.useragree.checked==false){
		Nform.useragree.focus();
		alert("You must agree in order to continue registration");
		return false;
	}
	return true;
}
function validteRegisterForm(Nform){
	return IsValidEmail1(Nform) &&
	IsValidEmail2(Nform)  && 
	validatemailstogother(Nform) && 
	validatefirstname(Nform) &&
	validatelastname(Nform) &&
	validategender(Nform) &&
	validateMobileNumber(Nform) &&
	validateAddress(Nform) &&
	validateCountry(Nform) &&
	//validateCity(Nform) &&
	validateusercheck(Nform);
	return false;
}

function validteUpdateForm(Nform){
	return validatefirstname(Nform) &&
	validatelastname(Nform) &&
	validateMobileNumber(Nform) &&
	validateAddress(Nform) &&
	validateCountry(Nform)
	//validateCity(Nform);
	return false;
}


//functions for viewcart.php
function display_showhide(id,id2){
	var target = document.getElementById(id);
	var target2 = document.getElementById(id2);
	target.style.display = 'none';
	target2.style.display = '';
}

function Validate_wul_Name(NForm)
{ 
 NForm.Cname.focus();
 if(NForm.Cname.value.length==0){ 
  alert("You must enter a Name"); 
  return false; 
 }else{
  return true;
 }
}

function Validate_wul_Address(NForm)
{ 
 NForm.address1.focus();
 if(NForm.address1.value.length==0){ 
  alert("You must enter an Address");
  return false;
 }else{
  return true;
 }
}

function Validate_wul_City(NForm)
{ 
 NForm.city.focus();
 if(NForm.city.value.length==0){ 
  alert("You must enter a City"); 
  return false; 
 }else{
  return true;
 }
}

function IsValidEmail(NForm){ 
	
        NForm.email.focus();
        var str = NForm.email.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Email");
                return false; 
        }
}

function Validate_wul_phoneNumber(NForm){ 
        NForm.mobilenum.focus();
 if(NForm.mobilenum.value.length==0){ 
  alert("You must enter a Mobile Number"); 
  return false; 
 }else{
  return true;
 }
}

function ValidatePurchase_Form(NForm){
	if(NForm.country.value==102 && NForm.cityid.value==''){
		alert("Since you selected Lebanon, you need to select a City.");
		return false;
		
	}
	return Validate_wul_Name(NForm) &&
	Validate_wul_Address(NForm)&&
	Validate_wul_City(NForm) &&
	IsValidEmail(NForm) &&
	Validate_wul_phoneNumber(NForm);
}

function IsValidLogin(NForm){
	
        NForm.email.focus();
        var str = NForm.email.value;
      	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)){
     		NForm.password.focus();
        	if(NForm.password.value.length==0 ){
            		alert("Enter a Password");
                	return false;
            	}else{
               	 	return true; 
                		}	
        }else{ 
                alert("Enter a valid User Name");
                return false; 
        }
}
function validatepasswords(NForm){
	if(!NForm.password.value.trim()||NForm.password.value.length < 6){
		NForm.password.focus();
		alert("Password must be more than 6 characters");
		return false;
	}
	if(!NForm.password2.value.trim()||NForm.password2.value.length < 6){
		NForm.password2.focus();
		alert("Confirm Password must be more than 6 characters");
		return false;
	}
	if(NForm.password2.value.trim()!=NForm.password.value.trim()){
		NForm.password2.focus();
		alert("Passwords does not match,please check your passwords!");
		return false;
	}
	return true;
}

function IsValidEmailToFreind(NForm){
	NForm.to.focus();
        var str = NForm.to.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)){ // if syntax is valid 
        	NForm.from.focus();
        	var str = NForm.from.value; 
        	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        	if (!reg1.test(str) && reg2.test(str)){  // if syntax is valid 
               		return true; 
               		}else{	alert("Enter a valid Email");
				return false;
               			}
        }else{
                alert("Enter a valid freind Email");
                return false; 
        }
}

function WriteReview(cid){
	window.open("Reviewing.php?cid=" + cid, "writereview", "status=no,toolbar=no,location=no,menu=no,scrollbars=0,top=100,left=100,width=395,height=295");
}

function RateLocale(cid){
	window.open("ratingSubmit.php?cid=" + cid, "ratelocale", "status=no,toolbar=no,location=no,menu=no,scrollbars=0,top=100,left=100,width=395,height=175");
}

function ReadReviews(cid){
	//window.open("ReadReviews.php?cid=" + cid, "writereview", "status=no,toolbar=no,location=no,menu=no,scrollbars=0,top=100,left=100,width=330,height=160");
	document.location = "Reviews.php?cid=" + cid;
}

function ShowPictures(cid, type){
  	window.open("picturegallery.php?cid=" + cid + "&type=" + type, "id", "status=no,toolbar=no,location=no,menu=no,scrollbars=0,top=100,left=100,width=395,height=275");
}

function ShowMovies(cid , type){
  	window.open("show360.php?cid=" + cid + "&type=" + type, "id", "status=no,toolbar=no,location=no,menu=yes,scrollbars=0,top=100,left=40,width=710,height=300");
}

function ShowHideSearchForms(showForm){
	searchSerialForm.style.display='none';
	searchDateForm.style.display='none';
	document.getElementById(showForm).style.display='';
}


function IsValidContactForm(NForm){
	 
        	NForm.fname.focus();
        	var str = NForm.fname.value; 
                if(str.length!=0){
                	NForm.lname.focus()
                	var str = NForm.lname.value; 
                	if(str.length!=0){
                		
                		NForm.company.focus()
                		var str = NForm.company.value; 
                		if(str.length!=0){
	                		NForm.address.focus()
					var str = NForm.address.value; 
					if(str.length!=0){
						NForm.phone.focus()
						var str = NForm.phone.value;
						if(str.length!=0){
							NForm.email.focus()
							var str = NForm.email.value; 
		        				var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
		       	 				var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
		        				if (!reg1.test(str) && reg2.test(str)) { 
								NForm.message.focus()
								var str = NForm.message.value; 
								if(str.length!=0){
		                					return true;
								}
								else{
									alert("Enter Comment");
									return false;
								}
							}
							else{
								alert("Enter a valid Email Address");
								return false;
							}
						}else{
							alert("Enter your phone number");
							return false;
						}
					}
					else{
						alert("Enter your Address");
						return false;
					}
                		}else{
                			alert("Enter your company name");
					return false;
                		}
                	}
        		else{
        			alert("Enter your Last Name");
        			return false;
        		}
                }
        	else{
        		alert("Enter your First Name");
        		return false;
        	} 
}



function IsValidAdvertForm(NForm){
	 	NForm.fname.focus();
        	var str = NForm.fname.value; 
                if(str.length!=0){
                	NForm.company.focus()
                	var str = NForm.company.value; 
                	if(str.length!=0){
	                	NForm.phone.focus()
				var str = NForm.phone.value;
				if(str.length!=0){
					NForm.email.focus()
					var str = NForm.email.value; 
		        		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
		       	 		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
		        		if (!reg1.test(str) && reg2.test(str)) { 
						NForm.message.focus()
						var str = NForm.message.value; 
						if(str.length!=0){
		                			return true;
						}
						else{
							alert("Enter Comment");
							return false;
						}
					}
					else{
						alert("Enter a valid Email Address");
						return false;
						}
					}else{
						alert("Enter your phone number");
						return false;
					}
					
                		}else{
                			alert("Enter your company name");
					return false;
                		}
                	
                }
        	else{
        		alert("Enter your Name");
        		return false;
        	} 
}


function IsValidEmail(NForm){
        NForm.email.focus();
        var str = NForm.email.value; 
        var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
        var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 
        if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
                return true; 
        }else{ 
                alert("Enter a valid Email Address");
                return false; 
        } 
}



function validate_confirm_form(NForm){
	if(!NForm.f_name.value.trim()){
		NForm.f_name.focus();
		alert("Please enter your first name!");
		return false;
	}
	if(!NForm.l_name.value.trim()){
		NForm.l_name.focus();
		alert("Please enter your last name!");
		return false;
	}
	if(!NForm.phone.value.trim() || (isNaN(NForm.phone.value)) || (NForm.phone.value.trim().length<6)){
		NForm.phone.focus();
		alert("Please enter your phone number!");
		return false;
	}
	if(!NForm.mobile.value.trim() || (isNaN(NForm.mobile.value)) || (NForm.mobile.value.trim().length<6)){
		NForm.mobile.focus();
		alert("Please enter your mobile number!");
		return false;
	}
	if(!(IsValidEmail(NForm))){
		return false;
	}
	if(!NForm.b_add.value.trim()){
		NForm.b_add.focus();
		alert("Please enter your billing address!");
		return false;
	}
	if(!NForm.d_add.value.trim()){
		NForm.d_add.focus();
		alert("Please enter your delivery address!");
		return false;
	}
	if(!NForm.city.value.trim() && NForm.country.value!=102){
		NForm.city.focus();
		alert("Please enter your city!");
		return false;
	}
	if(!NForm.zip.value.trim()){
		NForm.zip.focus();
		alert("Please enter your zip/postal code!");
		return false;
	}
	if(NForm.country.value==''){
		NForm.country.focus();
		alert("Please select a Country!");
		return false;
	}
	if(NForm.country.value!=102 && NForm.pay_type.value!="Online"){
		NForm.pay_type.focus();
		alert("Only ONLINE PAYMENT method is available for overseas orders.\n You selected Upon Delivery");
		return false;
	}
	if(NForm.country.value==102 && NForm.cityid.value==''){
		NForm.cityid.focus();
		alert("Since you selected Lebanon, you need to select a City.");
		return false;
	}
	if(NForm.country.value==189 && NForm.state.value==1){
		NForm.state.focus();
		alert("Since you selected United States, you need to select a State.");
		return false;
	}
	return true;
}


function handler(e){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if (key == 110)
		return false;
	if ((key > 36 && key < 41) || key == 9 || key == 8 || key == 13 || key == 46 || (key > 47 && key < 58) || (key > 95 && key < 106))
		return true; 
	else
		return false;
}

function noRating(){
alert("You have to be a registered user to perform this process. Please register, login and try again.");
return false;	
}
function display_showhide(id,id2){
		var target = document.getElementById(id);
		var target2 = document.getElementById(id2);
		target.style.display = 'none';
		target2.style.display = '';
	}

function showsubform(id,id2,id3,id4,id5){
	var target = document.getElementById(id);
	var target2 = document.getElementById(id2);
	var target3 = document.getElementById(id3);
	var target4 = document.getElementById(id4);
	var target5 = document.getElementById(id5);
	target.style.display = '';
	if(target2.checked==true){
		target3.value=target2.value;
		target5.innerHTML = target3.value;
	}
	if(target4.checked==true){
		target3.value=target4.value;
		target5.innerHTML = target3.value;
	}
	return false;
}

function  validateSearchWULForm(NForm){
	if (NForm.textsearch.value.length == ""){
		NForm.textsearch.focus();
		alert("Enter a search Criteria")
		return false;	
	}
	
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addBookmark(title,url) {
	if (window.sidebar) { 
			window.sidebar.addPanel(title, url,""); 
		} else if( document.all ) {
			window.external.AddFavorite( url, title);
		} else if( window.opera && window.print ) {
	return true;
	}
}

function resendEmail(NForm){
	if (NForm.email.value.length == ""){
		NForm.email.focus();
		alert("Enter an Email")
		return false;	
	}
	return IsValidEmail(NForm);
}

function validtechangePassword(NForm){
	if (NForm.oldPass.value.length == ""){
		NForm.oldPass.focus();
		alert("Enter old password")
		return false;	
	}
	if (NForm.newPass.value.length == ""||NForm.newPass.value.length<6){
		NForm.newPass.focus();
		alert("New Password must be more than 6 characters!")
		return false;	
	}
	if (NForm.confirmPass.value.length == ""){
		NForm.confirmPass.focus();
		alert("Confirm Password must be more than 6 characters!")
		return false;	
	}
	if (NForm.newPass.value != NForm.confirmPass.value){
		NForm.newPass.focus();
		NForm.newPass.value = "";
		NForm.confirmPass.value = "";
		alert("Please ensure that the password and confirmation match exactly")
		return false;	
	}
}


function display_hide_vtable(id,id2,id3,id4){
	var target = document.getElementById(id);
	var target2 = document.getElementById(id2);
	var target3 = document.getElementById(id3);
	var target4 = document.getElementById(id4);
	target.style.display = 'none';
	target3.style.display = 'none';
	target2.style.display = '';
	target4.style.display = '';
}


function validateonlinepoll(count){
	for(var i=0;i<count;i++){
		if(document.poll_form.answerid[i].checked==true){
			return true;
		}
	}
	//alert("You must select at least an answer!");
	return false;
}


function validation_lebshipment(id,id1){
	var target = document.getElementById(id);
	var target1 = document.getElementById(id1);
	var target2 = document.getElementById(id1+'_sel');
	var target3 = document.getElementById(id1+'1');
	var target4 = document.getElementById(id1+'2');

	if(target.value==102){
		target1.style.display = '';
		target2.disabled = false;
		target3.disabled = true;
		target4.style.display = 'none';
		

	}else{
		target1.style.display = 'none';
		target2.disabled = true;
		target3.disabled = false;
		target4.style.display = '';

	}
}
function checkLoginRemember() 
{ 
        var check = getCookies("Application_Name_Login_Remember"); 
        if ((check==null) || (check==0)){ 
                return false; 
        }else{ 
                return true; 
        } 
} 
/*function getCookie(NameOfCookie){ 
        if(document.cookie.length > 0){ 
                begin = document.cookie.indexOf(NameOfCookie+"="); 
                if(begin != -1){ 
                        begin += NameOfCookie.length+1; 
                        end = document.cookie.indexOf(";", begin); 
                        if (end == -1) end = document.cookie.length; 
                        return unescape(document.cookie.substring(begin, end)); 
                } 
        } 
        return null; 
}*/
 
/*function setCookie(NameOfCookie, value, expiredays) 
{
        var ExpireDate = new Date(); 
        ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); 
 
        document.cookie = NameOfCookie + "=" + escape(value) + 
                ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
} 
 */

function delCookie(NameOfCookie) 
{ 
 if(getCookie(NameOfCookie)){ 
  document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
 } 
}