// JavaScript Document
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=1000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  FadeInImage(pictureID,nextImage,backgroundID);
  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}
/*function right(e) {
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("Sorry, right click is not allowed here.");
return false;
}
else if (e.button==2||e.button==3) {
      e.preventDefault();
      e.stopPropagation();
      alert("Sorry, right click is not allowed here.");
      return false;
}
return true;
}
var callback = function(event){ 
	if(event.preventDefault) {  
		event.preventDefault(); 
	} // Other code...
}
document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
if (!document.all) document.onclick=right;
if (!document.all) document.ondblclick=right;
window.onmousedown=right;
window.onmouseup=right;
*/

function popImg(path) {
	var windowprops ="top=50px,left=50px,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no";
	TheWin = window.open('','image',windowprops);
	TheWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>');
	TheWin.document.write('<head><meta HTTP-EQUIV="imagetoolbar" CONTENT="no"><title>Enlarged Photo<\/title>');
	TheWin.document.write('<\/head><body style="overflow:scroll;margin:0px;background-color:#ffffff;" onload="window.opener.popImgfitSize();">');
	TheWin.document.write('<img src="' + path + '" alt="" title="">');
	TheWin.document.write('<\/body><\/html>');
	TheWin.document.close();
}

function popWin(path, width, height) {
	var windowprops ="top=400px,left=400px,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, width="+width+", height="+height+"";
	TheWin = window.open(path,'actionWindow',windowprops);
}

function popImgfitSize() {
	if (navigator.appName.indexOf("Microsoft")>=0) 
		TheWin.window.resizeBy(TheWin.document.images[0].width-TheWin.document.body.clientWidth, TheWin.document.images[0].height-TheWin.document.body.clientHeight); 
	else TheWin.window.resizeBy(TheWin.document.images[0].width-TheWin.window.innerWidth+18, TheWin.document.images[0].height-TheWin.window.innerHeight);
	TheWin.focus();
}
function changeLargePhoto(photoId) {
	document.getElementById("largePhotoArea").innerHTML = largeList[photoId][0];
	document.getElementById("largePhotoDesc").innerHTML = largeList[photoId][1];
}
function copyToClipboard(txt) {
     if(window.clipboardData)
     {
         window.clipboardData.clearData();
         window.clipboardData.setData("Text", txt);
     }
     else if(navigator.userAgent.indexOf("Opera") != -1)
     {
         window.location = txt;
     }
     else if (window.netscape)
     {
         try {
             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         }
         catch (e)
         {
             alert("!!被瀏覽器拒絕！\n請在瀏覽器地址欄輸入about:config'並回車\n然後將signed.applets.codebase_principal_support'設置為true'");
         }
         var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
         if (!clip)
             return;
         var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
         if (!trans)
             return;
         trans.addDataFlavor("text/unicode");
         var str = new Object();
         var len = new Object();
         var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
         var copytext = txt;
         str.data = copytext;
         trans.setTransferData("text/unicode",str,copytext.length*2);
         var clipid = Components.interfaces.nsIClipboard;
         if (!clip)
             return false;
         clip.setData(trans,null,clipid.kGlobalClipboard);
     }
     return true;
}

function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage('http://hahaxiao.cn');
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
    alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage','http://hahaxiao.cn');
 }
}
//Check column height
function adjustColumnHeight(){
	var maxHeight;
	var lftHeight = document.getElementById('col_lft').clientHeight;
	var midHeight = document.getElementById('col_mid').clientHeight;
	var rhtHeight = document.getElementById('col_rht').clientHeight;
	maxHeight = Math.max(lftHeight, midHeight);
	maxHeight = Math.max(maxHeight, rhtHeight);
	document.getElementById('col_mid').style.height = maxHeight+"px";
}
function filterDate(month){
	var daySelBox = document.getElementById('day');

	daySelBox.innerHTML = "";
	appendOptionLast("日", "", daySelBox);
	if(month.value == 4 || month.value == 6 || month.value == 9 || month.value == 11){
		for(i=1;i<=30;i++){
			appendOptionLast(i, i, daySelBox);
		}
	}else if(month.value == 2){
		var dayNo =(document.getElementById('year').value%4==0)?29:28;
			for(i=1;i<=dayNo;i++){
			appendOptionLast(i, i, daySelBox);
			}
	}else{
		for(i=1;i<=31;i++){
			appendOptionLast(i, daySelBox);
		}
	}
}
function subStringTextArea(obj, wordCount){
	if ( obj.value.length > wordCount){
		obj.value = obj.value.substring(0, wordCount);
		alert("字数已达上限。");
		return false;
	}
}

function appendOptionLast(numText, numvalue, obj)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = numText;
  elOptNew.value = numvalue;

  try {
    obj.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    obj.add(elOptNew); // IE only
  }
}

