function ContactUsRedirect(errMsg){
 
	e=document.URL;
	r=e.split('Lang=');
	lang=r[1].split('&');
	lang=lang[0];
	flag = 0;
	Name =document.getElementById('name').value;
	Address =document.getElementById('address').value;
	Phone =document.getElementById('phone').value;
	Mobile =document.getElementById('mobile').value;
	Email =document.getElementById('email').value;
	Comment =document.getElementById('comment').value;

	if(Name==''){
		document.getElementById("nameCell").innerHTML="<font color ='red' size='4pt'>*</font>";
		flag=1;
	}
	else
		document.getElementById("nameCell").innerHTML="";	
	if(Phone==''){
		document.getElementById("phoneCell").innerHTML="<font color ='red' size='4pt'>*</font>";
		flag=1;
	}
		else
			document.getElementById("phoneCell").innerHTML="";
	if(Email=='' ){
		document.getElementById("emailCell").innerHTML="<font color ='red' size='4pt'>*</font>";
		flag=1;
	}
	else
		document.getElementById("emailCell").innerHTML="";
	if(Comment==''){
		document.getElementById("commentCell").innerHTML="<font color ='red' size='4pt'>*</font>";
		flag=1;
	}
	else
		document.getElementById("commentCell").innerHTML="";

	if(Name !='' && Email !='' && Comment!='' && Phone!='' ){
		if(Validate_Email_Address(Email)){
				flag=0;
				document.getElementById("emailCell").innerHTML="";
		}else
			document.getElementById("emailCell").innerHTML="<font color ='red' size='4pt'>*</font>";
	}
if(flag==1)
	alert(errMsg);
else
	window.location.href ="Controller/operation.SendMail.php?name="+Name+"&phone="+Phone+"&mobile="+Mobile+"&address="+Address+"&email="+Email+"&comment="+Comment+"&Lang="+lang;

	
}


function redirect(){


var email=document.getElementById('newsletter').value;

if(Validate_Email_Address(email))
	window.location.href ="Controller/operation.Add.php?Target=email&Value="+ email;
	

}
function Validate_String(string, return_invalid_chars) {
	  valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	  invalid_chars = '';
	  if(string == null || string == '')
	     return(true);

	  //For every character on the string.   
	  for(index = 0; index < string.length; index++) {
	    char = string.substr(index, 1);                        
	     
	    //Is it a valid character?
	    if(valid_chars.indexOf(char) == -1) {
	      //If not, is it already on the list of invalid characters?
	      if(invalid_chars.indexOf(char) == -1) {
	        //If it's not, add it.
	        if(invalid_chars == '')
	          invalid_chars += char;
	        else
	          invalid_chars += ', ' + char;
	      }
	    }
	  }
	            
	  //If the string does not contain invalid characters, the function will return true.
	  //If it does, it will either return false or a list of the invalid characters used
	  //in the string, depending on the value of the second parameter.
	  if(return_invalid_chars == true && invalid_chars != '') {
	    last_comma = invalid_chars.lastIndexOf(',');
	    if(last_comma != -1)
	      invalid_chars = invalid_chars.substr(0, $last_comma) + 
	      ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
	    return(invalid_chars);
	    }
	  else
	    return(invalid_chars == ''); 
	}


function Validate_Email_Address(email_address){
  
  at = email_address.indexOf('@');
  dot = email_address.indexOf('.');

  if(at == -1 || 
    dot == -1 || 
 
    dot == 0 || 
    dot == email_address.length - 1)
  {
  	alert("Invalid email");
    return(false);
  }
     
  user_name = email_address.substr(0, at);
  domain_name = email_address.substr(at + 1, email_address.length);                  

  if(Validate_String(user_name) === false || Validate_String(domain_name) === false)
  {
  	alert("Invalid email");
    return(false);
  }

  //alert("Valid email");//
  return(true);
}

function Searchredirect(key){

var w=window.location.href;
w=w.split("?Lang=" ,2);

//	var email=document.getElementById('newsletter').value;

	//if(Validate_Email_Address(email))
	//	window.location.href ="Controller/operation.Add.php?Target=email&Value="+ email;
		//undefined
		if(key != ""){
			if(w[1]=="en" || w[1]=="ar"){//since the defualt not specify any language
				lang =w[1];
				
				window.location.href ="index.php?Lang="+lang +"&search="+ key;
			}
			else{
				window.location.href ="index.php?search="+ key;
			}
		}

	}

function Langredirect(Lang){
	

			if(Lang == "en"){
				
				
					window.location.href ="index.php?Lang=en";
				}
				else{
					
					window.location.href ="index.php?Lang=ar";
				}
			
	
}