﻿

function DisplayBar(b)
{
	if (b =='y')
		document.getElementById("trBar").style.display = "";
	else
		document.getElementById("trBar").style.display = "none";
}

// style="DISPLAY: none"
function DisplayByID(obj,b)
{
	if (b =='y')
		document.getElementById(obj).style.display = "";
	else
		document.getElementById(obj).style.display = "none";
}	

function DisplayByIDAuto(obj)
{
	if(document.getElementById(obj).style.display == '')
		document.getElementById(obj).style.display = "none";
	else
		document.getElementById(obj).style.display = "";
}	

function LoadiFrame(trid,iframeid,iframeurl)
{
	if(document.getElementById(trid).style.display == '')
	{
		document.getElementById(trid).style.display = "none";
	}
	else
	{
		document.getElementById(trid).style.display = "";
		document.getElementById(iframeid).src = iframeurl;
	}
}


function newwindow(link,width,height) {
	window.open(link,'_blank','location=no, toolbar=no, menubar=no, status=no, scrollbars=yes, resizable=no, width=' + width + ', height=' + height );
} 


function newdialog(link,width,height) {
    //window.showModalDialog("openwin.html",self,'modal=yes,width=775,height=700,resizable=no,scrollbars=no');			
    window.showModalDialog(link,self,'modal=yes,width=' + width + ',height=' + height + ',resizable=no,scrollbars=no');			
	//window.open(link,'newwin','location=no, toolbar=no, menubar=no, status=no, scrollbars=yes, resizable=no, width=' + width + ', height=' + height );
	window.status = '123';
} 
			
			
function CopyValue(sData){
	  var format = "Text";
    var clipboard = window.clipboardData;
    clipboard.setData(format, sData);
	alert('網址已複製到剪貼簿!');
}			

function ImageReSizeMax( sImgurl, iMaxWidth , iMaxHeight )
{
    var oImageOriginal ;
    
	oImageOriginal = document.createElement( 'IMG' ) ;	// new Image() ;
	oImageOriginal.src = sImgurl.src ;
	srcHeight = oImageOriginal.height;
	srcWidth = oImageOriginal.width;


	if(srcWidth >= iMaxWidth)
	{
		srcHeight = iMaxWidth * srcHeight / srcWidth;
		srcWidth = iMaxWidth;
	}

	if(srcHeight >= iMaxHeight)
	{
		srcWidth = iMaxHeight * srcWidth / srcHeight;
		srcHeight = iMaxHeight;
	}

	if(srcWidth == 0) srcWidth = iMaxWidth;
	if(srcHeight == 0) srcHeight = iMaxHeight;

	srcHeight = Math.round(srcHeight);
	srcWidth = Math.round(srcWidth);
	vSpac = Math.round((iMaxHeight - srcHeight) / 2)
	hSpac = Math.round((iMaxWidth - srcWidth) / 2)


	sImgurl.width = srcWidth;
	sImgurl.height = srcHeight;
	sImgurl.vspace = vSpac;
	sImgurl.hspace = hSpac;
	
    //alert(srcWidth + ',' + srcHeight);
	
    return 0;
}

function ImageReSizeMaxNoSpac( sImgurl, iMaxWidth , iMaxHeight )
{
    var oImageOriginal ;

	oImageOriginal = document.createElement( 'IMG' ) ;	// new Image() ;
	oImageOriginal.src = sImgurl.src ;
	srcHeight = oImageOriginal.height;
	srcWidth = oImageOriginal.width;

	if(srcWidth > iMaxWidth)
	{
		srcHeight = iMaxWidth * srcHeight / srcWidth;
		srcWidth = iMaxWidth;
	}

	if(srcHeight > iMaxHeight)
	{
		srcWidth = iMaxHeight * srcWidth / srcHeight;
		srcHeight = iMaxHeight;
	}

	if(srcWidth == 0) srcWidth = iMaxWidth;
	if(srcHeight == 0) srcHeight = iMaxHeight;

	srcHeight = Math.round(srcHeight);
	srcWidth = Math.round(srcWidth);

	sImgurl.width = srcWidth;
	sImgurl.height = srcHeight;
	
    return 0;
}


function isMaxLength(obj,mlength){
	//TextArea Max Length
	//var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : maxlength
	//Setting On onkeyup Event
	if (obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}


function snaponload(sid,swidth,bid)
{
	//check special snapid, then do some action , like: resize etc..
	switch (bid) 
	{ 
		case "block8":
		case "block9":
		case "block12":
		case "block13":
		case "block14":
		case "block15": 
			swidth = 150; 
			break; 
		case "block2": 
		case "block3":
		case "block5":
		case "block6":
		case "block10":
		case "block11":
		case "block16": 
			swidth = 310; 
			break; 
		case "block4":
		case "block7": 
			swidth = 620; 
			break; 
		default : 
			swidth = 150; 
	} 	

	//alert(bid + " ~ " + swidth);

	if(sid == 'Snap0_9' || false)
	{
		//620*265
		//### miniroom size ratio(450,200)
		srcWidth = 620;
		srcHeight = 265;

		//### padding pixel, not to 100%
		iMaxWidth = swidth-10;

		//### Don't change blow line order..
		srcHeight = iMaxWidth * srcHeight / srcWidth;
		srcWidth = iMaxWidth;
		//### End

		srcHeight = Math.round(srcHeight);
		srcWidth = Math.round(srcWidth);
	
		//alert(srcWidth + "," + srcHeight);

		document.getElementById('miniroom').width = srcWidth-8;
		document.getElementById('miniroom').height = srcHeight-1;
	}
	if(sid == 'Snap0_1' || false)
	{
		iMaxWidth = Math.round(swidth * 0.85);
		ImageReSizeMaxNoSpac(document.getElementById('ImgMyPic'), iMaxWidth , iMaxWidth );
	}
	
	//Don't remove it.
	if(document.getElementById('sspanelitem') != null)
	{
		document.getElementById('sspanelitem').style.visibility = 'visible';
	}

}
function snapmovemouseup()
{
	//alert('snapmovemouseup~~~');
}

function ResizeiFrameHeight(obj) 
{
	parent.document.getElementById(obj).height = document.body.scrollHeight;
}

MyHTMLEncode = function(text)
{
	if ( typeof( text ) != "string" )
		text = text.toString() ;

	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/'/g, "&#39;") ;

	return text ;
}


				var preid = "";
				
				function preidnow()
				{
					return preid;
				}
				
				function playtrial(trialid)
				{
					var objwmp = "wmptrial";
					var sURL;
					
					if(parent.window.parent.topframe)
						parent.window.parent.topframe.window.Stop();	
					
					if(window.parent.topframe)
						window.parent.topframe.window.Stop();	
						
					if(window.iFrameShop)
					{
						if(window.iFrameShop.document.getElementById(objwmp))
						{
							window.iFrameShop.document.getElementById(objwmp).controls.stop();
							var idx = window.iFrameShop.preidnow();
							if(idx!='')
								window.iFrameShop.document.getElementById('play'+window.iFrameShop.preidnow()).src = "/myhp/giftshop/image/music_play.gif";
						}
					}
					
					if(window.parent)
					{
						if(window.parent.document.getElementById(objwmp))
						{
							window.parent.document.getElementById(objwmp).controls.stop();
							var idx =  window.parent.preidnow();
							if(idx!='')
								window.parent.document.getElementById('play'+window.parent.preidnow()).src = "/myhp/giftshop/image/music_play.gif";
						}
					}
									
					if(preid != trialid)
					{
						if(preid != "")
							document.getElementById('play'+preid).src = "/myhp/giftshop/image/music_play.gif";
							document.getElementById('play'+trialid).src = "/myhp/giftshop/image/music_stop.gif";
						
							document.getElementById(objwmp).URL = "../PlayListTrial.aspx?trialid=" + trialid;
							document.getElementById(objwmp).controls.play();
					}
					else
					{
						//alert(document.getElementById(objwmp).playState);
						if(document.getElementById(objwmp).playState == 3)
						{	//play
							document.getElementById(objwmp).controls.stop();
							document.getElementById('play'+trialid).src = "/myhp/giftshop/image/music_play.gif";
						}
						else
						{
							document.getElementById(objwmp).URL = "../PlayListTrial.aspx?trialid=" + trialid;
							document.getElementById('play'+trialid).src = "/myhp/giftshop/image/music_stop.gif";
							document.getElementById(objwmp).controls.play();
						}

					}
					
					preid = trialid;
				}
	
	
	var srcColor = '';
	
	function OnChangeColor(sFunc, obj, sChgColor) {
			//obj.id
			//obj.innerText
		
			switch (sFunc) {
				case 'on':
					if( sChgColor == '') {
						sChgColor = '#7d7d7d';
						//sChgColor = '#FDEFDE';						
					}
					srcColor = obj.style.backgroundColor;
					obj.style.backgroundColor = sChgColor;
					obj.style.color = 'blue';
					break;
				case 'off':
					obj.style.backgroundColor = srcColor;
					obj.style.color = '#000000';
					//if (sColor.indexOf("," + obj.style.backgroundColor + ",") == -1) {
					//	obj.style.backgroundColor = 'white';
				    //}
					break;
			}	
	}		
	
function SelectCheckbox_All(name, value)
{
    var forminputs;
    forminputs = document.getElementsByTagName('input');

    for (i = 0; i < forminputs.length; i++)
    {
        //regex here to check name attribute
        var regex = new RegExp(name, "i");
        if (regex.test(forminputs[i].getAttribute('name')))
        {
            if (value == '1')
            {
                forminputs[i].checked = true;
            }
            else
            {
                forminputs[i].checked = false;
            }
        }
    }
}	
