/*
Ajax Library:
===========
This library contains all the code you need to initiate the xmlHTTPObject
and the general procedure of sending ajax request to the server and
receiving it.
@version: 1.0
@author:  Waseem Khan
@blog:    http://blog.pakcoders.com
*/

function op(){
if (trim(document.form1.fac.value)=="")
{
alert("اختر الكلية...");
return false;
}
if (document.form1.cen)
{
if (trim(document.form1.cen.value) =="" && (trim(document.form1.cer.value) =="2" || trim(document.form1.cer.value) =="3") && (trim(document.form1.fac.value)=="19"))
{
	alert("اختر المركز");
	return false;
}
}

if (trim(document.form1.cer.value)=="")
{
alert("اختر نوع الدراسة...");
return false;
}
else if(trim(document.form1.cer.value)=="1" || trim(document.form1.cer.value)=="6")
if (document.form1.cen && trim(document.form1.fac.value)=="19" && trim(document.form1.fac.value)=="12")
document.form1.cen.value="";
if (trim(document.form1.dep.value)=="")
{
alert("اختر القسم...");
return false;
}
if (trim(document.form1.lev.value)=="")
{
alert("اختر الفرقة...");
return false;
}
if (document.form1.cls)
if (trim(document.form1.cls.value) =="")
{
alert("اختر الفصل الدراسي");
return false;
}
if (trim(document.form1.yea.value)=="")
{
alert("اختر السنة...");
return false;
}
//window.open("index.php?id2="+r1+"&id3="+r2+"&id4="+r3+"&id5="+r4+"&id6="+r5,"_self");
//getElemId('form1').submit();
}
var loaded = false;
var loaded1 = false;
var loaded2 = false;
var loaded3 = false;

function startLoading(tid) {
    loaded = false;
    loaded1 = false;
    loaded2 = false;
    loaded3 = false;
	if(tid=="dept")
    window.setTimeout('showLoadingImage()', 100);
	if(tid=="levl")
    window.setTimeout('showLoadingImage1()', 100);
	if(tid=="cent")
    window.setTimeout('showLoadingImage2()', 100);
	if(tid=="cl")
    window.setTimeout('showLoadingImage3()', 100);
  }

function showLoadingImage() {
    var el = document.getElementById("loading_box");
    if (el && !loaded) {
    el.style.visibility = "visible";
        el.innerHTML = '<img src="images/load2.gif" width=25 hight=25>';
        //new Effect.Appear('loading_box');
    }
  }
function showLoadingImage1() {
    var el = document.getElementById("loading_box1");
    if (el && !loaded1) {
    el.style.visibility = "visible";
        el.innerHTML = '<img src="images/load2.gif"  width=25 hight=25>';
        //new Effect.Appear('loading_box1');
    }
  }
function showLoadingImage2() {
    var el = document.getElementById("loading_box2");
    if (el && !loaded2) {
    el.style.visibility = "visible";
        el.innerHTML = '<img src="images/load2.gif"  width=25 hight=25>';
        //new Effect.Appear('loading_box1');
    }
  }
function showLoadingImage3() {
    var el = document.getElementById("loading_box3");
    if (el && !loaded3) {
    el.style.visibility = "visible";
        el.innerHTML = '<img src="images/load2.gif"  width=25 hight=25>';
        //new Effect.Appear('loading_box1');
    }
  }
function stopLoading(tid) {
	if(tid=="dept")
	{
	var el = document.getElementById("loading_box");
    el.style.visibility = "hidden";
    loaded = true;
	}
	if(tid=="levl")
	{
	var el = document.getElementById("loading_box1");
    el.style.visibility = "hidden";
    loaded1 = true;
	}
		if(tid=="cent")
	{
	var el = document.getElementById("loading_box2");
    el.style.visibility = "hidden";
    loaded2 = true;
	}
	if(tid=="cl")
	{
	var el = document.getElementById("loading_box3");
    el.style.visibility = "hidden";
    loaded3 = true;
	}
  }
  
function getAjaxObject()
{
  // initially set the object to false 
  var XMLHttpRequestObject = false;
  if (window.XMLHttpRequest)
  {
      // check for Safari, Mozilla, Opera...
	  XMLHttpRequestObject = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) 
  {
      // check for Internet Explorer
	  XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (!XMLHttpRequestObject)
  {
	  alert("Your browser does not support Ajax.");
	  // return false in case of failure
	  return false;
  }
  // return the object in case of success
  return XMLHttpRequestObject;
}


function sendRequest(xmlHTTPObject, url, parameters, id, targetid, inputid, searchid, e)//, handleResponse
{
   if(xmlHTTPObject)
   {
      // continue if the object is idle
      if (xmlHTTPObject.readyState == 4 || xmlHTTPObject.readyState == 0) 
      {
		 // open connection and send "GET" request to server
		 xmlHTTPObject.open("POST", url, true);
		 // send the appropriate headers
		 xmlHTTPObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 // set the function to be called on a change in ajaxObj state--handleSuggestResponse
		 xmlHTTPObject.onreadystatechange = function () {handleSuggestResponse(id, targetid, inputid, searchid, e)};//handleResponse
		 // set additional parameters (to be sent to server) to null
         xmlHTTPObject.send(parameters);
      }
   }
}
