// JavaScript Document
function isValidEmail(strEmail) {
	
	var msg;
	var i;
	var len=strEmail.length;
	if(strEmail=="") {
			msg="";
	} else {
		if((strEmail.charAt(0)=="@") || (strEmail.charAt(0)==".")) {
			msg="Invalid Email Address.";
		} else {
	//	checking the number of the @ and dots in the email add	
			var countAt=0;
			var countDot=0;
			for (i=0; i<len; i++) {
				if(strEmail.charAt(i)=="@") {
					countAt=countAt+1;
				}	
				if(strEmail.charAt(i)==".") {
					countDot=countDot+1;
				}
			} //end of for (i=0; i<strEmail.length; i++) {...	
			if((countAt!=1) || (countDot<1)) {
				msg="Invalid Email Address.";
			} else {
		//	checking the position of the @ with respect to the dot 
				var posDot=0;
				var posAt=0;
				posDot=strEmail.lastIndexOf(".");
				posAt=strEmail.indexOf("@");
				if((posAt>posDot) || (posDot==(posAt+1))) {
					msg="Invalid Email Address.";
				} else {
			//	checking the dot position and the @ postion at the end
					if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {
						msg="Invalid Email Address.";
					} else {
						/* 	checking for the invalid characters
						 if(ereg('[^A-Za-z0-9_]', strEmail)) {
					msg="Only letters, numbers and underscores(_).";		*/
						msg = "";
					} //end of if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {...
				} //end of if((posAt>posDot) || (posDot==(posDot+1))) {...
			} //end of if((countAt!=1) ||(countDot<1)) {...		
		} //end  if((strEmail.charAt(i)=="@") || (strEmail.charAt(i)==".")) {...
	} //end of if(strEmail=="") {...
	return msg;	
}//end function	

function GoLiveWindow()
{
	var liveWin = window.open("GoLive.php"); /*,"","width=549,height=629"*/
}

function ChatWindow(user,app)
{
	var getElement = "?username="+user+"&appInstance="+app;
	var chatWin = window.open("http://zonechill.com/newzonechill/Chat/ZCmulti.html"+getElement,"","width=575,height=675");
}

function SelectedTab(selectedId,unselectedId)
{
	var imagepath="images/new_images";
	switch(selectedId)
	{
			case 'msg_tab':
				image="messages_tab_hover.gif";
				color="#008099";
				break;			
			case 'stats_tab':
				image="stats_tab_hover.gif";
				color="#008099";				
				break;
			case 'friends_tab':
				image="tab_friends_hover.gif";
				color="#008099";
				break;
			case 'birthday_tab':
				image="tab_birthday_hover.gif";
				color="#008099";
				break;
			case 'updates_tab':
				image="tab_updates_hover.gif";
				color="#008099";
				break;
	}	
	document.getElementById(selectedId).style.backgroundImage="url("+imagepath+"/"+image+")";
	document.getElementById(selectedId).style.color=color;
	var unselected=unselectedId.split(",");
	for(i=0;i<unselected.length;i++)
	{
		switch(unselected[i])
		{
			case 'msg_tab':
				image="messages_tab_normal.gif";
				color="#FFFFFF";
				break;			
			case 'stats_tab':
				image="stats_tab_normal.gif";
				color="#FFFFFF";
				break;
			case 'friends_tab':
				image="tab_friends_normal.gif";
				color="#FFFFFF";
				break;
			case 'birthday_tab':
				image="tab_birthday_normal.gif";
				color="#FFFFFF";
				break;
			case 'updates_tab':
				image="tab_updates_normal.gif";
				color="#FFFFFF";
				break;
		}
		document.getElementById(unselected[i]).style.backgroundImage="url("+imagepath+"/"+image+")";
		document.getElementById(unselected[i]).style.color=color;
	}
}

function checkUncheckAll(theElement)
{	var theForm = theElement.form, z = 0;
	
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{
			theForm[z].checked = theElement.checked;
		}
	}	
}

function checkUncheckThroughLink(theElement)
{
	
	if(document.getElementById(theElement).checked==false)
	{
		document.getElementById(theElement).checked=true;
		checkUncheckAll(document.getElementById(theElement));
		
	}
	else
	{
		document.getElementById(theElement).checked=false;
		checkUncheckAll(document.getElementById(theElement));
		
	}	
}

function show_hide(showId,hideId,checkAuth)
{
	if(checkAuth=="1")
	{
	document.getElementById(showId).style.display="";
	document.getElementById(hideId).style.display="none";
	}
	else
	{
		if(checkAuth!=null)
			alert("You don't have enough privilege");			
	}
}

function startmsg()
{	
	document.getElementById('searchlist').innerHTML='Start typing a name';
	document.getElementById('searchlist').style.display='';	
}

function list_friend()
{
	searchFriend(document.getElementById('to').value);
	document.getElementById('searchlist').style.display='';
}

function append_name(hideId,aptext,apimage,apid)
{
	document.getElementById(hideId).style.display="none";
	document.getElementById('searchlist').style.display="none";
	document.getElementById('showName').innerHTML="<table width='100%'><tr><td width='27'><img src='phpthumb/phpthumb.php?src=../"
												  +document.getElementById(apimage).value+"&w=80&h=80&aoe=1'></td>"
												  +"<td>"+document.getElementById(aptext).value+"</td>"
												  +"<td valign='top' width='15'>"
												  +"<a href='javascript:;' onclick=\"show_hide('to','showName')\">"
												  +"<img src='images/icons/no.gif' border='0'></a></td></tr></table>";
	document.getElementById('showName').style.display="";
	document.getElementById('toId').value=document.getElementById(apid).value;	
}

/*Admin Section*/
function SelectedTabAdmin(selectedId,unselectedId)
{
	var imagepath="../images/new_images";
	switch(selectedId)
	{
			case 'msg_tab':
				image="messages_tab_hover.gif";
				color="#008099";
				break;			
			case 'stats_tab':
				image="stats_tab_hover.gif";
				color="#008099";				
				break;
			case 'friends_tab':
				image="tab_friends_hover.gif";
				color="#008099";
				break;
			case 'birthday_tab':
				image="tab_birthday_hover.gif";
				color="#008099";
				break;
			case 'updates_tab':
				image="tab_updates_hover.gif";
				color="#008099";
				break;
	}	
	document.getElementById(selectedId).style.backgroundImage="url("+imagepath+"/"+image+")";
	document.getElementById(selectedId).style.color=color;
	var unselected=unselectedId.split(",");
	for(i=0;i<unselected.length;i++)
	{
		switch(unselected[i])
		{
			case 'msg_tab':
				image="messages_tab_normal.gif";
				color="#FFFFFF";
				break;			
			case 'stats_tab':
				image="stats_tab_normal.gif";
				color="#FFFFFF";
				break;
			case 'friends_tab':
				image="tab_friends_normal.gif";
				color="#FFFFFF";
				break;
			case 'birthday_tab':
				image="tab_birthday_normal.gif";
				color="#FFFFFF";
				break;
			case 'updates_tab':
				image="tab_updates_normal.gif";
				color="#FFFFFF";
				break;
		}
		document.getElementById(unselected[i]).style.backgroundImage="url("+imagepath+"/"+image+")";
		document.getElementById(unselected[i]).style.color=color;
	}
}