var xmlhttp = false;

try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}

catch (e){
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
////////////////////////////////////
function makevisible(cur,which){
strength=(which==0)? 1 : 0.85

if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
}

//////////////////////////////////////////////////
function makerequest(serverPage, objID) {
  var obj = document.getElementById(objID);
  //fadeIn();
  xmlhttp.open("get", serverPage);
  var loadstatustext="<img src='../images/indicator.gif'>";
  xmlhttp.onreadystatechange = function() {
    document.getElementById('loading_div').innerHTML=loadstatustext;
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      dhtmlHistory.add(serverPage);
      document.getElementById(objID).innerHTML = xmlhttp.responseText;
      document.title = ":: الجمعية السورية لدعم البحوث الطبية ::" ;
      document.getElementById('loading_div').innerHTML="";
    }
  }
  xmlhttp.send(null);
}
//////////////////////////////////////////////////
function getformvalues (fobj){
var str = "";
for(var i = 0; i < fobj.elements.length; i++){
  str += fobj.elements[i].name + "=" + fobj.elements[i].value + "&";
}
return str;
}

//////////////////////////////////////////////////
function submitform (theform, serverPage, objID){
var file = serverPage;
var str = getformvalues(theform);
//If the validation is ok.
obj = document.getElementById(objID);
obj.disabled=true;
processajax2(serverPage, obj, str);
}

//////////////////////////////////////////////////
function search_request (theform, ss_str, serverPage, objID){
if(ss_str.length > 3){
  var file = serverPage;
  var str = getformvalues(theform);
  //If the validation is ok.
  obj = document.getElementById(objID);
  processajax(serverPage, obj, str);
}else{
  document.getElementById('search_area').innerHTML="";
}
}

//////////////////////////////////
function processajax2(serverPage, obj, str){
xmlhttp.open("post", serverPage, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
var loadstatustext="<img src='../images/indicator.gif' hspace='50'>";
xmlhttp.onreadystatechange = function() {
  document.getElementById('loading_div').innerHTML=loadstatustext;
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  document.getElementById('loading_div').innerHTML="";
  obj.innerHTML = xmlhttp.responseText;
  obj.disabled=false;
}
}
xmlhttp.send(str);
}

//////////////////////////////////////////////////////////
function processajax(serverPage, obj, str){
xmlhttp.open("post", serverPage, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
var loadstatustext="<img src='../images/spinner.gif'>";
xmlhttp.onreadystatechange = function() {
  document.getElementById('loading_div2').innerHTML=loadstatustext;
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  document.getElementById('loading_div2').innerHTML="";
  obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(str);
}

//////////////////////////////////////////////////
function makerequestph(serverPage, objID) {
  var obj = document.getElementById(objID);
  //fadeIn();
  xmlhttp.open("get", serverPage);
  //var loadstatustext="<img src='images/ss.gif'>";
  xmlhttp.onreadystatechange = function() {
    //document.getElementById('loading_div').innerHTML=loadstatustext;
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      opacity('main2', 0, 100, 500);
      document.getElementById(objID).innerHTML = xmlhttp.responseText;
      //document.getElementById('loading_div').innerHTML="";
    }
  }
  xmlhttp.send(null);
}

/////////////////////////////////////////
function clear_frame(objID) {
  opacity('main2', 100, 0, 500);
}
////////////////////////////////////////////////
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("changeOpac2(" + 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 + ")";
	if(object.opacity == 1/100){ document.getElementById('main2').innerHTML = "";}
}
function changeOpac2(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 + ")";
}
////////////////////////////////////////////////////////////////////////////
window.onload = initialize;
  function initialize() {
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(handleHistoryChange);
	var initialLocation = dhtmlHistory.getCurrentLocation();
	if (initialLocation == ""){
		initialLocation = 'main.php';
	}
	// now initialize our starting UI
	makerequest(initialLocation, 'main');
  }
  /** A function that is called whenever the user presses the back or forward buttons. This function will be passed the newLocation, as well as any history data we associated with the location. */
function handleHistoryChange(newLocation) {
	// use the history data to update our UI
  makerequest(newLocation, 'main');
}
