function  open3d(d) {
	popframe("/assets/optima/"+d+"/model.htm", 638, 481, "3D Viewer");
}

function openDownloads( l ) {
	popframe( "productdownloads.asp?ids="+l, 500, 500, "Downloads");
}

function showBoreSelector(pr_id,table,tag,type){

	switch(type){
		case 1:
			var pg='boreselector1.asp';
			break;
		case 2:
			var pg='boreselector2.asp'
			break;
	}

	popframe("/"+pg+"?lang=&tag="+tag+"&id="+pr_id+"&table="+table, 400, 440, "Bore Selector" );
}

function showDownLoads(pr_ref,tag){
	popframe("/downloadspop.asp?lang=&tag="+tag+"&ref="+pr_ref, 400, 400, "Downloads")
}

function popframe(u, w, h, t){ //url, width, height, title

	w = w || 300;
	h = h || 400;
	u = u || "about:blank";

	//get some window details
	var st = document.documentElement.scrollTop;
	var sl = document.documentElement.scrollLeft;
	var wh = window.innerHeight || document.documentElement.clientHeight;
	var ww = window.innerWidth || document.documentElement.clientWidth;


	var d = document.createElement("div");
	d.id = "blanker";
	d.style.height = document.documentElement.scrollHeight+30+"px";
	d.style.width = document.documentElement.scrollWidth+"px";

	document.body.appendChild(d);

 	var p = document.createElement("div");
 	p.id = "popwin";
 	p.style.width = w+"px";
 	p.style.height = h+"px";
 	p.style.top = Math.round((wh-h)/2)+st+"px";
 	p.style.left = Math.round((ww-w)/2)+sl+"px";

 	document.body.appendChild(p);

 	var hd = document.createElement("div");
 	hd.id = "p_header";
 	hd.style.height = "22px";
 	var hp = document.createElement("p");
 	hp.innerHTML = t || "";
 	hd.appendChild(hp);
 	var hc = document.createElement("div");
 	hc.id = "p_header_close";
 	hc.innerHTML = "x"
 	hc.onclick = closepop;//function(){
 		//document.body.removeChild(p)
 		//document.body.removeChild(d)

 	//}
 	hd.appendChild(hc);

 	p.appendChild(hd)

	var ifr = document.createElement("iframe");
	ifr.id = "p_ifr";
	ifr.setAttribute("frameborder", "0");
	ifr.style.height = (h-22)+"px";
 	ifr.src = u;

	p.appendChild(ifr)

	return false;
}
function closepop() {
	document.body.removeChild(document.getElementById('popwin'))
 	document.body.removeChild(document.getElementById('blanker'))
}

function validateSearch( f ){
	if(f.q.value.length>=1){
		return(true)
	}
	return(false)
}


window.addEvent( "domready", function(){

	var contextItems = $$(".contextitem");
	var contextLinks = $$(".contextlink");
	var contextMenus = $$(".contextmenu");

	contextLinks.each( function( el ) {
		el.addEvent( "click", function( e ) {

			var ev = new Event( e );
			contextItems.each( function( item ) {
				item.className= "contextitem";
			});
			ev.target.getParent().className= "contextitemactive";
			ev.target.getParent().getElement(".contextmenu").setStyle( "left", ( ev.client.x - 10 )+"px" );
		});
	});
	contextItems.each( function( el ) {
		el.addEvent( "mouseleave", function( e ) {
			this.className= "contextitem";
		});
	});
	contextMenus.each( function( el ) {
		el.addEvent( "click", function( e ) {
			this.parentNode.className= "contextitem";
		});
	});

});



// a little function that returns a little random saltiness
function salt(len){
	var s = "";
	var n = len || 5;
	for( var i = 0; i < n; i++ ) {
		s += String.fromCharCode(Math.floor((Math.random()*26)+97));
	}
	return s;
}


var briefcase = {
	ajax: null,
	signedIn: true,

	createTransport: function(){
	try {
			this.ajax = new XMLHttpRequest();
		}
		catch (e) {
			try {
				this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				try {
					this.ajax = new ActiveXObject('Msxml2.XMLHTTP');
				}
				catch (e) {
					return false;
				}
			}
		}
	},

	add: function(t, l, d){ //type, lable, data
		if( !this.signedIn ) {
			alert("You need to be signed in to use My Huco");
			return false;
		}
		var nl = l;

		while( nl == "" || l == null ) {
			nl = window.prompt("What would you like this item to be called?\nThe label you supply will appear in My Huco");
		}

		this.createTransport();
		this.ajax.open('GET', 'myhucoengine.asp?action=add&type='+t+'&label='+nl+'&data='+d);
		this.ajax.onreadystatechange = this.updateBriefcase.bind(this);
		this.ajax.send(null);
	},

	updateBriefcase: function(){
		switch( this.ajax.readyState ) {
		case 1:
			$('myhucocontent').set( 'html', "<blink>Loading...</blink>" );
			break;
		case 4:
			$('myhucocontent').set( 'html', this.ajax.responseText );
			break;
		}
	}
}

function myHucoInfo() {
alert("coming soon");
}


function retrieveCSResults(data) {
	document.cookie = "couplingselector = " + unescape(data);
	window.location = "couplingselector.asp";
}

