var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2-10:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
win.focus();}

function setpic(file){

var filepath = file;

extArray = new Array(".mp3", ".mpg", ".mpeg", ".wma", ".wmv", ".wav", ".mid", ".asf" );
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();

pic = true;
for (var i = 0; i < extArray.length; i++) {
	if (extArray[i] == ext) {
		pic = false;
		}
}
	
if(pic) {

	layerpic.style.visibility = "hidden";
	layerpic.style.visibility = "";

	layerpic.innerHTML = "<IMG NAME=thepic SRC='" +filepath+ "' onmouseover='imgResize(this.width)'>";
	var high = document.thepic.height;
	var wide = document.thepic.width;
	if (wide > 250){
		layerpic.innerHTML = "<IMG NAME=thepic SRC='" +filepath+ "' width='250' onmouseover='imgResize(this.width)'>";
		layerpic.style.visibility = "visible";}
	else{layerpic.style.visibility = "visible";}

	topic.imgw.value=wide;

}
else {
	layerpic.style.visibility = "hidden";
	layerpic.style.visibility = "";

	layerpic.innerHTML = "<Embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/\" src=\"" +filepath+ "\"  ShowControls=1 AutoStart=True ShowStatusBar=1>";
	layerpic.innerHTML += "<br>รูปแบบการเล่น: <INPUT TYPE=\"checkbox\" NAME=\"autoStart\" VALUE=\"True\"> เล่นอัตโนมัติ&nbsp;<INPUT TYPE=\"radio\" NAME=\"loop\" VALUE=\"False\" checked> ครั้งเดียว&nbsp;<INPUT TYPE=\"radio\" NAME=\"loop\" VALUE=\"True\"> วนซ้ำๆ";
}

}

function doPreview() {
	var src = document.topic.fileupload.value;
	if (document.topic.fileupload.value.charAt(1)==":") src = "file:/" + src;
		document.thepic.src=src;

		var high = document.thepic.height;
		var wide = document.thepic.width;
		if (wide > 250){document.thepic.width=250;}

		topic.imgw.value=wide;
}

function imgResize(w){
if(w>250){
	topic.imgw.value=w;
	document.thepic.width=250;
	}
}

function setCookie(name, value, expires, path, domain, secure){
	var path="/"
	var dCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = dCookie;}

function fixDate(date) {
	 var base = new Date(0)
	 var skew = base.getTime()
	 if (skew > 0)
	 date.setTime(date.getTime() - skew)
  }

	function getCookie(name,num) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
	return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
	cookieEndIndex = document.cookie.length
	//return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
	var mm=unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
	strarray = mm.split('-//-'); // splits value on a separator
	
	if(strarray[0]!=''){
		if (num == 0){	
			document.write ('value='+strarray[0])
		}
		if (num == 1){	
			document.write ('value='+strarray[1])
		}
		if (num == 2){	
			document.write ('value='+strarray[2])
		}
	  }
	}

function printit(){  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}

function ExpandLayer(id, height)
{
	eval("var obj=document.all."+id);
	if(obj.style.height == "100%") {
		obj.style.height = height;
		document.all.imgExpand.src = "/images/expand.gif";
	}
	else {
		obj.style.height="100%";
		document.all.imgExpand.src = "/images/collapse.gif";
	}
}

	function mOvr(src,clrOver) {
		if (!src.contains(event.fromElement)) {
			src.style.cursor = 'hand';
			src.bgColor = clrOver;
		}
	}
	function mOut(src,clrIn) {
		if (!src.contains(event.toElement)) {
			src.style.cursor = 'default';
			src.bgColor = clrIn;
		}
	}
	function mClk(src) {
		if(event.srcElement.tagName=='TD'){
			src.children.tags('A')[0].click();
		}
	}

function DropShadow(elem){
	var i;
	var size=5;
	var color='#606060';
	for (i=size; i>0; i--)
	{
		var shadow = document.createElement('div');
		shadow.style.position = 'absolute';
		shadow.style.left = (elem.style.posLeft -i+9) + 'px';
		shadow.style.top = (elem.style.posTop -i+9) + 'px';
		shadow.style.width = elem.offsetWidth +i+i-size-5+ 'px';
		shadow.style.height = elem.offsetHeight +i+i-size-5+ 'px';
		shadow.style.zIndex = elem.style.zIndex - i;
		shadow.style.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		shadow.style.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		elem.insertAdjacentElement('afterEnd', shadow);
	}
}
