﻿var unvalid     = "/\\:*?<>|" + '"'
var validen     = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var validnum    = "0123456789";
var validennum  = validen + validnum

/*Google AD*/
var google_ad_client    = "pub-5569957955993587";
var google_ad_width     = 120;
var google_ad_height    = 240;
var google_ad_format    = google_ad_width+"x"+google_ad_height+"_as";
var google_ad_type      = "text_image";
var google_ad_channel   = "";
var google_color_border = "F7F3F7";
var google_color_bg     = "F7F3F7";
var google_color_link   = "FF6633";
var google_color_text   = "8C8C8C";
var google_color_url    = "008000";

/*
檢查E-mail信箱帳號是否格式正確
*/
function Check_MailValue(p_str){
  var i;
  if (p_str == '') {
    return false;
  };
  if (p_str.indexOf("@") == -1 || p_str.indexOf(".") == -1) {
    return false;
  };
  if (p_str.indexOf(".", p_str.indexOf("@")+1) == -1){
    return false;
  };
  if (p_str.lastIndexOf (".") == p_str.length - 1){
    return false;
  };
  if (p_str.indexOf("@.") >= 0) {
    return false;
  };
  if (p_str.indexOf(".@") >= 0) {
    return false;
  };
  if (p_str.indexOf("..") >= 0) {
    return false;
  };
  if (p_str.indexOf(" ") != -1) {
    return false;
  };
  var aii = 0;
  for (i = 0;i < p_str.length; i ++) {
    if (p_str.substr(i,1) == '@'){
      aii ++;
    };
  };
  if (aii > 1){
    return false;
  };
  for (i = 0;i < p_str.length; i ++) {
    if ((p_str.charCodeAt(i) >= 33 && p_str.charCodeAt(i) <= 44) || p_str.charCodeAt(i) == 47 || (p_str.charCodeAt(i) >= 58 && p_str.charCodeAt(i) <= 63) || (p_str.charCodeAt(i) >= 91 && p_str.charCodeAt(i) <= 94) || p_str.charCodeAt(i) == 96 || (p_str.charCodeAt(i) >= 123 && p_str.charCodeAt(i) <= 126)){
      return false;
    };
  };
  for (i = 0;i < p_str.length; i ++) {
    if (p_str.charCodeAt(i) >= 128) {
      return false;
    };
  };
  return true;
};

/*
將字串去掉前後空白
*/
function trim(inputString) {
  if (typeof inputString != "string") { return inputString; };
  var retValue = inputString;
  var ch = retValue.substring(0, 1);
  while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
  };
  ch = retValue.substring(retValue.length-1, retValue.length);
  while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
  };
  while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
  };
  return retValue;
};

/*
檢查輸入textarea是否完全無文字
*/
function chktextareaisempty(chkobj){
  var tmpa;
  tmpa = chkobj.value;
  if (tmpa == ''){return true;};
  //set up a variable that will hold your form 
  var needfields = ''; 
  //var checkval = tempform.yourTextArea.value; 
  tmpa = tmpa.replace(/\r\n/g,"");
  tmpa = tmpa.replace(/\r/g,"");
  tmpa = tmpa.replace(/\n/g,"");
  tmpa = trim(tmpa); 
  if (tmpa == ''){
    return true;
  } else {
    return false;
  };
};

/*
檢查輸入文字物件是否皆符合帶入的sample字串
*/
function vaildstringobj(sample,testobj){
  var teststr, vaildstr;
  vaildstr = sample;                        //'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  teststr = trim(testobj.value);           //form1.Pwd.value;
  if (teststr == '')
  {
    return false;
  };
  for (i=0;i<teststr.length;i++){    
    if (vaildstr.indexOf(teststr.substr(i,1)) < 0){      
      return false;
    };    
  };
  return true;
};

/*
檢查輸入文字字串是否皆符合帶入的sample字串
*/
function vaildstring(sample,teststr){
  var vaildstr;
  vaildstr = sample;                        //'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  teststr = trim(teststr);
  if (teststr == '')
  {
    return false;
  };
  for (i=0;i<teststr.length;i++){    
    if (vaildstr.indexOf(teststr.substr(i,1)) < 0){      
      return false;
    };    
  };
  return true;
};

/*
檢查輸入的網址格式是否有誤
針對非空白的網址才做檢查
*/
function chkURLAddress(chkURLvalue){
  chkURLvalue = trim(chkURLvalue);
  if (chkURLvalue == '')
  {
    return true;
  };
  chkURLvalue = chkURLvalue.toLowerCase()
  if ((chkURLvalue.substr(0,7) != "http://") && (chkURLvalue.substr(0,8) != "https://"))
  {
    return false; 
  } else {
    if (chkURLvalue.substr(0,7) == "http://")
    {
      chkURLvalue = chkURLvalue.substr(7);
    };
    if (chkURLvalue.substr(0,8) == "https://")
    {
      chkURLvalue = chkURLvalue.substr(8);
    };
  };
  if (chkURLvalue == '')
  {
    return true;
  };
   if (chkURLvalue.indexOf(".") == -1) {
    return false;
  };
  if (chkURLvalue.lastIndexOf (".") == chkURLvalue.length - 1){
    return false;
  };
  return true;
};

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 * mm/dd/yyyy
 */
// Declaring valid date character, minimum year and maximum year
  var dtCh= "/";
  //var minYear = 1900;
  //var maxYear = 2100;

  function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    };
    // All characters are numbers.
    return true;
  };

  function stripCharsInBag(s, bag){
    var i;
      var returnString = "";
      // Search through string's characters one by one.
      // If character is not in bag, append to returnString.
      for (i = 0; i < s.length; i++){   
          var c = s.charAt(i);
          if (bag.indexOf(c) == -1) {returnString += c};
      };
      return returnString;
  };

  function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
      // EXCEPT for centurial years which are not also divisible by 400.
      return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
  };
  function DaysArray(n) {
    for (var i=1; i <= n; i++) {
      this[i] = 31
      if ((i==4) || (i==6) || (i==9) || (i==11)) {this[i] = 30};
      if (i==2) {this[i] = 29};
     }; 
     return this
  };

  function isDate(dtStr, minYear, maxYear){
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
      if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    };
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
      alert("日期格式必須為 : mm/dd/yyyy")
      return false
    };
    if (strMonth.length<1 || month<1 || month>12){
      alert("請輸入正確的月份")
      return false
    };
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
      alert("請輸入正確的日期")
      return false
    };
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
      alert("年份請輸入四位數字並介於 " + minYear + " 和 " + maxYear + "之間" )
      return false
    };
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
      alert("請輸入正確的日期格式" + " --- " + dtStr)
      return false
    };
    return true
  };
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function display_image(fileInfo,inputname) {
  var filename = trim(fileInfo);
  var features = ",scrollbars=1,location=0,menubar=0,status=1,toolbar=0,resizable=1";
  features = ",scrollbars=1,status=1,resizable=1"
  if(filename != ""){
    myWindow = window.open("", "Preview", "width=600,height=450,left=0,top=0"+features);
    myWindow.document.open();
    myWindow.document.write("<HTML><HEAD>");
    myWindow.document.write("<TITLE>Preview</TITLE>");
    myWindow.document.write("</HEAD><BODY topmargin=0 rightmargin=0 leftmargin=0 bottommargin=0 BGCOLOR=#FFFFFF TEXT=#000000>");
    myWindow.document.write("<img src='" + filename + "'>");
    myWindow.document.write("<HR><INPUT TYPE='button' VALUE='關閉視窗'" + " onClick='window.close()'>");
    myWindow.document.write("</BODY></HTML>");
    myWindow.document.close();
    myWindow.focus();
  } else {
    alert ("請先選擇一張圖片");
    inputname.focus();
  };
};


function myisDate(dtStr, minYear, maxYear) {
  var daysInMonth = DaysArray(12)
  var pos1=dtStr.indexOf(dtCh)
  var pos2=dtStr.indexOf(dtCh,pos1+1)
  var strMonth=dtStr.substring(0,pos1)
  var strDay=dtStr.substring(pos1+1,pos2)
  var strYear=dtStr.substring(pos2+1)
  strYr=strYear
  if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
  if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
  for (var i = 1; i <= 3; i++) {
    if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
  };
  month=parseInt(strMonth)
  day=parseInt(strDay)
  year=parseInt(strYr)
  if (pos1==-1 || pos2==-1){
    alert("日期格式必須為 : mm/dd/yyyy")
    return false
  };
  if (strMonth.length<1 || month<1 || month>12){
    alert("請輸入正確的月份")
    return false
  };
  if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
    alert("請輸入正確的日期")
    return false
  };
  if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
    alert("年份請輸入四位數字並介於 " + minYear + " 和 " + maxYear + "之間" )
    return false
  };
  if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
    alert("請輸入正確的日期格式" + " --- " + dtStr)
    return false
  };
  return true
};

//開啟一個新視窗
function popwin(theURL, wname, W, H){
  var dowin = theURL != "" ? true : false;
  var features = ",fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1";
  features = ",status=1,scrollbars=1"
  if (dowin) {
    var windowW = W;
    var windowH = H;
    //check the window screen max size
    if (window.screen.width < windowW){
      windowW = window.screen.width;
      windowH = window.screen.height;
    };
    if (window.screen.width < 800){
      windowW = Math.ceil(window.screen.width * 0.9) ;
      windowH = Math.ceil(window.screen.height * 0.9) ;
    };
    var windowX = Math.ceil( (window.screen.width - windowW) / 2 );
    var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
    if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) {isie=true} else {isie=false}
    if (isie) { windowH=windowH+20+2; windowW=windowW+2; };
    //s = ",width="+W+",height="+H;
    s = ",width="+windowW+",height="+windowH;
    if (isie && (navigator.userAgent.toLowerCase().indexOf("win")!=-1) ) {
      splashWin = window.open( theURL , wname, s+features);
      splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
      splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
      return splashWin;
      //splashWin.document.open();
      //splashWin.document.write( chromeFRMhtml );
      //splashWin.document.close();
    } else {
      features = ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
      features= "";
      var splashWin = window.open(theURL, wname, s+features, true);
      return splashWin;
    };
  } else {
    alert ("請確定代入的網址!");
  };
};

//開啟一個新視窗可以不置中的
// X < 0 && Y < 0 ===> 置中
function popwin1(theURL, wname, X, Y, W, H){
    var dowin = theURL != "" ? true : false;
    var features = ",fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0"
    if (dowin) {
      var windowW = W;
      var windowH = H;
      //check the window screen max size
      if (window.screen.width < windowW){
        windowW = window.screen.width;
        windowH = window.screen.height;
      };
      
      if (window.screen.width < 800){
          windowW = Math.ceil(window.screen.width * 0.9) ;
          windowH = Math.ceil(window.screen.height * 0.9) ;
      };
        
      if ((X < 0) && (Y < 0)){  //置中
        var windowX = Math.ceil( (window.screen.width - windowW) / 2 );
        var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
      } else {
        var windowX = Math.ceil( X );
        var windowY = Math.ceil( Y );
      };        

      if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) {isie=true} else {isie=false};
      if (isie) { windowH=windowH+20+2; windowW=windowW+2; };
      //s = ",width="+W+",height="+H;
      s = "left="+windowX+",top="+windowY+",width="+windowW+",height="+windowH;
      features = ",scrollbars=1"
      if (isie && (navigator.userAgent.toLowerCase().indexOf("win")!=-1) ) {
          splashWin = window.open( theURL , wname, s+features);
          splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
          splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
          return splashWin;
          //splashWin.document.open();
          //splashWin.document.write( chromeFRMhtml );
          //splashWin.document.close();
      } else {
        features = ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
        features = "";
        var splashWin = window.open(theURL, wname, s+features, true);
        return splashWin;
      };
  } else {
    alert ("請確定代入的網址!");
  };
};

//開啟一個新視窗可以不置中的
// X < 0 && Y < 0 ===> 置中
function popwin2(theURL, wname, X, Y, W, H){
    var dowin = theURL != "" ? true : false;
    var features = ",fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
    if (dowin) {
        var windowW = W;
        var windowH = H;
        
        //check the window screen max size
        if (window.screen.width < windowW){
          windowW = window.screen.width;
          windowH = window.screen.height;
        };
        if (window.screen.width < 800){
            windowW = Math.ceil(window.screen.width * 0.9) ;
            windowH = Math.ceil(window.screen.height * 0.9) ;
        };
        if ((X < 0) && (Y < 0)){  //置中
          var windowX = Math.ceil( (window.screen.width - windowW) / 2 );
          var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
        } else {
          var windowX = Math.ceil( X );
          var windowY = Math.ceil( Y );
        };
        if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) {isie=true} else {isie=false}
        if (isie) { windowH=windowH+20+2; windowW=windowW+2; };
        //s = ",width="+W+",height="+H;
        s = "left="+windowX+",top="+windowY+",width="+windowW+",height="+windowH;
        if (isie && (navigator.userAgent.toLowerCase().indexOf("win")!=-1) ) {
            splashWin = window.open( theURL , wname, s+features);
            splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
            splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
            return splashWin;
            //splashWin.document.open();
            //splashWin.document.write( chromeFRMhtml );
            //splashWin.document.close();
        } else {
        features = ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
        features = "";
        var splashWin = window.open(theURL, wname, s+features, true);
        return splashWin;
      };
  } else {
    alert ("請確定代入的網址!");
  };
};

//開啟一個新視窗
//居中、無status
function popwin3(theURL, wname, W, H){
  var dowin = theURL != "" ? true : false;
  if (dowin) {
    var windowW = W;
    var windowH = H;
        
    //check the window screen max size
    if (window.screen.width < windowW){
      windowW = window.screen.width;
      windowH = window.screen.height;
    };
      
    if (window.screen.width < 800){
        windowW = Math.ceil(window.screen.width * 0.9) ;
        windowH = Math.ceil(window.screen.height * 0.9) ;
    };
        
    var windowX = Math.ceil( (window.screen.width - windowW) / 2 );
    var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
          
    s = ",width="+windowW+",height="+windowH;
    features = ",fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
    features = ",scrollbars=1,resizable=1";
    splashWin = window.open( theURL , wname, s+features);
    splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
    splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
    return splashWin;
      
  } else {
    alert ("請確定代入的網址!");
  };
};


function popmusicwin(theURL, wname, X, Y, W, H){
  //var whoAmI = navigator.appName; 
  //var whatAmI = parseInt(navigator.appVersion.charAt(0)); 
  var features = ",channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0";
  features = "";
  var dowin = theURL != "" ? true : false;
  if (dowin) {
    var windowW = W;
    var windowH = H;
    if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) {isie=true} else {isie=false};
    //if (isie) { windowH=windowH+20+2; windowW=windowW+2; };
    //s = ",width="+W+",height="+H;
    s = "left="+X+",top="+Y+",width="+windowW+",height="+windowH;
    //if (whoAmI == "Netscape" && whatAmI >= 4) {
    //  netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
    var splashWin = window.open( theURL , wname, s+features, true);
    //  netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserWrite");
    //} else {
    //  var splashWin = window.open( theURL , wname, s+",fullscreen=no,toolbar=no,location=no,directories=no,titlebar=no,status=no,menubar=no,scrollbars=no,resizable=no", true);
    //};
    
    return splashWin;
  } else {
    alert ("請確定代入的網址!");
  };
};

function CopyTxt(thisvalue){
  if (window.clipboardData) { 
    window.clipboardData.setData("text", thisvalue);
  }else{
        var flashcopier='_____flashcopier______'; 
        if(!document.getElementById(flashcopier)) { 
            var divholder=document.createElement('div'); 
            divholder.id=flashcopier; 
            document.body.appendChild(divholder); 
        } 
        document.getElementById(flashcopier).innerHTML=''; 
        var divinfo='<embed src="/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(thisvalue)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>'; 
        document.getElementById(flashcopier).innerHTML=divinfo;
  } 
  return false; 
}

function CopyTxtOOXX(thisvalue){
  //var format = "Text";
  var ccdata = thisvalue;
  //var clipboard = window.clipboardData;
  //clipboard.setData(format, ccdata);
  //window.clipboardData.setData("Text", ccdata);
	if (window.clipboardData)
	{
		window.clipboardData.setData('Text', ccdata);
	}
	else if (window.netscape)
	{
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		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;
		var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
		str.data=ccdata;
		trans.addDataFlavor('text/unicode');
		trans.setTransferData('text/unicode',str,ccdata.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clipid) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	else
	{
		return false;
	}
	return false;
};

function SetCookie(name,value,expiredays,spath )
{
  var ctoday = new Date();
  ctoday.setDate(ctoday.getDate() + expiredays );
  var strcookie = "";
  strcookie = name + "=" + escape( value ) + ";";
  if (spath == ""){
    strcookie += "path=/;";
  } else {
    strcookie += "path=" + spath + ";";
  };
  if (expiredays > 0){
    strcookie += "expires=" + ctoday.toGMTString() + ";";
  };
  
  document.cookie = strcookie ;   //name + "=" + escape( value ) + "; path=/; expires=" + ctoday.toGMTString() + ";";
  
};
function eraseCookie(name)
{
  SetCookie(name,"",-1,"/");
};

function GetCookie(name)
{
  var cnameOfCookie = name + "=";
  var x = 0;
  while ( x <= document.cookie.length )
  {
    var y = (x + cnameOfCookie.length);
    if ( document.cookie.substring( x, y ) == cnameOfCookie ) {
      if ( (cendOfCookie = document.cookie.indexOf( ";", y )) == -1 )
        cendOfCookie = document.cookie.length;
      return unescape( document.cookie.substring( y, cendOfCookie ) );
    };
    x = document.cookie.indexOf( " ", x ) + 1;
    if ( x == 0 )
      break;
  };
  return "";
};

function preview_image(fileInfo,inputname,swidth,sheight) {
  var filename = fileInfo;
  var features = ",scrollbars=0,location=0,menubar=0,status=0,toolbar=0,resizable=0";
  features = "";
  var extension = filename.substring(filename.length - 3, filename.length);
  if(((extension.toLowerCase() == 'jpg') || (extension.toLowerCase() == 'gif')) && filename != ""){
    previewWin = window.open("", "previewWin", "width=" + swidth + ",height=" + sheight + ",left=0,top=0"+features);
    previewWin.document.open();
    previewWin.document.write("<HTML><HEAD>");
    previewWin.document.write("<TITLE>Preview</TITLE>");
    previewWin.document.write("</HEAD><BODY BGCOLOR=FFFFFF TEXT=000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>");
    previewWin.document.write("<img src=\"" + filename + "\" alt=\"點我!!!按我!!!就關視窗!!!!\" onClick=\"javascript:window.close()\">");
    //previewWin.document.write("<HR><INPUT TYPE=\"button\" VALUE=\"Close Window\"" + " onClick=\"window.close()\">");
    previewWin.document.write("</BODY></HTML>");
    previewWin.document.close();
    previewWin.focus();
  } else {
    alert ("Image Error!!");
    if (inputname != ''){
      inputname.focus();
    };
  };
};
function imgzoom(o) {
  if(event.ctrlKey) {
    var zoom = parseInt(o.style.zoom, 10) || 100;
    zoom -= event.wheelDelta / 12;
    if(zoom > 0) {
      o.style.zoom = zoom + "%";
    };
    return false;
  } else {
    return true;
  };
};
function _ge(id){
  el = document.getElementById(id);
  return el;
};
function do_showwho(whotype, whochannel, whowhat, whosd){
  var hhwin ;
  var features = ",resizable=no,scrollbars=yes";
  features = ",scrollbars=1";
  var winurl = "/who/whowho.asp";
  var whoparam = "?type=" + whotype;        //種類    collection/vote/play
  whoparam = whoparam + "&channel=" + whochannel;      //music/video/design/diary/
  whoparam = whoparam + "&outsid=" + whowhat;
  whoparam = whoparam + "&sd=" + whosd;
  //var hhwin = window.open(winurl+whoparam,"whowho","top=0,left=0,width=620,height=580"+features);
  var hhwin = do_showwhowin(winurl+whoparam,"whowho","top=0,left=0,width=620,height=580",features);
  hhwin.focus();
};
function do_showwhowin(gurl, gname, s, features ){
  var sswin = window.open(gurl,"whowho",s+features);
  return sswin;
};
function setGoogleParams(_a,_b,_c,_d,_e,_f,_g,_h){
  google_ad_client    = "pub-5569957955993587";
  google_ad_width     = 120;
  google_ad_height    = 240;
  google_ad_format    = google_ad_width+"x"+google_ad_height+"_as";
  google_ad_type      = "text_image";
  google_ad_channel   = "";
  google_color_border = "F7F3F7";
  google_color_bg     = "F7F3F7";
  google_color_link   = "FF6633";
  google_color_text   = "8C8C8C";
  google_color_url    = "008000";

  google_ad_width     = (_a == null) ? google_ad_width : _a;
  google_ad_height    = (_b == null) ? google_ad_height : _b;
  google_ad_format    = (_c == null) ? google_ad_format : _c;
  google_color_border = (_d == null) ? google_color_border : _d;
  google_color_bg     = (_e == null) ? google_color_bg : _e;
  google_color_link   = (_f == null) ? google_color_link : _f;
  google_color_text   = (_g == null) ? google_color_text : _g;
  google_color_url    = (_h == null) ? google_color_url : _h;
}

function encodeMyHtml(__a) {
 var encodedHtml = "";
 encodedHtml = escape(__a);
 encodedHtml = encodedHtml.replace(/\//g,"%2F");
 encodedHtml = encodedHtml.replace(/\?/g,"%3F");
 encodedHtml = encodedHtml.replace(/=/g,"%3D");
 encodedHtml = encodedHtml.replace(/&/g,"%26");
 encodedHtml = encodedHtml.replace(/@/g,"%40");
 return encodedHtml;
}
function reencodeMyMyHtml(__a) {
 var rea = __a;
 rea = rea.replace(/&amp;/g,"&");
 rea = rea.replace(/&lt;/g,"<");
 rea = rea.replace(/&gt;/g,">");
 return rea;
}
function reencodeMyMaHtml(__a) {
 var rea = __a;
 rea = rea.replace(/&/g,"&amp;");
 rea = rea.replace(/</g,"&lt;");
 rea = rea.replace(/>/g,"&gt;");
 return rea;
}

function ranAjax(ranType){
	var URL = "/randomAjax.asp?type=" + ranType + "";
	new Ajax.Request(URL, {   
			method: 'get',
			encoding:'UTF-8',   
			onSuccess: function(transport) {     
				//alert (transport.responseText);
				eval(transport.responseText);
			}
		}
	);   
}

	function checkR(objId,putId,putId2,num){		//檢查關鍵字函數，objId是提交的表單id，putId是關鍵字存放表單，putId2關鍵字序號存放表單，num檢查出幾個關鍵字即退出
		if ((typeof(myArray_keyr)!='undefined')&&(typeof(myArray_keysno)!='undefined')){
			var r, re;
			var str;
			var i;
			var j = 0;
			var k = 0;
			str = simplized(document.getElementById(objId).value).toLowerCase( );
			for(var i=0; i<myArray_keyr.length; i++){
				eval("r=/" + UnEncode(myArray_keyr[i]).toLowerCase( ) + "/i;");
				temp = str.match(r);
				if(temp!= null){
					//alert(UnEncode(myArray[i]));
					//alert(temp);
					//logKey(UnEncode(myArray_keysno[i]),temp,linkStr,msid);
					k++;
					document.getElementById(putId).value = document.getElementById(putId).value + ";" + myArray_keysno[i];
					document.getElementById(putId2).value = document.getElementById(putId2).value + ";" + temp;
					//alert(myArray_keyr[i]);
					if((k>=num)&&(num!=0)){
						break;
					}
				}
			}	
		}
	}
	function logKey(sno,keyStr,linkStr,msid){
		var url = 'check_keywords_act.asp';
		//alert($('BNN2').value);
		//window.open(url);
		var pars = "sno="+sno+"&keyStr="+keyStr+"&linkStr="+linkStr+"&msid="+msid;
		//alert(pars);
		new Ajax.Request(url,
					{
						method:'post',
						encoding:'UTF-8',
						parameters:pars,
						onSuccess:function(transport){
							alert('完成！！！' );
						},
						onFailure:function(){
							alert('哎呀!!!!出錯啦~~~~');
						}
					});
	}

	function UnEncode(str){
		str = unescape(str);
		var strTemp = "";
		for(var j=0;j<str.length;j++){
			strTemp = strTemp + str.slice(str.length-j-1,str.length-j);
		}
		return strTemp;
	}
/* 給 FLASH 開新視窗用的 */
function swfopenwindow(argg,winname,features){
	var swfwin = window.open(argg,winname,features);
	swfwin.focus();
}

function chkEmail(str){		//檢查郵件地址格式是否正確
	var r;
	r = /^[a-z]([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_\.]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/
	//alert(r.test(str));
	return r.test(str)
}

function chkUrl(str){		//檢查Url地址格式是否正確
	var r;
	r = /((http|https|ftp):(\/\/|\\\\)((\w)+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)/
	//alert(r.test(str));
	return r.test(str)
}

/*載入圖片*/
function SVLoadimage(vstr,vw,vh) {
	var imgs = '<img src="' + vstr + '" border="0"';
	if (vw){ imgs += ' width="'+ vw +'"';}
	if (vh){ imgs += ' height="'+ vh +'"';}
	imgs += '>';
	document.getElementById(vstr).innerHTML = imgs;
	document.getElementById(vstr).onclick = "javascript:return false;";
	return false;
};
function SVLoadShowallimg(vw,vh){
	var objs = document.getElementsByName('SVLoadImg');
	for (ij=0; ij<objs.length; ij++) {
		SVLoadimage(objs[ij].id,vw,vh);
	};
	return false;
};