///////// JScript File
/********************************************************************************/
/*							Common Functions   									*/
/********************************************************************************/
function ShowFlash(filepath, width, height)
{
	document.write(" <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+width+"\" height=\""+height+"\" VIEWASTEXT> ");
	document.write(" 		<param name=\"movie\" value=\""+filepath+"\"> ");
	document.write(" 		<param name=\"quality\" value=\"high\"> ");
	document.write(" 		<param name=\"wmode\" value=\"transparent\"> ");
	document.write(" 		<param name=\"menu\" value=\"false\" > ");
	document.write("        <param name=\"allowScriptAccess\" value=\"always\" >");
	document.write(" 		<embed src=\""+filepath+"\" allowScriptAccess=\"always\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" wmode=\"transparent\" menu=\"false\" ></embed> ");
	document.write(" </object> ");
}



function createCookie(name,value,days) {
	    if (days) {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
	    //window.location.href = 'http://mabinogi.nexon.net'; 
    }
    



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}


//Check Email
function isEmail(strEmail)
{
	var emailfilter = /^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
	if(strEmail == "")
		return false;
	else if(!emailfilter.test(strEmail))
		return false;
	
	return true;
}




// isNaN() 
function num_chk(obj)
{
	if( obj.value.length > 0 )
	{
		if(isNaN(obj.value)) 
		{
			openModalDialog(550, null, null);
			obj.value = "";
			obj.focus();
			return;
		}
	}
}

// isNaN() 
function num_chk_alert(obj)
{
	if( obj.value.length > 0 )
	{
		if(isNaN(obj.value)) 
		{
			alert('You may only use numbers for your Security PIN.');
			obj.value = "";
			obj.focus();
			return;
		}
	}
}


// Trim : 
function Trim(strInput)
{
    return(LTrim(RTrim(strInput)));
}

// LTrim : 
function LTrim(strInput)
{
    var i = 0;
    while (strInput.substring(i,i+1) == ' ')  i = i + 1;
    return strInput.substring(i);
}

// RTrim : 
function RTrim(strInput)
{
    var i = strInput.length - 1;
    while (i >= 0 && strInput.substring(i,i+1) == ' ') i = i - 1;
    return strInput.substring(0,i+1);
}




//Open Modal Dialog
function openModalDialog(msgCid, winWidth, winHeight)
{
    if(!winWidth || 'undefined' == typeof(winWidth))
      var winWidth = 300;
    if(!winHeight || 'undefined' == typeof(winHeight))
      var winHeight = 280;
      
	window.showModalDialog("/PAGE.ASPX?PART=/Common/PopupAlert&cid="+msgCid, null, "dialogWidth:"+winWidth+"px; dialogHeight:"+winHeight+"px; edge:sunken; center:yes; resizable:no; status:no; help:no; scroll:no;");
}


//Open Popup Dialog
function openPopupDialog(msgCid, winWidth, winHeight)
{
    if(!winWidth || 'undefined' == typeof(winWidth))
      var winWidth = 300;
    if(!winHeight || 'undefined' == typeof(winHeight))
      var winHeight = 220;
      
    var win= null;
	var winl = (screen.width-winWidth)/2;
	var wint = (screen.height-winHeight)/2;
	var settings  ='height='+winHeight+',';
		settings +='width='+winWidth+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='resizable=no';
		win = window.open("/PAGE.ASPX?PART=/Common/PopupAlert&cid="+msgCid, "PopupAlert" ,settings);
	
	if(parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}


//Open Popup Dialog
function openPopupWindow(URL, winWidth, winHeight)
{
    if(!winWidth || 'undefined' == typeof(winWidth))
      var winWidth = 300;
    if(!winHeight || 'undefined' == typeof(winHeight))
      var winHeight = 220;
      
    var win= null;
	var winl = (screen.width-winWidth)/2;
	var wint = (screen.height-winHeight)/2;
	var settings  ='height='+winHeight+',';
		settings +='width='+winWidth+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='resizable=no';
		win = window.open(URL, "PopupPage" ,settings);
	
	
	if(parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}


//Open Modal Dialog
function openPopupModalDialog(URL, winWidth, winHeight)
{
    if(!winWidth || 'undefined' == typeof(winWidth))
      var winWidth = 300;
    if(!winHeight || 'undefined' == typeof(winHeight))
      var winHeight = 280;
      
	window.showModalDialog(URL, null, "dialogWidth:"+winWidth+"px; dialogHeight:"+winHeight+"px; edge:sunken; center:yes; resizable:no; status:no; help:no; scroll:no;");
}

function addBookmark(url,title ) {
        if (window.sidebar) { // firefox
              window.sidebar.addPanel(title, url,"");
        } else if( document.all ) { //MSIE
                window.external.AddFavorite( url, title);
        } else {
               alert("Sorry, your browser doesn't support this");
        }
}
//Set BookMark
function bookmark()
{
	window.external.AddFavorite('http://maplestory.nexon.net/', 'MapleStory - Global English Site');
}

//Trim Method
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

function chkFirstInput(strType)
{

	if (strType == "Main")
		var objEmail	= (document.all["/Controls/SiteMain/MainLogin:tbEmail"]);
	else
		var objEmail	= (document.all["/Controls/SiteMain/SubLogin:tbEmail"]);
	
	if (objEmail.value == "ID")	
		objEmail.value = "";
	else
		return false;
}

function frmLogin(strType)
{
	
	if (strType == "Main")
	{	
		var objEmail	= (document.all["/Controls/SiteMain/MainLogin:tbEmail"]);
		var objPass		= (document.all["/Controls/SiteMain/MainLogin:tbPassword"]);
	}
	else
	{	
		var objEmail	= (document.all["/Modules/Accounts/SubLogin:tbEmail"]);
		var objPass		= (document.all["/Modules/Accounts/SubLogin:tbPassword"]);
	}
	
	if (objEmail.value.trim() == "" | objEmail.value.trim() == "ID") 
	{
		openModalDialog(200, null, null);
		objEmail.value = "";
		objEmail.focus();
		return false;
	}
	
	if (objPass.value.trim() == "") 
	{
		openModalDialog(201, null, null);
		objPass.value = "";
		objPass.focus();
		return false;
	}
	return true;	
}

function showhide(what,img){

	if (what != undefined)
	{
		if (what.style.display=='none')
			what.style.display=''; 
		else
			what.style.display='none' 		
	}
	if (img != undefined)
		img.src='http://nxcache.nexon.net/maplestory/common/images/menu_on.gif';
}

function SetMenu()
{
	var strPathName;
	
	strPathName = location.href;
	var bbs_header = document.getElementById('BoardHeader');
	if (bbs_header== null || bbs_header=='undefined')
	{
        if (strPathName.indexOf("&") > 0 )
	        strPathName = strPathName.substring(0 , strPathName.indexOf("&"));
	
	
	    if (strPathName.indexOf("=") > 0 )
		    strPathName = strPathName.substring( strPathName.indexOf("=")+1 );
    }else
    {
        //if (strPathName.indexOf("boardNo=103") > 0 )
		//    strPathName = "//"+"update";
		//else 
        if (strPathName.indexOf("boardNo=20") > 0 )
		    strPathName = "//"+"event";
        else
            strPathName = "//"+document.getElementById('BoardHeader').getAttribute('title');
            
    }
    
	var path = strPathName.split("/");
	strPathName = path[2];
	
	
	if (strPathName == 'Game') //GameRank
	{
		strPathName = location.href;
		strPathName = strPathName.substring(strPathName.indexOf("&")+1);
		var path2 = strPathName.split("=");
		strPathName = path2[1];
	}
	if (strPathName == 'WeddingPhotoUp')
	{0
	    strPathName = 'Event';
	}
	if (strPathName == 'LeafGearMisc')
	{
	    strPathName = 'LeafGear';
	}
	
	showhide(document.getElementById(strPathName), document.getElementById(strPathName + '_img'));
	
	
}

//inquiry submit
function SubmitForm()
{
	if (document.frmWZ.all['/Modules/Support/Inquiry:h'].value==0)
	{
		if ( document.frmWZ.all['/Modules/Support/Inquiry:txtTitle'].value == "" ) 
		{
			alert('Please enter the title.');
		}
		else if (document.frmWZ.all['/Modules/Support/Inquiry:txtContent'].value == "")
		{
			alert('Please describe the bug in detail..');
		}
		else
		{
			document.frmWZ.all['/Modules/Support/Inquiry:h'].value=1;
			__doPostBack('/Modules/Support/Inquiry:btnOk','');
		}
		
	}
}
//inquiry submit
function SubmitCannotLogin()
{
	if (document.frmWZ.all['/Modules/Support/CannotLogin:h'].value==0)
	{
		if (document.frmWZ.all['/Modules/Support/CannotLogin:txtLoginID'].value == "")
		{
			alert('Please enter your login id.');
		}
		else if ( document.frmWZ.all['/Modules/Support/CannotLogin:txtEmail'].value == "" ) 
		{
			alert('Please enter Email address.');
		}
		else if ( document.frmWZ.all['/Modules/Support/CannotLogin:txtEmail'].value.indexOf("@") <= 0 || 
					document.frmWZ.all['/Modules/Support/CannotLogin:txtEmail'].value.indexOf(".") <= 0 ||
					document.frmWZ.all['/Modules/Support/CannotLogin:txtEmail'].value.length < 5   )
		{
			alert('Please enter your email address under this format: maple@wizet.com.');
		}	
		else if (document.frmWZ.all['/Modules/Support/CannotLogin:ddlBirthYear'].options[document.frmWZ.all['/Modules/Support/CannotLogin:ddlBirthYear'].selectedIndex].value == "")
		{
			alert('Please select the year of birth.');
		}
		else if (document.frmWZ.all['/Modules/Support/CannotLogin:txtContent'].value == "")
		{
			alert('Please enter the Text.');
		}
		else
		{
			document.frmWZ.all['/Modules/Support/CannotLogin:h'].value=1;
			__doPostBack('/Modules/Support/CannotLogin:btnOk','');
		}
		
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	if (selObj.options[selObj.selectedIndex].value != '')
	{
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}

function BanFunctionKey()
{
	if( event.ctrlKey == true || event.altKey == true )
	{
		alert("Don't use CtrlKey and AltKey");
		return false;
	}
}

function PermitCharacter(obj)
{ 
	
	str = obj.value;
	if (str.length > 0) { 
        for (i = 0; i < str.length; i++) { 
            if ((str.charAt(i) < '0' || str.charAt(i) > '9') &&
			   (str.charAt(i) < 'A' || str.charAt(i) > 'Z') &&
			   (str.charAt(i) < 'a' || str.charAt(i) > 'z'))
            { 
				alert("You may only use numbers and character");
				obj.value = "";
				obj.focus();
				return true;
            }
        }
    }
}
/********************************************************************************/
/*							Frame Part      									*/
/********************************************************************************/
function checkParent()
{
//	var strHref = document.location.href;
//	if( parent == document )
//	{
//		var strURL = strHref.substr( strHref.indexOf( "?" ) );
//		location.href = '/' + strURL;
//	}
}

function loadframe()
{	
//	
//	var strHref = document.location.href;
//	var strURL = strHref.substr( strHref.indexOf( "?" ) );
//	var objMainFrame = document.frames.frmMain;
//	var objTopFrame =  document.frames.frmTop;

//	if( strURL.substring(0,7) != "http://" )
//		objMainFrame.location.href = '/WZ.ASPX' + strURL;
}

/********************************************************************************/
/*							Logout Event	   									*/
/********************************************************************************/

function Logout(objType)
{
	
	if (parent.frmTop.mxconn)
	{
		con = parent.frmTop.mxconn;
		con.ResetCookie();
	}
	
	if (objType == "Main")
		__doPostBack('/Controls/SiteMain/MainLogin:btnLogout','');
		
	else if (objType == "Sub")
		__doPostBack('/Controls/SiteMain/SubLogin:btnLogout','');
		
	else if (objType == "XLogin")
		__doPostBack('UserPageControl:XLogin:btnLogout','');
		
	return true;
}


/********************************************************************************/
/*							Pack Man & Game   									*/
/********************************************************************************/





function getCookies(nameVal) 
{
	var numCookie = document.cookie.length
	var oven = document.cookie.split("; ")
	for(var i = 0; i<oven.length; i++) 
	{
		if(oven[i].indexOf("=") != -1) 
			cookieName = oven[i].substring(0,oven[i].indexOf("="))
		else 
			cookieName = oven[i]
		
		if(cookieName == nameVal) 
		{
			if(oven[i].indexOf("=") != -1) 
				cookieVal = oven[i].substr(oven[i].indexOf("=")+1)
			else 
				cookieVal = ""
			
			return cookieVal
		}
	}
	return ""
}


//Block User
function blockuser()
{
	openPopupModalDialog('/PAGE.ASPX?PART=/Common/Error/PopupBlock', 560, 315);	
	return false;
}


//Javascript¸¦ defalse 
function setCookie(name,value)
{         
    document.cookie = "JSUse=" + name + ";" + name + "=" + escape(value) +";domain =nexon.net";
}

function openPopupWindow(URL, winWidth, winHeight)
{
    if(!winWidth || 'undefined' == typeof(winWidth))
      var winWidth = 900;
    if(!winHeight || 'undefined' == typeof(winHeight))
      var winHeight = 740;
      
    var win= null;
	var winl = (screen.width-winWidth)/2;
	var wint = (screen.height-winHeight)/2;
	var settings  ='height='+winHeight+',';
		settings +='width='+winWidth+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		//settings +='resizable=no';
		settings +='scrollbars=no';
		win = window.open(URL, "PopupPage" ,settings);
	
	if(parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}


// Leaf Gear - voyage
function leafGearViewer300Swf1nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_300x250Swf"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer300Swf(swfValue);
	    
}

function leafGearViewer300Swf2nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_300x250Swf2nd"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer470Swf(swfValue);
}

function leafGearViewer300Swf3nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_300x250Swf3nd"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer300Swf(swfValue);	    
}

function leafGearViewer300Swf4nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_470x90Swf4nd"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer470Swf(swfValue);	    
}

function leafGearViewer300Swf5nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_470x90Swf5nd"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer300Gif(swfValue);	    
}

function leafGearViewer300Swf6nd()
{
	var publicID = "";  
	var obj	= (document.all["secret_470x90Swf6nd"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer470Gif(swfValue);	    
}

function leafGearViewer300Swf7nd()
{
	var publicID = "";  
	var obj	= (document.all["anti_300x250_1"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer300Gif(swfValue);	    
}

function leafGearViewer300Swf8nd()
{
	var publicID = "";  
	var obj	= (document.all["anti_470x90_1"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer470Gif(swfValue);	    
}

function leafGearViewer300Swf9nd()
{
	var publicID = "";  
	var obj	= (document.all["luv_pie300x250_1"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer300Gif(swfValue);	    
}

function leafGearViewer300Swf10nd()
{
	var publicID = "";  
	var obj	= (document.all["luv_pie470x90_1"]);
	
	var swfValue = Trim(obj.value);
	
	leafGearViewer470Gif(swfValue);	    
}



function leafGearViewer300Gif(fileName)
{
	window.open("/Modules/Downloads/Popup/LeafGear300Gif.aspx?strFileName="+fileName, null, "Width=510, Height=375, edge=sunken, center=yes, resizable=no, status=no, help=no, scroll=no");
}

function leafGearViewer300Swf(fileName)
{
	window.open("/Modules/Downloads/Popup/LeafGear300Swf.aspx?strFileName="+fileName, null, "Width=510, Height=375, edge=sunken, center=yes, resizable=no, status=no, help=no, scroll=no");
}

function leafGearViewer470Gif(fileName)
{
	window.open("/Modules/Downloads/Popup/LeafGear470Gif.aspx?strFileName="+fileName, null, "Width=510, Height=360, edge=sunken, center=yes, resizable=no, status=no, help=no, scroll=no");
}

function leafGearViewer470Swf(fileName)
{
	window.open("/Modules/Downloads/Popup/LeafGear470Swf.aspx?strFileName="+fileName, null, "Width=510, Height=360, edge=sunken, center=yes, resizable=no, status=no, help=no, scroll=no");
}

function leafGearViewer470GifMisc(fileName)
{
	window.open("/Modules/Downloads/Popup/LeafGear470GifMisc.aspx?strFileName="+fileName, null, "Width=510, Height=372, edge=sunken, center=yes, resizable=no, status=no, help=no, scroll=no");
}
var currentSkinTab;
var imagePath = "http://nxcache.nexon.net/maplestory/community/";
function ImageTab_Unselected(imageObj,imageNo)
{
    if(currentSkinTab!=imageObj)
        imageObj.src = imagePath+"btn_"+imageNo+"_off.gif";
}
function ImageTab_Selected(imageObj,imageNo)
{

    imageObj.src = imagePath+"btn_"+imageNo+"_on.gif";
    imageObj.style.cursor = "pointer";
}
function ImageTab_Current(currentTab,imageNo)
{
    document.images.skin_01.src=imagePath+"btn_01_off.gif";
    document.images.skin_02.src=imagePath+"btn_02_off.gif";
    document.images.skin_03.src=imagePath+"btn_03_off.gif";
    document.images.skin_04.src=imagePath+"btn_04_off.gif";
    
    currentSkinTab = currentTab;
    ImageTab_Selected(currentSkinTab,imageNo);
    SkinPreview(currentSkinTab,imageNo);  
   
   document.getElementById("selectedSkinId").value = imageNo; 
}
function SkinPreview(imageObj,imageNo)
{
    document.getElementById("SkinPreview").innerHTML="<img src=\""+imagePath+"card_selected_"+imageNo+".gif\" title=\""+imageNo+"\" alt=\""+imageObj.alt+"\" />";
    document.getElementById("/Controls/Forums/Referral_tbSelectedSkin").value = imageNo;
    
}
function CharacterSelected(id,character)
{
    var cDiv=document.getElementById("/Controls/Forums/Referral_tbSelectedCharacterName");
    var iDiv=document.getElementById("/Controls/Forums/Referral_tbSelectedCharacterId");
    cDiv.value = character;
    iDiv.value = id;
    
    document.getElementById("selectedCharacterName").value = character;
}

function HideChart(obj)
{

    if(obj.src=="http://nxcache.nexon.net/maplestory/download/download_expand_hide.gif")
    {
        obj.src="http://nxcache.nexon.net/maplestory/download/download_expand_see.gif";
        document.getElementById("DownloadComparison").style.display="none";        
        //document.getElementById("DownloadComparison").style.height="0px";
        //alert(obj.src+"/"+document.getElementById("DownloadComparison").style.display);
    }else{
        obj.src="http://nxcache.nexon.net/maplestory/download/download_expand_hide.gif";
        //document.getElementById("DownloadComparison").style.height="126px";  
        document.getElementById("DownloadComparison").style.display="inline";  
        
        //alert("else"+document.getElementById("DownloadComparison").style.display);    
    }
    
}

