﻿// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("MSXML2.XMLHTTP");
   else if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}   
function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}
function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}
function dologindo(gg){
if(document.loginf.cook.value=="no"){

} else {
if(document.loginf.rememberme.checked) {
	writeCookie('remember', '' + document.loginf.userName.value + '', 3600);
} else {
	writeCookie('remember', '', 3600);
}
}
		goSubmitl(gg);
}

function dopolldo(gg){
	if(document.pollf.voteid.value == undefined) {
		alert ('الرجاء إختيار أحد الخيارات');
	} else {
var voteidtext = document.pollf.voteid.value;
var pollidtext = document.pollf.pollid.value;
var polltext = document.pollf.poll.value;


		loaditpollj('' + gg + '?poll=' + polltext + '&pollid=' + pollidtext + '&voteid=' + voteidtext);
	}
}

function sendmail(gg){var email=document.forms["mailform"].elements["email"].value;
 var reEmail = new RegExp('^[a-z0-9\._-]+@[a-z0-9][a-z0-9_-]*(\.[a-z0-9_-]+)*'+
                         '\.([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|'+
                         'int|mil|museum|name|net|org|pro|travel)$', 'i');
	if(document.mailform.name.value == "") {
		alert ('الرجاء كتابة الإسم');
  		document.mailform.name.focus();
		return false;
		}
 if (document.mailform.email.value == "") {
  alert("الرجاء كتابة البريد الإلكتروني")
  document.mailform.email.focus()
  return false} 
    if (!reEmail.test(email))
 {
  alert('! البريد الإلكتروني غير صحيح');
  document.mailform.email.focus()
  return false;
 }
	if(document.mailform.country.value == "") {
		alert ('الرجاء إختيار البلد');
  		document.mailform.country.focus();
		return false;
		}
	if(document.mailform.subject.value == "") {
		alert ('الرجاء إختيار موضوع الرسالة');
  		document.mailform.subject.focus();
		return false;
		}
	if(document.mailform.message.value == "") {
		alert ('الرجاء كتابة الرسالة');
  		document.mailform.message.focus();
		return false;
	}
	
	
  goSubmit(gg);


}




function addcommentadd(gg){
var http = new XMLHttpRequest();
var url = "comments.php";
var tagtext = document.ForMembersComment.tag.value;
var idtext = document.ForMembersComment.id.value;
var introtext = document.ForMembersComment.intro.value;

	if(document.ForMembersComment.intro.value == "") {
  alert("!! الرجاء كتابة التعليق")
  document.ForMembersComment.intro.focus()
  return false;
	}
	
		
var params = "tag=" + tagtext + "&id=" + idtext + "&intro=" + introtext + "&addmemberComment=1";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		// document.getElementById('bodyin').innerHTML = http.responseText;
		//loadit(gg);
		loaditcomments(gg);
	}
}
http.send(params);

}

function addnewsadd(gg){
var http = new XMLHttpRequest();
var url = "reports.php";
var titletext = document.addnews.title.value;
var newstext = document.addnews.news.value;
var addtext = document.addnews.add.value;
var params = "add=" + addtext + "&title=" + titletext + "&news=" + newstext + "";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		// document.getElementById('bodyin').innerHTML = http.responseText;
		loadit(gg);
	}
}
http.send(params);
}





function goregister(gg){
var http = new XMLHttpRequest();
var url = "register.php";
var usernametext = document.FormRegister.username.value;
var Passwordtext = document.FormRegister.Password.value;
var emailtext = document.FormRegister.email.value;
var gendertext = document.FormRegister.gender.value;
var countrytext = document.FormRegister.country.value;
var srctext = document.FormRegister.src.value;

var email=document.forms["FormRegister"].elements["email"].value;
 var reEmail = new RegExp('^[a-z0-9\._-]+@[a-z0-9][a-z0-9_-]*(\.[a-z0-9_-]+)*'+
                         '\.([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|'+
                         'int|mil|museum|name|net|org|pro|travel)$', 'i');
 if (document.FormRegister.username.value == "") {
  alert("إسم العضو ؟؟")
  document.FormRegister.username.focus()
  return false}
 if (document.FormRegister.Password.value == "") {
  alert("كلمة المرور ؟؟")
  document.FormRegister.Password.focus()
  return false}
 if (document.FormRegister.Password2.value == "") {
  alert("تثبيت كلمة المرور ؟؟")
  document.FormRegister.Password2.focus()
  return false}
 if (document.FormRegister.Password2.value != document.FormRegister.Password.value) {
  alert("الرجاء التأكد من كلمة المرور ؟؟")
  document.FormRegister.Password.focus()
  return false}
 if (document.FormRegister.email.value == "") {
  alert("البريد الإلكتروني ؟؟")
  document.FormRegister.email.focus()
  return false} 
    if (!reEmail.test(email))
 {
  alert('! البريد الإلكتروني غير صحيح');
  return false;
 }
 if (document.FormRegister.gender.value == "") {
  alert("الجنس ؟؟")
  document.FormRegister.gender.focus()
  return false}
 if (document.FormRegister.country.value == "") {
  alert("البلد ؟؟")
  document.FormRegister.country.focus()
  return false}

var params = "username=" + usernametext + "&Password=" + Passwordtext + "&email=" + emailtext + "&gender=" + gendertext + "&country=" + countrytext + "&src=" + srctext + "&addfriend=1";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		 document.getElementById('bodyin').innerHTML = http.responseText;
	}
}
http.send(params);
}



function gotestiadd(gg){
var email=document.forms["FormRegister"].elements["email"].value;
 var reEmail = new RegExp('^[a-z0-9\._-]+@[a-z0-9][a-z0-9_-]*(\.[a-z0-9_-]+)*'+
                         '\.([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|'+
                         'int|mil|museum|name|net|org|pro|travel)$', 'i');
 if (document.FormRegister.name.value == "") {
  alert("الإسم ؟؟")
  document.FormRegister.name.focus()
  return false}
 if (document.FormRegister.email.value == "") {
  alert("البريد الإلكتروني ؟؟")
  document.FormRegister.email.focus()
  return false} 
    if (!reEmail.test(email))
 {
  alert('! البريد الإلكتروني غير صحيح');
  document.FormRegister.email.focus()
  return false;
 }
 if (document.FormRegister.country.value == "") {
  alert("البلد ؟؟")
  document.FormRegister.country.focus()
  return false}
 if (document.FormRegister.intro.value == "") {
  alert("المقال ؟؟")
  document.FormRegister.intro.focus()
  return false}

  goSubmit(gg);
}



function comm()
    {
	document.getElementById('comments').style.display = '';
	document.getElementById('addcomments').style.display = 'none';
    }
function addcomm()
    {
	document.getElementById('comments').style.display = 'none';
	document.getElementById('addcomments').style.display = '';
    }

function Download2(url){
oIFrm = document.getElementById('myIFrm2');
oIFrm.src = url;
}
function Download(url){
oIFrm = document.getElementById('myIFrm');
oIFrm.src = url;
bla;
}
function bla(){
document.getElementById('myIFrm').execCommand('SaveAs');
}
 function download() {
 document.getElementById('download').style.display = '';
 }


// Implement business logic
function loadit(ff){
	document.getElementById('loader').style.display = '';
	document.getElementById('bodyin').style.display = 'none';
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = function() {
		  
				if(httpObject.readyState == 2 || httpObject.readyState == 3 || httpObject.readyState == 4 ){
				
				document.getElementById('bodyin').innerHTML = httpObject.responseText;
				
				document.getElementById('bodyin').style.display = '';
				document.getElementById('loader').style.display = 'none';
				}
		}
	} else {
	gorefreshloadit(ff);
   }	   
}
var httpObject = null;


					function gorefreshloadit(ff)
						{
							
						setTimeout(gorefreshloadit2,1000);
						
								function gorefreshloadit2()
								{
								loadit(ff);
								alert('doing loading again');
								} 
						
						} 
					

function loaditcomments(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputcomments;
   }
}
var httpObject = null;


function setOutputcomments(){
   if(httpObject.readyState == 4){
      document.getElementById('commentsp').innerHTML = httpObject.responseText;
   }
}


function loaditalbumpics(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputalbumpics;
   }
}
var httpObject = null;


function setOutputalbumpics(){
   if(httpObject.readyState == 4){
      document.getElementById('albumpicsin').innerHTML = httpObject.responseText;
   }
}

function loaditpoll(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputpoll;
   }
}
var httpObject = null;


function loaditpollc(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputpollc;
   }
}
var httpObject = null;


function loaditpollj(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputpollj;
   }
}
var httpObject = null;


function setOutputpollj(){
   if(httpObject.readyState == 4 && httpObject.status == 200){
      document.getElementById('pollp').innerHTML = httpObject.responseText;
   }
}

function loaditstat2(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputstat2;
   }
}
var httpObject = null;

function loaditstat2r(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputstat2r;
   }
}
var httpObject = null;



function loaditstat2c(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputstat2c;
   }
}
var httpObject = null;

function loaditstat(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputstat;
   }
}
var httpObject = null;



function loaditstatc(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputstatc;
   }
}
var httpObject = null;



function loaditl(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputl;
   }
}
var httpObject = null;


function loaditlc(ff){
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = setOutputlc;
   }
}
var httpObject = null;


function setOutputstat(){
   if(httpObject.readyState == 4 && httpObject.status == 200){
      document.getElementById('statp').innerHTML = httpObject.responseText;
	  loaditstat2('stat2.php');
   }
}
function setOutputstatc(){
   if(httpObject.readyState == 4){
      document.getElementById('statp').innerHTML = httpObject.responseText;
	  loadit('ns.php?thread=26');
   }
}

function setOutputstat2r(){
   if(httpObject.readyState == 4 && httpObject.status == 200){
      document.getElementById('stat2p').innerHTML = httpObject.responseText;
   }
}
function setOutputstat2(){
   if(httpObject.readyState == 4 && httpObject.status == 200){
      document.getElementById('stat2p').innerHTML = httpObject.responseText;
	  loadit('bodymain.php');
   }
}
function setOutputstat2c(){
   if(httpObject.readyState == 4){
      document.getElementById('stat2p').innerHTML = httpObject.responseText;
	  loadit('ns.php?thread=24');
   }
}
function setOutputpoll(){
   if(httpObject.readyState == 4){
      document.getElementById('pollp').innerHTML = httpObject.responseText;
	  loaditstat('stat.php');
	  //loadit('bodymain.php');
   }
}
function setOutputpollc(){
   if(httpObject.readyState == 4){
      document.getElementById('pollp').innerHTML = httpObject.responseText;
	  loaditstatc('stat.php');
	  //loadit('bodymain.php');
   }
}
function setOutputl(){
   if(httpObject.readyState == 4){
      document.getElementById('loginp').innerHTML = httpObject.responseText;
	  loaditpoll('polli.php');
	  //loaditstat('stat.php');
	  //loadit('bodymain.php');
	  document.loginf.userName.value = readCookie('remember');
   }
}
function setOutputlc(){
   if(httpObject.readyState == 4){
      document.getElementById('loginp').innerHTML = httpObject.responseText;
	  loaditpollc('polli.php');
	  //loaditstat('stat.php');
	  //loadit('bodymain.php');
	  document.loginf.userName.value = readCookie('remember');
   }
}

// Change the value of the outputText field
function setOutput2(ff){
   if(httpObject.readyState == 4){
		loadit(ff + '&finished=1');
	}
}
// Implement business logic
function loadit2(ff){
	document.getElementById('loader').style.display = '';
	document.getElementById('bodyin').style.display = 'none';
   httpObject = getHTTPObject();
   if (httpObject != null) {
      httpObject.open("GET", ff, true);
      httpObject.send(null);
      httpObject.onreadystatechange = function() {//Call a function when the state changes.
	if(httpObject.readyState == 4) {
		// document.getElementById('bodyin').innerHTML = http.responseText;
		setOutput2(ff);
	}
   }
   }
}
var httpObject = null;

// Implement business logic
function loading(ff){
	loaditl('login.php');
}
function loadingc(ff){
	loaditlc('login.php');
}


	 function CuteWebUI_AjaxUploader_OnTaskComplete(task)
	 {
		// var div=document.createElement("DIV");
		// var link=document.createElement("A");
		// link.setAttribute("href","savefiles/"+task.FileName);
		// link.innerHTML="You have uploaded file : savefiles/"+task.FileName;
		// link.target="_blank";
		// div.appendChild(link);
		// document.body.appendChild(div);
		document.FormRegister.src.value = task.FileName;
		document.getElementById('hh2').innerHTML = task.FileName;
		document.getElementById('button').style.display = "none";
		document.getElementById('input').style.display = "";
	 }
	 function remove()
	 {
		document.FormRegister.src.value = '';
		document.getElementById('hh2').innerHTML = '';
		document.getElementById('button').style.display = "";
		document.getElementById('input').style.display = "none";
	 }
	 
	 
	function goSubmit(f){
	window.addEvent('domready', function() {
	$(f).addEvent('submit', function(e) {
		e.stop();
		//Empty the log and show the spinning indicator.
		$('bodyin').style.display='none';
		$('loader').style.display='';
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) {
			$('loader').style.display='none';
			$('bodyin').style.display='';
			$('bodyin').set('html', response);
		}});
		//Send the form.
		this.send();
	
	});
	});
	};
	function goSubmitl(f){
	if(f=="loginfl"){
	window.addEvent('domready', function() {
	$(f).addEvent('submit', function(e) {
		e.stop();
		//Empty the log and show the spinning indicator.
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) {
			$('loginp').set('html', response);
	  document.loginf.userName.value = readCookie('remember');
	  loaditpoll('polli.php');
	  //loaditl('login.php');
		}});
		//Send the form.
		this.send();
	
	});
	});
	} else {
	window.addEvent('domready', function() {
	$(f).addEvent('submit', function(e) {
		e.stop();
		//Empty the log and show the spinning indicator.
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) {
			$('loginp').set('html', response);
	  document.loginf.userName.value = readCookie('remember');
	  loaditpoll('polli.php');
		}});
		//Send the form.
		this.send();
	
	});
	});
	}
	};