
var xmlhttp;
var load = ""	// Loading Div to show ajax loader
var element = "welcome";    //element to be defined as the main div to see changes in it
function waiting(){
	$('#'+load).fadeIn();
}
function loading(){
	$('#'+load).fadeOut();
	$('#'+element).fadeIn();
	}
function showpage(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getpage.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
(str!='main')?xmlhttp.onreadystatechange=stateChanged:xmlhttp.onreadystatechange=stateChangedmain;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function Post(str)
{
  xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
		{
		alert ("Browser does not support HTTP Request");
		return;
		}
var url = "submit.php";
var params = "lorem="+str;
xmlhttp.open("POST", url, true);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange =stateChanged;// function() {//Call a function when the state changes.
//	if(http.readyState == 4 && http.status == 200) {
//		alert(http.responseText);
//	}
//}
xmlhttp.send(params);
}
function showvalues(str)
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="q.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChangedforvalue;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function addbasket(id)
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="add.php";
url=url+"?q="+id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=add;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function plmi(id,d){
  xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
    var url="qty.php";
    url=url+"?do="+d;
    url=url+"&id="+id;
    url=url+"&sid="+Math.random();
    xmlhttp.onreadystatechange=donebasload;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);

}
function basket()
    {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="bask.php";
url=url+"?sid="+Math.random();
xmlhttp.onreadystatechange=basload;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function add(){
if(xmlhttp.readyState < 4){
          }
if(xmlhttp.readyState == 4){
      if(navigator.appName == "Netscape"){
      $('#asd').clone().prependTo('#prod');
      $('#asd').animate({opacity:"0",width:"50",height:"50","left":"-=319","top":"+=35"},1000,
      function(){
              $('#asd').remove();
              alert(xmlhttp.responseText);
            }
        )
      }
      else alert(xmlhttp.responseText);

      }
}


function basload(){
if(xmlhttp.readyState < 4){
        document.getElementById('basket').innerHTML = "<img src = \"images/loading.gif\"> ";
          }
if(xmlhttp.readyState == 4){
      document.getElementById('basket').innerHTML = xmlhttp.responseText;
      }
}
function donebasload(){
if(xmlhttp.readyState < 4){
        document.getElementById('basket').innerHTML = "<img src = \"images/loading.gif\"> ";
          }
if(xmlhttp.readyState == 4){
      basket();
      }
}


function stateChangedforvalue()
{
    if(xmlhttp.readyState < 4){
	//waiting();
    	document.getElementById("test").innerHTML="";
	}
    if (xmlhttp.readyState==4)
    {
        $('#test').animate({opacity:"0"}, 100)
        .slideUp()
        $('#test').animate({opacity:"1.0",height:"100"},500,
        function(){
           document.getElementById("test").innerHTML = xmlhttp.responseText;
        }
        )

    }
}
function stateChanged()
{
    if(xmlhttp.readyState < 4){
	//waiting();
    $("#ette").hide();
    $('#content').fadeOut();
    	document.getElementById("content").innerHTML="";
	}
    if (xmlhttp.readyState==4)
    {

      $('#content').fadeIn();
        $('#content').animate({opacity:"1.0",height:"100"},500,
        function(){
           document.getElementById("content").innerHTML = xmlhttp.responseText;
        }
        )

    }
}
function stateChangedmain()
{
    if(xmlhttp.readyState < 4){
	//waiting();
    $("#ette").hide();
    $('#content').fadeOut();
    	document.getElementById("content").innerHTML="";
	}
    if (xmlhttp.readyState==4)
    {
    $("#ette").fadeIn();
      $('#content').fadeIn();
        $('#content').animate({opacity:"1.0",height:"100"},500,
        function(){
           document.getElementById("content").innerHTML = xmlhttp.responseText;
        }
        )

    }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
var i=0;
function addtf(){
  if(i<48){
var obj = document.getElementById('tf').cloneNode(true);
$("#questions").append(obj);
$("#questions").hide();
$("#questions").fadeIn();
i++;}else
alert("شما 50 سوال قرار داده ايد براي استفاده بهتر ابتدا اين 50 سوال را تاييد کرده و سپس دوباره سوالات را اضافه کنيد.");
}
function addtest(){
  if(i<48){
var obj = document.getElementById('test').cloneNode(true);
$("#questions").append(obj);
$("#questions").hide();
$("#questions").fadeIn();
i++;       }else
alert("شما 50 سوال قرار داده ايد براي استفاده بهتر ابتدا اين 50 سوال را تاييد کرده و سپس دوباره سوالات را اضافه کنيد.");
}
function close(e){
  alert(window.event);
}
function addcomment(comment,name,cat)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
  var url = "addcomment.php";
    var params = "comment="+comment;
    params += "&name="+name;
    params += "&cat="+cat;
    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.onreadystatechange=stateChangedcomment;
    xmlhttp.send(params);
}
function stateChangedcomment()
{
    if(xmlhttp.readyState < 4){
	//waiting();
        $('#comment').fadeOut();
    	document.getElementById("comment").innerHTML="";
	}
    if (xmlhttp.readyState==4)
    {
         $('#comment').fadeIn();
         document.getElementById("comment").innerHTML = xmlhttp.responseText;
    }
}
