var xmlhttp
var response;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}

function handleStateChange()
{        
    if (xmlhttp.readyState == 3)
    {
        alert(xmlhttp.responseText);
    }
}

function ajax_call(Url, param, returnDiv, showAlert) {
	

	xmlhttp.open("GET",Url+"?"+param,true);

	xmlhttp.onreadystatechange=function() {
		
		if (xmlhttp.readyState==4 ) {
		
				if(showAlert == true){
				alert("ajax_call Debug : "+xmlhttp.responseText)
				alert(document.getElementById(returnDiv).innerHTML);
				}


			document.getElementById(returnDiv).innerHTML = xmlhttp.responseText;
			if(showAlert == true)
				alert("ajax_call Debug : "+xmlhttp.responseText)
		}
	}
	xmlhttp.send(null)
	
	return false;
}

function ajax_call2(Url, param, returnDiv, showAlert) {

      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
 //     http_request.onreadystatechange = alertContents;
 	http_request.onreadystatechange=function() {
		
		if (http_request.readyState==4 ) {
		
				if(showAlert == true){
				alert("ajax_call Debug : "+http_request.responseText)
				alert(document.getElementById(returnDiv).innerHTML);
				}

			//alert(xmlhttp.responseText);
			document.getElementById(returnDiv).innerHTML = http_request.responseText;
			if(showAlert == true)
				alert("ajax_call Debug : "+http_request.responseText)
		}
	}
      http_request.open('POST', Url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", param.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(param);
}

function escapeURL(str) {

str=str.replace(" ", "%20"); 	
str=str.replace("!", "%21"); 
str=str.replace("@", "%40"); 
str=str.replace("#", "%23"); 
str=str.replace("$", "%24");
str=str.replace("%", "%25");
str=str.replace("^", "%5E");
str=str.replace("&", "%26");
str=str.replace("*", "%2A");
str=str.replace("(", "%28");
str=str.replace(")", "%29");
str=str.replace("=", "%3D");
str=str.replace("+", "%2B");
str=str.replace(":", "%3A");
str=str.replace(";", "%3B");
str=str.replace('"', "%22");	
str=str.replace("'", "/'");
str=str.replace("\\", "%5C");
str=str.replace("/", "%2F");
str=str.replace("?", "%3F");
str=str.replace("<", "%3C");
str=str.replace(">", "%3E");
str=str.replace("~", "%7E");
str=str.replace("[", "%5B");
str=str.replace("]", "%5D");
str=str.replace("{", "%7B");
str=str.replace("}", "%7D");
str=str.replace("'", "%60");

return str;
}
	 

function showAddFavForm(prdid,status,favId) {
	ajax_call("http://international.esources.co.uk/add-to-favourites.php","catid="+favId+"&parts=" + prdid+"&status="+status,"showAddFav"+prdid,false);
}

function addtofavourtiesFormPost(prdid,queryMode,favId) {

	favCat = document.getElementById('favcat'+prdid).value;
	favRating = document.getElementById('fav-rating'+prdid).className;
	
	if(favRating == "rating onestar"){	favRating="1";	}
	if(favRating == "rating twostar") {favRating="2"; }
	if(favRating == "rating threestar") {favRating="3";}
	if(favRating == "rating fourstar"){ favRating="4";	}
	if(favRating == "rating fivestar") {favRating="5";	}

	favNotes = document.getElementById('favmessage-textarea'+prdid).value;
	newFavCat = document.getElementById('favnewcat'+prdid).value;
		
		favNotes=escapeURL(favNotes);

	var poststr = "catid="+encodeURI(favId)+"&parts=" + encodeURI(prdid)
		+"&favcat="+encodeURI(favCat)
		+"&newfavcat="+encodeURI(newFavCat)
		+"&fav-rating="+encodeURI(favRating)
		+"&txtnotes="+encodeURI(document.getElementById('favmessage-textarea'+prdid).value)
		+"&queryMode="+encodeURI(queryMode)

	ajax_call2("http://international.esources.co.uk/add-to-favouritesFORMPOST.php",poststr
		,"layerDialog"+prdid, false);
}

function addtofavourtiesFormPostOLD(prdid,queryMode,favId) {

	favCat = document.getElementById('favcat'+prdid).value;
	favRating = document.getElementById('fav-rating'+prdid).className;
	
	
	if(favRating == "rating onestar"){	favRating="1";	}
	if(favRating == "rating twostar") {favRating="2"; }
	if(favRating == "rating threestar") {favRating="3";}
	if(favRating == "rating fourstar"){ favRating="4";	}
	if(favRating == "rating fivestar") {favRating="5";	}


	favNotes = document.getElementById('favmessage-textarea'+prdid).value;
	newFavCat = document.getElementById('favnewcat'+prdid).value;

	
		
		
		
		///newFavCat=escapeURL(newFavCat);
		favNotes=escapeURL(favNotes);
		//favNotes=escape(favNotes);
	
 	
    	
	//alert('favCat = '+favCat);
	//alert('newfavCat = '+newFavCat);
	//alert('favNotes = '+favNotes);
	//alert('favRating = '+favRating);


	ajax_call("http://international.esources.co.uk/add-to-favouritesFORMPOST.php",
		"catid="+favId+"&parts=" + prdid
		+"&favcat="+favCat
		+"&newfavcat="+newFavCat
		+"&fav-rating="+favRating
		+"&txtnotes="+favNotes+"&queryMode="+queryMode,"layerDialog"+prdid, false);
//	alert('END')

}


function showLink(prdid,favId) {
	ajax_call("http://international.esources.co.uk/add-to-favouritesLINKPRINTING.php","catid="+favId+"&parts=" + prdid,"showAddFav"+prdid,false)
}


	
function removeFromMyfav(prdid,favId) {
	ajax_call("http://international.esources.co.uk/add-to-favouritesREMOVEFROMFAVOURITES.php","catid="+favId+"&parts=" + prdid,"showAddFav"+prdid,false)
}



function changeRating(Id,ratingClass) {
		document.getElementById(Id).className=ratingClass
}


function disableItem(itemId) {
	document.getElementById(itemId).disabled=true
}

function enableItem(itemId) {
	document.getElementById(itemId).disabled=false
}

function assignStyleHeight(ID1,ID2){
			document.getElementById(ID2).style.height=document.getElementById(ID1).offsetHeight; 
}

function textCounter(Idtxtnotes,Idcounter,maxlimit){
	
	if (document.getElementById(Idtxtnotes).value.length > maxlimit) // if too long...trim it!
	document.getElementById(Idtxtnotes).value = document.getElementById(Idtxtnotes).value.substring(0, maxlimit);
	else
	document.getElementById(Idcounter).value =  2000 - (document.getElementById(Idtxtnotes).value.length);
}

function assignStyleHeight(ID1,ID2){
	document.getElementById(ID2).style.height=document.getElementById(ID1).offsetHeight; 
}
