
function echeck(str) {
		var at="@"
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Invalid email address")
		    return false
		 }

 		 return true					
	}

function validateForm(){
	var emailID=document.getElementById('formEmail');
	var nameID=document.getElementById('formName');
	var topicID=document.getElementById('formTopic');
	var commID=document.getElementById('formComment');
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please enter your name")
		nameID.focus()
		return false
	}
	if ((topicID.value==null)||(topicID.value=="")){
		alert("Please enter a topic")
		topicID.focus()
		return false
	}
	
	if ((commID.value==null)||(commID.value=="")){
		alert("Please enter a comment")
		commID.focus()
		return false
	}
	var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	var myPage="processForm.php";
	request.open("POST", myPage, true);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	request.onreadystatechange = function(){
		if (request.readyState == 4 && request.status == 200) {
			document.getElementById("contactFormDiv").style.display="none";
			document.getElementById("contactFormThanks").style.display="block";
		}
	};
	request.send("name="+encodeURIComponent(nameID.value)+"&email="+encodeURIComponent(emailID.value)+"&topic="+encodeURIComponent(topicID.value)+"&comment="+encodeURIComponent(commID.value));
 }

function showForm(){
	var emailID=document.getElementById('formEmail');
	var nameID=document.getElementById('formName');
	var topicID=document.getElementById('formTopic');
	var commID=document.getElementById('formComment');
	emailID.value='';
	nameID.value='';
	topicID.value='';
	commID.value='';
	document.getElementById("contactFormDiv").style.display="block";
	document.getElementById("contactFormThanks").style.display="none";	
}


var divContent=new Array();
divContent['time']=new Array();
divContent['source']=new Array();
divContent['country']=new Array();
divContent['feed']=new Array();
divContent['category']=new Array();


function sortByHits(a, b) {
    var x = parseInt(a[1]);
    var y = parseInt(b[1]);
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
	//return b-a;
}
function sortByItems(a, b) {
    var x = a[0].toUpperCase();
    var y = b[0].toUpperCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
