	 function valid(str) {
        for(var i = 0; i < str.length; i++) {
            var charcode = str.charCodeAt(i);

            /* A-Z */
            if(charcode >= 0x41 && charcode <= 0x5A) {
                continue;
            }               
            /* a-z */
            if(charcode >= 0x61 && charcode <= 0x7A) {
                continue;
            }   
            /* 0-9 */
            if(charcode >= 0x30 && charcode <= 0x39) {
                continue;
            }               
            /* . - _ 32*/
            if(charcode == 0x2D || charcode == 0x2E || charcode == 0x5F  ) {
                continue;
            }
               
            return false;
        }//end for(var i = 0; i < str.length; i++)

        return true;

    }//end function valid
	
	function testemail(obj) {
        var atpos = obj.value.indexOf("@");
            if(atpos == -1) {
                return false;
            }

            if(atpos == 0) {
                return false;
            }

            var dotpos = obj.value.indexOf('.', atpos+2);

            if( dotpos == -1) {
                return false;
            }
               
            if(dotpos == (obj.value.length - 1) ) {
               return false;
            }
               
            if(obj.value.indexOf(".") == 0){
                return false;
            }
               
            if( obj.value.indexOf("@")  == (obj.value.indexOf('.', obj.value.indexOf("@")+1)) - 1 ){
                return false;
            }
                              
            if( obj.value.indexOf(".")  == (obj.value.indexOf('.', obj.value.indexOf(".")+1)) - 1 ){
	        return false;
            }
               
                             
           var fpart = obj.value.substring(0,atpos);
           var host = obj.value.substring(atpos + 1, dotpos);
           var domain = obj.value.substr(dotpos +1);

           if(!( valid(fpart) && valid(host) && valid(domain))) {
               return false;
           }
     
           var afterat = obj.value.substr(atpos + 1);
     
           if(afterat.lastIndexOf('.') == (afterat.length - 1)) {
               return false;
           }
     
           for(var i = 1; i < afterat.length; i++) {
        
     	       if(afterat.charAt(i) == '.' && afterat.charAt(i-1) == '.') {
                   return false;
               }

           }//end for(var i = 1; i < afterat.length; i++)

           return true;
                  
    }//end function testemail	

	function validateData(){
		
		if (document.comment_form.name.value.trim() == "") {
	    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء إدخال  الإسم </font>';
	 		document.comment_form.name.focus();
			return false;
		}else if (document.comment_form.email.value.trim() == "") {
	    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء إدخال  البريد الإلكتروني </font>';
	 		document.comment_form.email.focus();
			return false;
		}else if (!testemail(document.comment_form.email) ){
           document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء التأكدّ من  البريد الإلكتروني </font>';
            document.comment_form.email.focus();
            return false;
		}else if (document.comment_form.comment.value.trim() == "") {
	    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء كتابة الموضوع المقترح</font>';
	 		document.comment_form.comment.focus();
			return false;
		}else{
			return true
		}
	}//end function
	
	
	
function addsuggestions(){
	if(validateData())
	{
		document.comment_form.submit();
	}

}
function validatenewspaperData()
{
	document.getElementById('error').innerHTML='';
	if (document.comment_form.name.value.trim() == "") {
    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء إدخال  اسم الجريدة  </font>';
 		document.comment_form.name.focus();
		return false;
	}else if(document.comment_form.SelectPrimary.selectedIndex==0)
	{
		document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء إختيار الدولة </font>';
 		document.comment_form.SelectPrimary.focus();
		return false;
	}
	else  if (document.comment_form.url.value.trim() == "" || document.comment_form.url.value.trim() == "http://") {
    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء إدخال  رابط الجريدة  </font>';
 		document.comment_form.url.focus();
		return false;
	}else if (!checkURL(document.comment_form.url.value)) {
    	document.getElementById('error').innerHTML='<font color="#FF0000">الرجاء التأكدّ من  رابط الجريدة  </font>';
 		document.comment_form.url.focus();
		return false;
	}
	return true;
}
function newspaperadd(){
	if(validatenewspaperData())
	{
	
		var i = document.comment_form.SelectPrimary.selectedIndex;
	
		var url = document.comment_form.url.value.replace(/([&\//?"><+])/g,Capitalize);
		AJAXGet(base_url+"addnewspaper.php?name="+document.comment_form.name.value+"&contry="+i+"&url="+url+"&desc="+document.comment_form.desc.value,viewResult,false,false);
		document.getElementById('buttonDIV').style.display="none";
		document.getElementById('imageDIV').style.display="block";
		document.comment_form.name.value = "";
		document.comment_form.SelectPrimary.selectedIndex = 0;
		document.comment_form.desc.value='';
		document.comment_form.url.value = "http://";
		
	}

}
function viewResult(sText)
{
	document.getElementById('buttonDIV').style.display="block";
	document.getElementById('imageDIV').style.display="none";
	document.getElementById('error').innerHTML='شكراً  لمشاركتك  '  ;
 	document.comment_form.name.focus();
}
function Capitalize(orig,re1){
var result;
	if(re1 == "&")
	{
		result = "(amp)"
	}else if(re1 == "/"){
		result = "(xx)"
	}else if(re1 == "?"){
		result = "(p)"
	}else if(re1 == "\""){
		result = "(quot)"
	}else if(re1 == "<"){
		result = "(lt)"
	}else if(re1 == ">"){
		result = "(gt)"
	}else if(re1 == "+"){
		result = "(pl)"
	}else if(re1 == "\\"){
		result = "(bk)"
	}
	return result;
}