//Save Listing Javscript
//created by Adam Duncan
//date: 07/17/06

// this is the code test what browser
var a = [ 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.5.0' ];

function checkBrowser() {
//See if the browser supports XMLHttpRequest
  if(window.XMLHttpRequest){
    //Mozilla
    return true;
  }
  else if(window.ActiveXObject) {
    //IE
    var testObj;
    var i = a.length;
    while (i--) {
     try {
       testObj = new ActiveXObject( a[i] );
	   return true;
	 } catch (e) {}
    }
  }
  return false;
} 

if(!checkBrowser()){
  window.location.href = 'default.asp';
}

if( !window.XMLHttpRequest && window.ActiveXObject ) {
//If IE, define XMLHttpRequest for consistency
  window.XMLHttpRequest = function() {
  var i = a.length;
  while (i--) {
   try {
     return new ActiveXObject( a[i] );
    } catch (e) {}
   }
   return null;
  };
 }
//end of browser test 

//global variables for save listing
 var Async_Queue;
 
//function changes the save icon if listing saved
 function listingComplete(ml_num_id,img_name_passed,dis_text_write)
{
  var x;
  var write_text = '<img src="' + img_name_passed + '" border="0" align="absmiddle" hspace="4px" />';
  if(dis_text_write=="true"){write_text = write_text + '<span class="function_font_heading">Listing Saved</span>';}
  var display_return_msg;
  requestInfo = Async_Queue;
  if (requestInfo.xmlHttp.readyState==4) {
    if(requestInfo.xmlHttp.status == 200) //The server responded with OK
      display_return_msg = requestInfo.xmlHttp.responseText;	
	  if(display_return_msg=="true"){
	  	document.getElementById("listing_" + ml_num_id).innerHTML = write_text;
	  }	
      requestInfo.xmlHttp = null;
  }
  requestInfo = null;
}
 
//sends ml information to asp page
 function sendSaveListing(ml_num,l_id,u_id,img_name,dis_text,ser_test)
{
  var theURL;
  var saveingObj = new Object();
  
  //define fucntion to call after save
  saveingObj.xmlHttp = new XMLHttpRequest();
  saveingObj.xmlHttp.onreadystatechange = function() {listingComplete(ml_num,img_name,dis_text);};
  Async_Queue = saveingObj;	
  
  //test which server it is on
  if(ser_test){
  	theURL = '../../scripts_rev/save_listing/save_listing_rev.asp?ml_num=' + ml_num + '&l_id=' + l_id + '&u_id=' + u_id;
  }else{
    theURL = 'scripts_rev/save_listing/save_listing_rev.asp?ml_num=' + ml_num + '&l_id=' + l_id + '&u_id=' + u_id;
  }
  //send info to asp page
  saveingObj.xmlHttp.open("GET", theURL, true);
  saveingObj.xmlHttp.send(null);
}

//sends ml information to asp page Third Party Version
 function sendSaveListing_tp(ml_num,l_id,u_id,img_name,dis_text,ser_test,f_num)
{
  var theURL;
  var saveingObj = new Object();
  
  //define fucntion to call after save
  saveingObj.xmlHttp = new XMLHttpRequest();
  saveingObj.xmlHttp.onreadystatechange = function() {listingComplete(ml_num,img_name,dis_text);};
  Async_Queue = saveingObj;	
  
  //test which server it is on
  if(ser_test){
  	theURL = '../../scripts_rev/save_listing/save_listing_tp.asp?ml_num=' + ml_num + '&l_id=' + l_id + '&u_id=' + u_id + '&f_num=' + f_num;
  }else{
    theURL = 'scripts_rev/save_listing/save_listing_tp.asp?ml_num=' + ml_num + '&l_id=' + l_id + '&u_id=' + u_id + '&f_num=' + f_num;
  }
  //send info to asp page
  saveingObj.xmlHttp.open("GET", theURL, true);
  saveingObj.xmlHttp.send(null);
}
 