var xmlHttp;



function SendRegister(Form){
    SendDataByAjax(Form,"includes/Site.Ajax.Functions.php?do=SendRequest","?");
}

function Paging(type,page){
	xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
	}	
	
	var url="includes/Site.Ajax.Functions.php?do="+type+"&PageID="+page;
	xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==1){
            document.getElementById("AjaxLoading").style.display = ""; 
		} 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            var result = xmlHttp.responseText.split('||||||');
              document.getElementById("pages_info").innerHTML="";
              jQuery('#pages_info').html(result[0]);
              document.getElementById("AjaxPaingArea").innerHTML="";
              jQuery('#AjaxPaingArea').html(result[1]);
              document.getElementById("pages_no").innerHTML="";
              jQuery('#pages_no').html(result[2]);
            document.getElementById("AjaxLoading").style.display = "none"; 
         }};
     
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);		
}

function SendDataByAjax(form,url,Redirect){
    
	xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
	}

    TextEditor1 = "Content";
    TextEditor2 = "Content2";
	
    var $inputs = $('#'+form+' input:text,#'+form+' input:hidden,#'+form+' input:password,#'+form+' input:checkbox:checked, #'+form+' textarea, #'+form+' select , #'+form+' input:radio:checked');
    
    var params = "";
	$inputs.each(function(i, el) {
	   if(el.name == TextEditor1 || el.name == TextEditor2){
           params += el.name + "=" + encodeURIComponent($(el).val()) + "&";
	   }else
       params += el.name + "=" + $(el).val() + "&";   
    }
    );
    
	xmlHttp.onreadystatechange= function(){
	   
    var ajax_loading = document.getElementById("ajax_loading");
	var tr_error_msg = document.getElementById("tr_error_msg");
	var error_msg = document.getElementById("error_msg");
	var buttons = document.getElementById("buttons");
	var tr_right_msg = document.getElementById("tr_right_msg");
    
	if (xmlHttp.readyState==1){
		tr_error_msg.style.display="none";
		tr_right_msg.style.display="none";
		error_msg.innerHTML='';
		ajax_loading.style.display="";
		buttons.style.display="none";
	}
		
	if (xmlHttp.readyState==4){
		var result = trim(xmlHttp.responseText);
		ajax_loading.style.display="none";
		buttons.style.display="";
		if(result != "true"){
			error_msg.innerHTML=result;
	    	$('#tr_error_msg').fadeIn("slow");
		}
		else{
		  if(Redirect == 0)
			$('#tr_right_msg').fadeIn("slow");
            else{
                $('#tr_right_msg').fadeIn("slow");
                setTimeout('window.location = "'+Redirect+'"', 1000);
            }
		}
	}
	};
	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.send(params);
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
     	xmlHttp=new XMLHttpRequest();
	}
	catch (e){//Internet Explorer
    	try{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e){
     		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
	}
	return xmlHttp;
}
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}
