
var msxmls = new Array ("Msxml2.XMLHTTP.3.0", "Microsoft.XMLHTTP" )

function createRequestObject(){
	var browser=navigator.appName;
	if(window.XMLHttpRequest){return new XMLHttpRequest();} // Mozilla, Safari, ...
	else if(window.ActiveXObject){ // IE
		for(var n in msxmls){
			try{return new ActiveXObject(msxmls[n]);}
			catch(e){ }
		}
	}
	return false;
}

function HTTPsend(fCallBack, u, d){
	var xmlhttp=createRequestObject();
	if(xmlhttp){
		if(u.indexOf('?')>-1){u+='&';}
		else{u+='?';}
		u+='rnd='+Math.ceil(Math.random()*10000);

		xmlhttp.open("POST", u, true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
	//			try{
					if(xmlhttp.status==200){
						text=xmlhttp.responseText;
						eval(fCallBack+"(text)");
						xmlhttp=null;
						try{CollectGarbage();} catch (e) {}
					}else{
						alert(xmlhttp.status+" HTTP Error: "+xmlhttp.statusText+"\n\nPlease check yout connection and try again.");
						xmlhttp=null;
					}
	//			}catch(e){
	//				alert("12031 HTTP Error: Unknown\n\nPlease check yout connection and try again.");
	//				xmlhttp=null;
	//			}
			}
		}
		xmlhttp.send(d);
		return true;
	}
}
function HTTPsendM(fCallBack, u, d){
	var xmlhttp=createRequestObject();
	if(xmlhttp){
		if(u.indexOf('?')>-1){u+='&';}
		else{u+='?';}
		u+='rnd='+Math.ceil(Math.random()*10000);

		xmlhttp.open("POST", u, true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
	//			try{
					if(xmlhttp.status==200){
						text=xmlhttp.responseText;
						eval(fCallBack+"(text, "+d+")");
						xmlhttp=null;
						try{CollectGarbage();} catch (e) {}
					}else{
						alert(xmlhttp.status+" HTTP Error: "+xmlhttp.statusText+"\n\nPlease check yout connection and try again.");
						xmlhttp=null;
					}
	//			}catch(e){
	//				alert("12031 HTTP Error: Unknown\n\nPlease check yout connection and try again.");
	//				xmlhttp=null;
	//			}
			}
		}
		xmlhttp.send(''+d);
		return true;
	}
}
// var xmlhttp;
// var callback;
// function HTTPsend(fCallBack, u, d){
// 	xmlhttp=createRequestObject();
// 	callback = fCallBack;
// 	if(xmlhttp){
// 		if(u.indexOf('?')>-1){u+='&';}
// 		else{u+='?';}
// 		u+='rnd='+Math.ceil(Math.random()*10000);
//
// 		xmlhttp.open("POST", u, false);
// 		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// 		xmlhttp.onreadystatechange=ReadyStateChange;
// 		xmlhttp.send(d);
// 		if(xmlhttp.onreadystatechange == null) ReadyStateChange();
// 		return true;
// 	}
// }
//
// function ReadyStateChange()
// {
// 	if(xmlhttp.readyState==4){
// 		try{
// 			if(xmlhttp.status==200){
// 				text=xmlhttp.responseText;
// 				eval(fCallBack+"(text)");
// 				xmlhttp=null;
// 				try{CollectGarbage();} catch (e) {}
// 			}else{
// 				alert(xmlhttp.status+" HTTP Error: "+xmlhttp.statusText+"\n\nPlease check yout connection and try again.");
// 				xmlhttp=null;
// 			}
// 		}catch(e){
// 			alert("12031 HTTP Error: Unknown\n\nPlease check yout connection and try again.");
// 			xmlhttp=null;
// 		}
// 	}
// }


//javascript function to encode:
function mycript(s)
{
	var res='';
	for(i=0; i<s.length; i++){
		a=s.charCodeAt(i);
		if(a>0xFF){a-=0x350;}
		res=res+'z'+a;
	}
	return res;
}

var __IE__ = 1 // IE
if (navigator.userAgent.indexOf('Gecko') != -1)
  __IE__ = 0 // MOZILLA

function positionWindow (width, height, event) {
var winWidth           = screen.width
var winHeight          = screen.height
if (event == null) {
  var left             = 150
  var top              = 150
} else {
  var left             = event.screenX + 15
  var top              = event.screenY + 15
}
if ((left + width) > winWidth)
  left =  winWidth - width - 10
if ((top + height + 100) > winHeight)
  top =  winHeight - height - 100
return new Array (left, top)
}


function PopupWindow (url, width, height, event){

	var aXY = positionWindow (width, height, event)

	if (__IE__ == 1) {
    height += 40
    window.showModalDialog(url,
      window,"dialogHeight: " + height + "px; dialogWidth: " + width +
      "px; dialogLeft: " + aXY[0] + "px; dialogTop: " + aXY[1] +
      "; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll:no; unadorned; no")

  } else {
    //var cBaseUrl = new String (window.location)
    //var a = cBaseUrl.split ('/')
    cBaseUrl = ''
    //for (var n = 0; n < a.length - 1; n ++) cBaseUrl += a [n] + '/'
    var win = window.open(cBaseUrl+url, "BuldingSurplus", "modal,width="+width+",height="+height+",left="+aXY[0]+",top="+aXY[1]+',resizable=no,status=no"')
    return win

  }
}
