//////////////////////////////New AJAX Request/////////////////////////////////////////////////



var loading = "http://campus-tech/careernet_new/images/ajax-loader.gif";

// JavaScript Document
function createRequest() {
     try {
       request = new XMLHttpRequest();
     } catch (trymicrosoft) {
       try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (othermicrosoft) {
         try {
           request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
           request = null;
         }
       }
     }

     if (request == null)
       alert("Error creating request object!");
   }
   
//////////////////////////////New AJAX Request/////////////////////////////////////////////////






function ajaxObject(url, callbackFunction) {
  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(divid, passData, postMethod, funct, parameters) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() { 
	  if(divid != null)
	  {
	  if (that.AJAX.readyState == 1 || that.AJAX.readyState == 2) 
		{
		document.getElementById(divid).innerHTML="<img src=\""+loading+"\"/ border=\"0\">";
		}
		if (that.AJAX.readyState == 3)
		{
		document.getElementById(divid).innerHTML="<img src=\""+loading+"\" border=\"0\"/>";	
		}	
	  }
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML, divid, funct, parameters);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
		  if(passData != null)
          var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
		  else
		  var uri=urlCall+'?timestamp='+(that.updating.getTime());
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
function ajaxObject(url, callbackFunction, throbber) {
  var that=this;      
  this.updating = false;
  this.abort = function() {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(divid, passData, postMethod, funct, parameters) { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) {              
      that.AJAX=new XMLHttpRequest();              
    } else {                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) {                             
      return false;                               
    } else {
      that.AJAX.onreadystatechange = function() { 
	  if(divid != null)
	  {			
	         if (that.AJAX.readyState == 1 || that.AJAX.readyState == 2) 
		     {
		  		if(throbber == 1)
				document.getElementById(divid).innerHTML="<img src=\""+defaultThrobber+"\"/ border=\"0\">";
				else if(throbber != 0)
				document.getElementById(divid).innerHTML=throbber;
		      }
		     if (that.AJAX.readyState == 3)
		      {
				if(throbber == 1)
						document.getElementById(divid).innerHTML="<img src=\""+defaultThrobber+"\"/ border=\"0\">";
				else if(throbber != 0)
						document.getElementById(divid).innerHTML=throbber;
		      }	
	  }
  
	  
        if (that.AJAX.readyState==4) {             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML, divid, funct, parameters);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } else {
		  if(passData != null)
          var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
		  else
		  var uri=urlCall+'?timestamp='+(that.updating.getTime());
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

/////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////NEW OPEN URL FUNCTION////////////////////////


function open_url(url, placeHolder, method, querystring, funct, functParams, throbber)
	{
		
		var myRequest = new ajaxObject(url, open_url_action, throbber);
		if(method == 'get' || method == 'GET')
        myRequest.update(placeHolder, querystring, 'get', funct, functParams);
		if(method == 'post' || method == 'POST')
        myRequest.update(placeHolder, querystring, 'post', funct, functParams);
		
	}

	function open_url_action(responseText, responseStatus, responseXML, placeHolder, funct, parameters)
		{
						if (responseStatus == 200) 
							{
							  document.getElementById(placeHolder).innerHTML=responseText;
							  if(funct !=null)
							  funct(parameters);
							} 
						else 
							{
							 alert(responseStatus);
							}	
		}

////////////////  OPEN URL////////////////////////



function clearDiv(divid)
{
document.getElementById(divid).innerHTML = '';
}

//////IndexOf for IE/////////
if(Array.indexOf = 'undefined' || !Array.indexOf)
	{
		Array.prototype.indexOf = function(obj)
			{
	       		for(var i=0; i<this.length; i++)
					{
	            		if(this[i]==obj)
							{
	               				 return i;
	            			}
	        		}
	        	return -1;
	    	}
	}
////////IndexOf for IE //////////

function removeElement(e, parent, child)
	{
		childObj=document.getElementById(child);
		parentObj=document.getElementById(parent);
		e = e || window.event;
        var element = e.target ? e.target : e.srcElement;
        parentObj.removeChild(childObj);
        if(e.preventDefault)
			{
             	e.preventDefault();
             	e.stopPropagation();
          	}
		else
			{
             	e.returnValue = false;
             	e.cancelBubble = true;
          	}
	}
	*/
