// JavaScript Document

function StrCode(str){
	if(encodeURIComponent) return encodeURIComponent(str);
	if(escape) return escape(str);
}

function UnStrCode(str){
	if(decodeURIComponent ) return decodeURIComponent (str);
	if(unescape) return unescape(str);
}

function Trim(s){
	var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null)?"":m[1];
}

function HtmlEncode(text){
	var re = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}

function HtmlDecode(text){
	var re = {'&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}

function gid(id){
	return document.getElementById ? document.getElementById(id) : null;
}

function gna(id){
	return document.getElementsByName ? document.getElementsByName(id) : null;
}

function gname(name){
	return document.getElementsByTagName ? document.getElementsByTagName(name) : new Array();
}

function InitRequest(){
	var C_req = null;
	try{
		C_req = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			C_req = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(oc){
			C_req = null;
		}
	}
	if (!C_req && typeof XMLHttpRequest != "undefined"){
		try{
			C_req = new XMLHttpRequest();
		}catch(fa){
			alert("Please use IE or firefox!");
			C_req = null;
		}
	}
	return C_req;
}

function PostRequest(url, data){
	var AjaxRequestObj = InitRequest();
	if (AjaxRequestObj != null){
		AjaxRequestObj.onreadystatechange = function (){
			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText){
				ProcessAjaxData(AjaxRequestObj.responseText);
			}
		};
		AjaxRequestObj.open("POST", url, true);
		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		AjaxRequestObj.send(data);
	}
}

function Browser(){
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.isOP = false;
	this.isSF = false;
	ua = navigator.userAgent.toLowerCase();
	s = "opera";
	if ((i = ua.indexOf(s)) >= 0){
		this.isOP = true;
		return;
	}
	s = "msie";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		return;
	}
	s = "netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		return;
	}
	s = "gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		return;
	}
	s = "safari";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isSF = true;
		return;
	}
}

function ProcessAjaxData(data){
	eval(data);
}

function ScreenConvert() {
	var browser = new Browser();
	var objScreen = gid("ScreenOver");
	if(!objScreen) var objScreen = document.createElement("div");
	var oS = objScreen.style;
	objScreen.id = "ScreenOver";
	oS.display = "block";
	oS.top = oS.left = oS.margin = oS.padding = "0px";
	if (document.body.clientHeight)	{
		var wh = document.body.clientHeight + "px";
	}else if (window.innerHeight){
		var wh = window.innerHeight + "px";
	}else{
		var wh = "100%";
	}
	oS.width = "100%";
	oS.height = wh;
	oS.position = "absolute";
	oS.zIndex = "3";
	if ((!browser.isSF) && (!browser.isOP)){
		oS.background = "";
	}else{
		oS.background = "";
	}
	oS.filter = "alpha(opacity=40)";
	oS.opacity = 40/100;
	oS.MozOpacity = 40/100;
	document.body.appendChild(objScreen);
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "hidden";
}

function ScreenClean(){
	var objScreen = document.getElementById("ScreenOver");
	if (objScreen) objScreen.style.display = "none";
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "visible";
}

var t_DiglogX,t_DiglogY,t_DiglogW,t_DiglogH;

function DialogLoc(){
	if (window.innerHeight){
		var ww = window.innerWidth;
		var wh = window.innerHeight;
		var bgX = window.pageXOffset;
		var bgY = window.pageYOffset;
	}else{
		var dde = document.documentElement;
		var ww = dde.offsetWidth;
		var wh = dde.offsetHeight;
		var bgX = dde.scrollLeft;
		var bgY = dde.scrollTop;
		bgY = bgY ? bgY : document.body.scrollTop;
	}
	t_DiglogX = (bgX + ((ww - t_DiglogW)/2));
	t_DiglogY = (bgY + ((wh - t_DiglogH)/2));
}

function DialogShow(showdata,ow,oh,w,h){
	var objDialog = document.getElementById("DialogMove");
	if (!objDialog) objDialog = document.createElement("div");
	t_DiglogW = ow;
	t_DiglogH = oh;
	DialogLoc();
	objDialog.id = "DialogMove";
	var oS = objDialog.style;
	oS.display = "block";
	oS.top = t_DiglogY + "px";
	oS.left = t_DiglogX + "px";
	oS.margin = "0px";
	oS.padding = "0px";
	oS.width = w + "px";
	oS.height = h + "px";
	oS.position = "absolute";
	oS.zIndex = "5";
	oS.background = "#FFF";
	oS.border = "solid #000 3px";
	objDialog.innerHTML = showdata;
	document.body.appendChild(objDialog);
}

function DialogHide(){
	ScreenClean();
	var objDialog = document.getElementById("DialogMove");
	if (objDialog) objDialog.style.display = "none";
}

function ShopAuth(title, type) {
	ScreenConvert();
	var title = UnStrCode(title);

	var str1 = "Melamine laminate is a printed paper product that is saturated with melamine resin and then thermally fused under heat and pressure to a substrate. When fully cured the laminate is highly resistant to scratching and staining.";
	var str2 = "MDF - Medium density fiberboard is a manufactured panel product that is made from recycled wood fibers. The fibers are electro-statically charged and combined with resins under pressure to produce sheets that are stable, smooth, and uniform. MDF is generally considered the best substrate for laminating wood veneers.";
	var str3 = "RTF - Rigid Thermo Foil is a Vinyl product that is heated and then applied under vacuum pressure to a door or drawer surface until it conforms to every detailed route and contour.  RTF is scratch resistant and extremely durable.";
	var str4 = "Roseburg Forest Products SkyBlend&#8482; is SCS (Scientific Certification Systems) and EPP (Environmentally Preferable Products) certified 100% pre-consumer recycled wood fiber particleboard that has no Urea Formaldehyde added during the manufacturing process. <br />(<a href=\"./uploadfiles/SkyBlend.pdf\" target=\"_blank\">PDF Fact Sheet</a>)";
	
	var str;
	switch (type) {
		case 1: str = str1; break;
		case 2: str = str2; break;
		case 3: str = str3; break;
		case 4: str = str4; break;
	}

	var AJAX_LoginBody="<div id=\"DialogTitle\"><div id=\"DialogTitleText\">" + title + "</div><div id=\"DialogTitleBtn\" onclick=\"return DialogHide();\" onmouseover=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #000000';\" onmouseout=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #EEE';\"></div></div><div id=\"DialogContent\">" + str + "</div>";
	DialogShow(AJAX_LoginBody,320,220,400,200);	
}

function myCustomerizeAlert(title, content, padding_right, padding_bottom, width, height) {
	ScreenConvert();
	var title = UnStrCode(title);
	var content = content;
	if (padding_right == null) padding_right = 320;
	if (padding_bottom == null) padding_bottom = 220;
	if (width == null) width = 400;
	if (height == null) height = 200;

var AJAX_LoginBody="<div id=\"DialogTitle\"><div id=\"DialogTitleText\">" + title + "</div><div id=\"DialogTitleBtn\" onclick=\"return DialogHide();\" onmouseover=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #000000';\" onmouseout=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #EEE';\"></div></div><div id=\"DialogContent\">" + content + "</div>";
	DialogShow(AJAX_LoginBody,padding_right,padding_bottom,width,height);	
}
