
var userlocation = new Array();
var lessoncount;

function countAreaChars(areaName,counter,limit)
{
if (areaName.value.length>limit)
areaName.value=areaName.value.substring(0,limit);
else
counter.value = limit - areaName.value.length;
}

function chk_loginpage(){
	if(document.getElementById("loginname").value == "" || document.getElementById("loginpwd").value == ""){
		showmsg("alertmsg","Please fill in Login Name or Password.");
	}else{
		return true;
	}
	return false;
}

function chk_contribute(){
	
	if(document.getElementById("lessontopic").value == ""){
		
		alert("Please fill in a Topic for your lesson.");
		
	}else if(document.getElementById("lessonabstract").value == ""){
		alert("Please fill in a snapshot for your lesson.");
	}else{
		return true;
	}
	
	return false;
	
}

function showalert_register(){
	$userlogin = getCookie("userlogin");
	if($userlogin != ""){
		var user_response = window.confirm("The registration procedures will automatically log you off from our system, do you want to continue?");
		if (user_response == true){
			window.location = "register.php";
		}else{
			return false;
		}
	}else{
		window.location = "register.php";
	}
}

function chk_weekly(){
	if(document.getElementById("weeklyemail").value == ""){
		showmsg("alertmsg","Please kindly enter a valid email address.");
	}else if(document.getElementById("weeklyemail").value.indexOf("@",0) == -1 || document.getElementById("weeklyemail").value.indexOf(".",0) == -1){
		showmsg("alertmsg","The email address you entered does not seem to be a valid one.");
	}else{
		return true;
	}
	return false;
}

function chksearch(from){
	if(document.getElementById("searchword"+from).value == ""){
		
		showmsg("alertmsg"+from,"No keyword entered.");
	}else{
		if(from == "top"){
			document.getElementById("searchwordlow").value == "";
		}else{
			document.getElementById("searchwordtop").value == "";
		}
		return true;
	}
	
	return false;
}

function callcountry(){
	
	xmlhttp2=GetXmlHttpObject();
		if (xmlhttp2==null)
		  {
		  alert ("Browser does not support HTTP Request");
		  return;
		  }

		var url2="randcountry.php";
		
		//url=url+"&sid="+Math.random();
		xmlhttp2.onreadystatechange=stateChangedcountry;
		xmlhttp2.open("GET",url2,true);
		xmlhttp2.send(null);
		
}


function stateChangedcountry()
	{
		if (xmlhttp2.readyState==4)
			  {
			  xmlDoc2=xmlhttp2.responseXML;
			  
			  
			  
	      userlocation[0] = xmlDoc2.getElementsByTagName("userlocation")[0].childNodes[0].nodeValue;
	      userlocation[1] = xmlDoc2.getElementsByTagName("userlocation")[1].childNodes[0].nodeValue;
	      userlocation[2] = xmlDoc2.getElementsByTagName("userlocation")[2].childNodes[0].nodeValue;
	      userlocation[3] = xmlDoc2.getElementsByTagName("userlocation")[3].childNodes[0].nodeValue;
	      userlocation[4] = xmlDoc2.getElementsByTagName("userlocation")[4].childNodes[0].nodeValue;
	      userlocation[5] = xmlDoc2.getElementsByTagName("userlocation")[5].childNodes[0].nodeValue;
	      //userlocation[6] = xmlDoc2.getElementsByTagName("userlocation")[6].childNodes[0].nodeValue;
	      //userlocation[7] = xmlDoc2.getElementsByTagName("userlocation")[7].childNodes[0].nodeValue;
	      //userlocation[8] = xmlDoc2.getElementsByTagName("userlocation")[8].childNodes[0].nodeValue;
	      //userlocation[9] = xmlDoc2.getElementsByTagName("userlocation")[9].childNodes[0].nodeValue;
	      //userlocation[10] = xmlDoc2.getElementsByTagName("userlocation")[10].childNodes[0].nodeValue;
	      //userlocation[11] = xmlDoc2.getElementsByTagName("userlocation")[11].childNodes[0].nodeValue;
	      //userlocation[12] = xmlDoc2.getElementsByTagName("userlocation")[12].childNodes[0].nodeValue;
	      //userlocation[13] = xmlDoc2.getElementsByTagName("userlocation")[13].childNodes[0].nodeValue;
	      //userlocation[14] = xmlDoc2.getElementsByTagName("userlocation")[14].childNodes[0].nodeValue;
	      //userlocation[15] = xmlDoc2.getElementsByTagName("userlocation")[15].childNodes[0].nodeValue;
			  
			  lessoncount = xmlDoc2.getElementsByTagName("lessoncount")[0].childNodes[0].nodeValue;
			  document.getElementById("lessoncount").innerHTML = lessoncount;
			  chgcountry();
			  }
	}

function chgcountry(){
	
	var locid = Math.floor(Math.random()*6);
	document.getElementById("userlocationtop").innerHTML = userlocation[locid];
	
	opacity("userlocationtop", 0, 100, 500)
	t=setTimeout("chgcountry()",2000);
}
var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
//alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
//alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")


function hideerror(){
	
	document.getElementById("loginalertwrapper").style.visibility = "hidden";
	document.getElementById("loginnamewrapper").style.visibility = "visible";
	document.getElementById("passwordwrapper").style.visibility = "visible";
}

function showerror(){
	
	document.getElementById("loginalertwrapper").style.visibility = "visible";
	document.getElementById("loginnamewrapper").style.visibility = "hidden";
	document.getElementById("passwordwrapper").style.visibility = "hidden";
	document.getElementById("loginname").focus();
}

function chkrate(){
	
	if(!document.getElementById("ratings[1]").checked && !document.getElementById("ratings[2]").checked && !document.getElementById("ratings[3]").checked && !document.getElementById("ratings[4]").checked){
		
		alert("Please choose a rating.");
		
	}else{
		
		return true;
		
	}
	
	return false;
	
}

function chkcomment(){
	
	var commentcontent = CKEDITOR.instances.commentcontent.getData();
	commentcontent = commentcontent.replace("<br />", "");
	commentcontent = commentcontent.replace("<p>", "");
	commentcontent = commentcontent.replace(" ", "");
	
	if(commentcontent.length < 3){
		
		alert("Please fill in your comment.");
		
	}else{
		
		return true;
		
	}
	
	return false;
	
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function showsmallerror(){
	
	alert("Your photo does not meet the minmium size requirment.");
	
}

function showimageerror(){
	
	alert("Your photo does not meet the image type requirment.");
	
}

function showcmykerror(){
	
	alert("Your photo does not meet the image type requirment(CMYK Image is not supported).");
	
}

function showvote(){
	
			
		alert("Thanks for your vote!");
		
}

function showcomment(){
	
			
		alert("Thanks for your comment!");
		
}

function showremovecomment(){
	
			
		alert("Your comment has been removed!");
		
}


function showmsg(id, msg){
	targetobj = document.getElementById(id);
	opacity(id,0,100,300);
	targetobj.innerHTML = msg;
 
}

function clearmsg(id){
	targetobj = document.getElementById(id);
	opacity(id,100,0,300);
	setTimeout("nullmsg('"+ id +"')" ,300);
}

function nullmsg(id){
	targetobj = document.getElementById(id);
	targetobj.innerHTML = "";
}


function mouseovereffect(buttonname){
	document.getElementById(buttonname).className=buttonname;
}

function mouseouteffect(buttonname){
	document.getElementById(buttonname).className="reset";
}




function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function GetXmlHttpObject()
	{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
	}
