// parameterHandler.js made by Humandream, Inc. at 2003.08.20
// Please do not input the 2bytes characters for foreign web-agent.
// This skin version is v1.2

// To open with the "startpage" parameter, insert the below strings at the BODY onLoad tag.
// onLoad="setStartPage( getStartPage() );"

/***
	[How to set up for the startpage]
	1. default1.html : <script language="JavaScript" src="appendix/parameterHandler.js"></script>
	2. default1.html : <BODY onLoad="JavaScript:setStartPage( getStartPage() )">
***/

function showFrame(frameID){
	hideOtherFrame(frameID);
	var oFrame = document.all[frameID];
	if(oFrame.style.visibility=="hidden"){
		if(frameID=="editLink"){
			var url = document.location.href;
			if(url.indexOf("albummaniac.com") >=0){
				var baseCol = document.all.tags('BASE');
				if(baseCol.length > 0)
					oFrame.src = "/gallery/dBook/"+strWork+".asp?baseURL=" + baseCol[0].href ;
				else{
					url = url.substring(0, url.lastIndexOf("/") + 1);
					oFrame.src = "/gallery/dBook/"+strWork+".asp?baseURL=" + url ;
				}
			}else{
				alert("albummaniac.com¿¡¼­¸¸ ¸µÅ©ÆíÁýÀÌ °¡´ÉÇÕ´Ï´Ù");
			}
		}else{
			if(oFrame.src==""){
				oFrame.src = frameID+".htm";
			}
		}
		
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;
		oFrame.style.visibility="visible";
		try{
			document.frames(frameID).moveAndResizeFrame("init");
		}catch(e){}
	}else{
		oFrame.style.left = 0;
		oFrame.style.top = 0;
		oFrame.style.width = 10;
		oFrame.style.height = 10;		
		oFrame.style.visibility="hidden";	
		if(frameID=="editLink"){
			oFrame.src="";
			document.dBook.handle_removeLink();
			document.dBook.handle_editLink(false);
		}
	}
}

function hideOtherFrame(frameID){
	var oFrame;
	var arrFrame = new Array("indexList","editLink","search");
	for(var i=0; i<arrFrame.length; i++){
		oFrame = document.all[arrFrame[i]];
		if(arrFrame[i] != frameID &&  oFrame.style.visibility=="visible"){
			oFrame.style.left = 0;
			oFrame.style.top = 0;
			oFrame.style.width = 10;
			oFrame.style.height = 10;		
			oFrame.style.visibility="hidden";						
		}
	}
}

function moveAndResizeFrame(frameID, pos, w, h){
	var oFrame = document.all[frameID];	
	var oBndRct = document.body.getBoundingClientRect();
	var limitHeight = oBndRct.bottom-oBndRct.top-(nSkinTop+nSkinBottom);
	var fw, fh;
	
	if(limitHeight<100)	limitHeight=100;
	
	if(pos=="init")
		pos = curPos;
	else
		curPos = pos;	
		
	if( limitHeight <= h){
		fw = w+18;
		fh = limitHeight;
	}else{
		fw = w;
		fh = h;
	}

	if(pos=="left_top"){
		iPosX = nSkinLeft;
		iPosY = nSkinTop;
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;
	}else if(pos=="right_top"){
		iPosX = oBndRct.right - oBndRct.left - fw - nSkinRight;
		iPosY = nSkinTop;			
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;			
	}else if(pos=="left_bottom"){
		iPosX = nSkinLeft;
		iPosY = oBndRct.bottom - oBndRct.top - fh- nSkinBottom;
		if(iPosY<nSkinTop){
			iPosY = nSkinTop;
			fh = nSkinTop - oBndRct.bottom+oBndRct.top+nSkinBottom;
		}
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;		
	}else if(pos=="right_bottom"){
		iPosX = oBndRct.right - oBndRct.left - fw - nSkinRight;
		iPosY = oBndRct.bottom - oBndRct.top - fh - nSkinBottom;
		if(iPosY<nSkinTop){
			iPosY = nSkinTop;
			fh = nSkinTop - oBndRct.bottom+oBndRct.top+nSkinBottom;
		}
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;			
	}
	
		oFrame.style.pixelWidth = fw;
		oFrame.style.pixelHeight = fh;
}

function HD_eidtLink(mode, linkID, left, top, right, bottom,page){
	try{
		document.frames("editLink").eidtLink(mode, linkID, left, top, right, bottom,page);
	}catch(e){
//			alert("error editLink");
	}
}

function getParameter( strParamName )				
{
	//  input : String, Parameter name from HTTP GET Paramemeter.
	// output : String, Parameter value which is parsed.
	
	var strParamValue = "[null]";
    var objWin = this;
    
    try 
    {
        while ( objWin != null )
        {
    		//  var strThisURL = objWin.location.href.toLowerCase();
    		var strThisURL = objWin.location.href + "";
    		
            if( -1 != strThisURL.indexOf( strParamName + "=",0 ) )
            {
        		var strParam = strThisURL.substring( strThisURL.indexOf(strParamName + "=",0), strThisURL.length );
        		if ( strParam == null || strParam == "" )		break;
        		var arrParam = strParam.split( "&" );
        		strParamValue = arrParam[0].substring( arrParam[0].indexOf(strParamName + "=",0)+strParamName.length+1, arrParam[0].length );
                break;        		
    	    }
      	    if ( objWin.parent==null || objWin==window.top ) 	break;
    	    else objWin = objWin.parent;
        }
    } 
    catch (e) 
    {
    	//	alert( "Parameter parsing failure.\nPlease check the frameset of HTML." );
    }
    
    return strParamValue;
}

//	for debug : alert( "Extracted Parameter Value = '" + getParameter( 'abc' ) + "'" );
//  USAGE : <script language="JavaScript" src="getParameter.js"></script>


function getStartPage()				
{
	var strStartPage = "1";			// default start page = 1
	
	strStartPage = getParameter( "startpage" );
    
    if ( isNaN( strStartPage ) )	strStartPage = "1";		// exception handler for non-digit type string.
    
    return strStartPage;
}

//	for debug : alert( "Extracted StartPage = '" + getStartPage() + "'" );


function setStartPage( strStartPage ) 
{	
	if ( strStartPage == null || strStartPage == "" )  
		strStartPage = "1";			// default start page = 1
	
	if ( document.dBook == null )	return;		// please insert ErrMsg?

	document.dBook.handle_inputGotoPage( strStartPage );
}


function getMailingParam()		// get params for 3DDM
{
	var objWin = this;
	var strThisHREF = "";

	try
	{
		while ( objWin != null )
		{
			strThisHREF = objWin.location.href;    			
			// In case of MSN Mail, the exception occurred at objWin.location.href exception.

			if( -1 != strThisHREF.indexOf("RcptEmail=",0) )		break;
			if ( objWin.parent==null || objWin==window.top ) 	break;
			else objWin = objWin.parent;
		}
	}
	catch (e)	
	{
		// In case of MSN Mail, an exception occurred at objWin.location.href exception.
	}
    
    return strThisHREF;
}
//	alert( "Extracted StartPage = '" + getStartPage() + "'" );
//	alert( "getMailingParam() = " + getMailingParam() );


function getCRMData()
{
	var strData;
	strData = getURLData();
	if (strData != "" && getCookieData() != "")
	{
		strData = strData + "&"
	}
	strData = strData + getCookieData();
	return strData;
}


function getURLData( )				
{
	//  input : String, Parameter name from HTTP GET Paramemeter.
	// output : String, Parameter value which is parsed.
	var strParamName = "dbookdata";
	var strResult = "";
    var objWin = this;
	var strThisURL = "";
    
    try 
    {
        while ( objWin != null )
        {
			strThisURL = objWin.location.href + "";		
			// In case of MSN Mail, an exception occurred at objWin.location.href exception.
    		
            if( -1 != strThisURL.indexOf( strParamName + "=",0 ) )
            {
//				alert("strParamName : " + strParamName);
        		strResult = strThisURL.substring( strThisURL.indexOf("?",0) + 1, strThisURL.length );
//				alert("strResult : " + strResult);
        		if ( strResult != null && strResult != "" )		break;
    	    }
      	    if ( objWin.parent==null || objWin==window.top ) 	break;
    	    else objWin = objWin.parent;
        }
    } 
    catch (e)	
    {
		// In case of MSN Mail, an exception occurred at objWin.location.href exception.
    }
//	alert("strParamName : " + strParamName);
//	alert("strParamValue : " + strParamValue);
    return strResult;
}


function getCookieData()
{
	var strCookie = "" + document.cookie;
	re = /\;\s+/gi;
	strCookie = strCookie.replace(re, "&");
//	alert("cookie : " + strCookie);
	return strCookie;
}
