//Global Variables:WHOSONLINE
var g_WHOSONLINE_IDS;
var g_WHOSONLINE_RTN;

//Fix the main frame
function TankTop(){
    var ChkOpener = false;
    try{
        var objOpener = top.opener;
        if( objOpener ) ChkOpener = true;
		if( window.name.toLowerCase() == "petconsole" ) ChkOpener = true;
    }catch(e){
        ChkOpener = false;
    }
    if( ChkOpener ){
		//
	} else {
        if(self == top) top.location = "/?" + window.location.href.replace("http://"+window.location.hostname,"");
    }
} TankTop();
//New Popup open
function Popup(sURL,width,height){
    window.open(sURL,"","scroll=no,scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}
function PopupEx(sURL,name,width,height){
    MyPetConsole = window.open(sURL,name,"scroll=no,scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height +",top=50,left=50");
	MyPetConsole.focus();
}
function PopOpen(url,name,width,height){
	window.open(url,name,"scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}
function ConfPop(url,name,width,height){
	return window.open(url,name,"scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width="+ width +",height="+ height);
}
//Return popup reference
var mypetchoicewindow;
function OpenMypetchoice(){
    mypetchoicewindow = ConfPop("/common/MypetChoice.asp","mypetchoice",390,245);
}
function MypetChoice(){
    if( mypetchoicewindow ){
        var petid,petname,petkname,petyear,petmonth,petgender,petlevel,petbirth;
        petid       = mypetchoicewindow.document.forms[0].fmPid.value;
        petname     = mypetchoicewindow.document.forms[0].fmPname.value;
        petkname    = mypetchoicewindow.document.forms[0].fmPkname.value;
        petgender   = mypetchoicewindow.document.forms[0].fmPgender.value;
        petlevel    = mypetchoicewindow.document.forms[0].fmPlevel.value;
		petbirth    = mypetchoicewindow.document.forms[0].fmPbirth.value;
        var objPetid,objPetname,objPetkname,objPetgender,objPetlevel,obPetbirth;
        objPetid    = document.getElementById("petid");
        objPetname  = document.getElementById("petname");
        objPetkname = document.getElementById("petkname");
        objPetgender= document.getElementById("petgender");
        objPetlevel = document.getElementById("petlevel");
		objPetbirth = document.getElementById("petbirth");
        if( objPetid    ){ objPetid.value    = petid;   }
        if( objPetname  ){ objPetname.value  = petname; }
        if( objPetkname ){ objPetkname.value = petkname;}
        if( objPetgender){ objPetgender.value= petgender;}
        if( objPetlevel ){ objPetlevel.value = petlevel;}
		if( objPetbirth ){ objPetbirth.value = petbirth;}
        mypetchoicewindow.close();
        UserMypetchoice();
    }
}
function UserMypetchoice(){} //Define for inheritance

//Shooting value to new window, GET
function submitToWindow(theForm,tURL,width,height){
	var n = theForm.elements.length;
	var sParam = "";
	sParam = "uname="+ decodeURI(theForm.uname.value) +"&no1="+ decodeURI(theForm.no1.value) +"&no2="+ decodeURI(theForm.no2.value);
	var sURL = tURL +"?"+ sParam;
	Popup(sURL,width,height);
}
function openFindID(){
	Popup("/login/find_id.asp",390,235);
}
function ViewPager(nID){
	PopOpen("/myzone/msg_view.asp?msgid="+ nID + "&boxid=R","","390","260");
}
function PetViewPop(strPid){
    var wp;
    wp = window.open("/common/mypView.asp?pid="+ strPid ,"mypView","width=390,height=500,scrollbars=no,toolbar=no,directories=no,menubar=no,resizable=no,status=no");
    wp.focus();
}
//Only number
function onlyNumber(){
	if ((event.keyCode>=48 && event.keyCode<=57)||(event.keyCode>=96 && event.keyCode<=105)||event.keyCode == 44 || event.keyCode==8 || event.keyCode==9 || event.keyCode==13 || event.keyCode==46 || event.keyCode==144) {
		event.returnValue = true;
	}
	else {event.returnValue=false;}
}
function petDiary(OwnerId){
    var openCheck;
    var objDiaryscript;
    try{
        PopupEx("/myBlog/blog/petDiaryView.asp?rid="+OwnerId, "PetConsole", 942, 584);
    }catch(e){}
}
function MoveOpener(url) {
	top.opener.document.location.replace(url);
	top.opener.document.focus();
}
function MoveLogin(pg) {
	document.location.replace("/login/login_frm.asp?goURL="+ pg)
}
function petroot(strPid){
    PopOpen("/petworld/petroots.asp?pid="+ strPid,"PETROOT","490","600");
}
function HotdogCharge(){
    //DBº¹±¸ÈÄ ÀÓ½Ã¸àÆ®,2010-04-19
    /*
    alert("ÁË¼ÛÇÕ´Ï´Ù. ¾ÈÁ¤È­ ±â°£µ¿¾È ÃæÀüÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.\nÃæÀüÀº 4¿ù26ÀÏºÎÅÍ °¡´ÉÇÕ´Ï´Ù.");
    return;
    */
	//Exit plan, 2011-05-02
	alert("ÁË¼ÛÇÕ´Ï´Ù. ÇöÀç ÃæÀü ½Ã½ºÅÛ Á¡°ËÁß ÀÔ´Ï´Ù.");
	return;
	//Exit plan

    var openerObj;
    try{
        openerObj = opener;
        PopOpen("/itemmall/charge/HotdogCharge.asp","HotdogChargeWindow",402,650);
    } catch(e){
        document.location.href = "/itemmall/charge/HotdogCharge.asp";
    }
}
function HotdogGift(){
    var openerObj;
    try{
        openerObj = opener;
        PopOpen("/itemmall/charge/HotdogGift.asp","HotdogGiftWindow",390,200);
    } catch(e){
        document.location.href = "/itemmall/charge/HotdogGift.asp";
    }
}
function RegiSSNL7(){
	PopOpen("/petworld/ptwResiRegi.asp","RegiSSNL7Window",402,430);
}
function ZoneSSNL7(){
	PopOpen("/petworld/ptwResiRegi.asp?Regimode=MYZONE","RegiSSNL7Window",402,430);
}
var bgempty = false ;
function bgEmpty(fld) {
    if ( bgempty ) return true;
    fld.value = "";
    bgempty = true;
    return bgempty;
}
//Move to charge center
function go_cash_fill() {
    top.document.location.href = "/itemmall/charge/HotdogCharge.asp";
}

function josa(str,tail){
    strTemp = str.substr(str.length - 1);
    var cc = strTemp.charCodeAt(0);
    if( cc < 129 ){
        //Number
        if( cc == 48 || cc == 49 || cc == 51 || cc == 54 || cc == 55 || cc == 56 ) return str+tail.substr(0,1);
        if( cc == 50 || cc == 52 || cc == 53 || cc == 57 ) return str+tail.substr(1,1);
        //English
        pattern = /[lmn]/i;
        if(pattern.test(strTemp)) return str+tail.substr(0,1);
        pattern = /([aeiou][^aeiouwy]e|mb)$/i;
        return pattern.test(str) ? str+tail.substr(0,1) : str+tail.substr(1,1);
    }
    return ((cc-16)%28!=0) ? str+tail.substr(0,1) : str+tail.substr(1,1);
}
function replace(str, original, replacement){
    var result;
    result = "";
    while(str.indexOf(original) != -1){
        if (str.indexOf(original) > 0)
            result = result + str.substring(0, str.indexOf(original)) + replacement;
        else
            result = result + replacement;
            str = str.substring(str.indexOf(original) + original.length, str.length);
    }
    return result + str;
}
function windowresize(){
    var heightBody= 0;
    var widthBody = 0;
    var heightWin = 0;
    var widthWin  = 0;

    var heightGap = 0;
    var widthGap  = 0;

    heightBody= document.body.scrollHeight;
    widthBody = document.body.scrollWidth;
    heightWin = document.body.clientHeight;
    widthWin  = document.body.clientWidth;
    heightGap = heightWin - heightBody;
    widthGap  = widthWin - widthBody;

    if( heightGap > 0 || heightGap < 0)
        top.window.resizeBy(0,-heightGap);

    if( widthGap > 0 || widthGap < 0)
        window.resizeBy(-widthGap,0);
}

function loginAlert(varEval){ //varEval- javascript:,gourl:
    var wname,wmessage,gourl;
    var evalLike,evalAction
    var logCookie;
	var returnPage;
	wmessage = "¸ÕÀú ·Î±×ÀÎ ÇÏ¼¼¿ä";

    if( varEval == "" || varEval == null ){
        varEval = "goUrl:/login/login_frm.asp";
    }
    wname = top.window.name.toLowerCase();
    if( wname == "petconsole" ){
        gourl = "/mypet/mypLogin.asp";
    } else {
        gourl = "/login/login_frm.asp";
    }

    evalLike = varEval.substr(0,varEval.indexOf(":")).toLowerCase();
    evalAction = varEval.substr(varEval.indexOf(":")+1);
    logCookie = getCookie("PmLoginSession");
    if( logCookie.substr(0,10) == " PmFriends" ) logCookie = "";
    if( logCookie == "" ){
        var wcf = window.confirm(wmessage);
        if( wcf ){
            //if( evalLike == "javascript" ) evalAction = "";
			evalAction = document.location;
			if (wname=="petconsole")
			{
				LoginPop();
			} else {
            location.href = gourl +"?goURL="+ evalAction;
			}
        }
    } else {
        switch(evalLike){
            case "javascript":
                eval(evalAction);
            break;
            case "gourl":
                location.href = evalAction;
            break;
        }
    }
}
function getCookie(name) {
	var Found = false
	var start, end
	var i = 0
	while(i <= document.cookie.length) {
		start = i
		end = start + name.length
		if(document.cookie.substring(start, end) == name) {
			Found = true
			break
		}
	i++
	}
	if(Found == true) {
		start = end + 1
		end = document.cookie.indexOf(";", start)
		if(end < start) end = document.cookie.length
		return document.cookie.substring(start, end)
	}
	return ""
}

function AJAX(){
    var xmlHttp = null;
    var bReady = false;
    var is_ie5 = (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) && document.all;
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else {
        var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        try {
            xmlHttp = new ActiveXObject(control);
        } catch (e) {
            xmlHttp = null;
        }
    }
    this.connect = function( sMethod, sUrl, sVars, FnName )
    {
        bReady = false;
        sMethod = sMethod.toUpperCase();
        try {
            if ( sMethod == "GET" )
            {
                if ( sVars.length > 0 )
                {
                    xmlHttp.open( sMethod, sUrl +"?"+ sVars, true );
                    sVars = "";
                } else {
                    xmlHttp.open( sMethod, sUrl, true );
                }
            } else {
                xmlHttp.open( sMethod, sUrl, true );
                xmlHttp.setRequestHeader("Method", "POST "+ sUrl +" HTTP/1.1");
            }
	        //xmlHttp.overrideMimeType(this.mimeType);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
            xmlHttp.setRequestHeader("Cookie",document.cookie);
            xmlHttp.onreadystatechange = function()
            {
                if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 && xmlHttp.statusText == 'OK' && !bReady ) {
                    bReady = true;
                    FnName( xmlHttp );
                }
            }
            xmlHttp.send( sVars );
        } catch(e) {
            //alert( "Error:"+ e +"\nName:"+ e.name +"\nNum:"+ e.number +"\nMachine:"+ (e.number>>16 & 0x1FFF) +"\nMessage:"+ e.message );
            return false;
        }
    }
}

function AJAXNoResponse(){
    var xmlHttp = null;
    var bReady = false;
    var is_ie5 = (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) && document.all;
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else {
        var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        try {
            xmlHttp = new ActiveXObject(control);
        } catch (e) {
            xmlHttp = null;
        }
    }
    this.connect = function( sMethod, sUrl, sVars, FnName )
    {
        bReady = false;
        sMethod = sMethod.toUpperCase();
        try {
            if ( sMethod == "GET" )
            {
                if ( sVars.length > 0 )
                {
                    xmlHttp.open( sMethod, sUrl +"?"+ sVars, true );
                    sVars = "";
                } else {
                    xmlHttp.open( sMethod, sUrl, true );
                }
            } else {
                xmlHttp.open( sMethod, sUrl, true );
                xmlHttp.setRequestHeader("Method", "POST "+ sUrl +" HTTP/1.1");
            }
	        //xmlHttp.overrideMimeType(this.mimeType);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
            xmlHttp.setRequestHeader("Cookie",document.cookie);
            xmlHttp.send( sVars );
        } catch(e) {
            return false;
        }
    }
}

function chkFunctionKey()
{
	we = window.event;
	if(we.ctrlKey)
	{
		we.returnValue = false;
		we.cancelBubble = true;
		return false;
	}
	switch(we.keyCode)
	{
		case 114: // F3
		case 116: // F5
		case 117: // F6
		case 122: // F11
		case 93:  // menu
		case 17:  // ctrl
			we.keyCode = 0;
			we.cancelBubble = true;
			we.returnValue = false;
			return false;
	}
}

function RegExpTest(ptn, TestStr) {
	var ObjRegExp = new RegExp(ptn,"g");
	if (ObjRegExp.exec(TestStr))
	{
		return true;
	} else {
		return false;
	}
}

function resizeIFrame(frm)
{
	var h = frm.contentWindow.document.body.scrollHeight;
	frm.height = h;
}

