function logout(location)
{

var answer = confirm("هل تريد بالتأكيد الخروج | Are You sure Logout?");

	if (answer){
		alert("Bye bye! الي اللقاء")
		window.location = location;
	}

}
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}





function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function Reload(elm) {
var f = document.getElementById(elm);
f.src = f.src;
}

function sendRequest(elem_input)
  {
    handle = $(elem_input).value;
    var url = 'inc/validate.php?';

        var fullurl = url + 'do=CheckUserName&user=' + handle;

  var ajaxReq = new Ajax.Request(fullurl, { method: 'get',onSuccess: Response});
  }
  function Response(transport)
  {

  var response = transport.responseText;
  document.getElementById('username_exists').innerHTML = response;
       // setTimeout(countPosts,5000);
  }


function checkLogin(){
if (document.theForm.meuser.value == "") {
alert("الرجاء التأكد من إدخال الإسم");
document.theForm.meuser.focus();
return false;
}else if (document.theForm.password.value == "") {
alert("الرجاء التأكد من إدخال كلمة السر");
document.theForm.password.focus();
return false;
}else if(document.theForm.meuser.value.length > 32) {
window.alert("اسم الدخول يجب أن يكون أقل من 32 حرف");
document.theForm.meuser.focus();
return false;
}else {
if(document.theForm.remember_me.checked==true){
SetCookie('remember_remember','1', 10);
}else{
SetCookie('remember_remember','0', 10);
}
document.theForm.submit();
}
}


function addflvPlayer(swfPath,param){
with (document) {

writeln('	<object   classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="283" height="190" id="flvplayer" align="middle">');
writeln('<param name="allowScriptAccess" value="sameDomain" />');
writeln('<param name="movie" value="'+swfPath+'?'+param+'" />');
writeln('<param name="quality" value="high" />');
writeln('<param name="wmode" value="transparent" />');
writeln('<param name="devicefont" value="true" />');
writeln('<param name="bgcolor" value="#ffffff" />');
writeln('<embed src="'+swfPath+'?'+param+'" quality="high" wmode="transparent" devicefont="true" bgcolor="#ffffff" width="283" height="190" name="flvplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
writeln('<\/object>');
writeln('<!-- -->');

}
}
function newWindow(mypage,myname,w,h,features)
{
  if(screen.width)
  {
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
  }
  else
  {
    winl = 0;wint =0;
  }
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}

function Layers(X)
{
 if(document.getElementById(X).style.display == 'none')
 {
   document.getElementById(X).style.display = ''
 }
 else
 {
   document.getElementById(X).style.display = 'none'
 }
}

function Tmail(obj) {
    var atpos = obj.indexOf('@');
    if(atpos == -1)
    {
		return false;
	 }
	if(atpos == 0) {
		return false;
	}
	var dotpos = obj.indexOf('.', atpos+2);
	if( dotpos == -1) {
		return false;
	}
	if(dotpos == (obj.length - 1) ) {
		return false;
	}
	return true;
}

function TF(murl)
{
   handlet = $('to').value;
   handlef = $('from').value;
   handlem = $('msg').value;
   handlec = $('cat').value;
   handlei = $('id').value;

   var url = murl + 'mod/tell.php?to=' + handlet + '&from=' + handlef + '&msg=' + handlem + '&cat=' + handlec + '&id=' + handlei  ;
   if(handlet=="")
   {
    document.getElementById('tellstate').innerHTML = 'برجاء كتابه البريد بشكل صحيح';
    $('to').focus();
     return false;
   }
   if(handlef=="")
   {
    document.getElementById('tellstate').innerHTML = 'برجاء كتابه البريد بشكل صحيح';
    $('from').focus();
     return false;
   }
   if(!Tmail(handlet))
    {
     document.getElementById('tellstate').innerHTML = 'برجاء كتابه البريد بشكل صحيح';
     $('to').focus();
     return false;
    }
    if(!Tmail(handlef))
    {
     document.getElementById('tellstate').innerHTML = 'برجاء كتابه البريد بشكل صحيح';
     $('from').focus();
     return false;
    }
    if(handlem=="")
   {
    document.getElementById('tellstate').innerHTML = 'يرجى كتابه موضوع للرساله';
    $('msg').focus();
     return false;
   }
   var ajaxReq = new Ajax.Request(url, { method: 'get',onSuccess: Response});


}

function SendRequest(elm)
{
  handle = $(elm).value;
  var url = 'index.php?do=validation&user=' + handle ;
   var ajaxReq = new Ajax.Request(url, { method: 'get',onSuccess: Response});
}

  function Response(transport)
  {

  var response = transport.responseText;
  document.getElementById('username_exists').innerHTML = response;
       // setTimeout(countPosts,5000);
  }



