/**
 * Project:     www.pkr.co.kr renewal
 * Filename:    common.js
 *  
 * Company:     TAIHO INST
 * Copyright:   Copyright TAIHO INST. All Rights Reserved. 
 * 
 * @author     TAIHO INST
 * @version    1.0
 * 
 * History
 *  
 * Date          Version   Description            Author
 * ------------  --------  ---------------------  -----------
 * 2006/11/03    1.0.0     Initial Creation       TAIHO INST) Ko M.S.
 */

/**
 * Action for page move
 *
 * @param url
 * @return nothing
 */
function chknum()
{
	if (event.keyCode != 13 && event.keyCode != 9 && event.keyCode != 8 
		&& event.keyCode != 37 && event.keyCode != 39 )
	{
		if (event.keyCode < 45 || (event.keyCode > 57 && event.keyCode < 96) || event.keyCode > 105) 	
			event.returnValue = false;
	}
}

function OnCheckPhone(oTa)
{
	var oForm = oTa.form ;
	var sMsg = oTa.value ;
	var onlynum = "" ;
	onlynum = RemoveDash2(sMsg);
	if(event.keyCode != 13 && event.keyCode != 9 && event.keyCode != 8 
		&& event.keyCode != 37 && event.keyCode != 39 )
	{
		if (GetMsgLen(onlynum) <= 2)  oTa.value  = onlynum ;
		if (GetMsgLen(onlynum) == 3)  oTa.value  = onlynum + "-";
		if (GetMsgLen(onlynum) == 4)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,4) ;
		if (GetMsgLen(onlynum) == 5)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,5) ;
		if (GetMsgLen(onlynum) == 6)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,6) + "-" ;
		if (GetMsgLen(onlynum) == 7)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,6) + "-" + onlynum.substring(6,7) ;
		if (GetMsgLen(onlynum) == 8)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,6) + "-" + onlynum.substring(6,8);
		if (GetMsgLen(onlynum) == 9)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,6) + "-" + onlynum.substring(6,9);
		if (GetMsgLen(onlynum) == 10)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,6) + "-" + onlynum.substring(6,10);
		if (GetMsgLen(onlynum) == 11)  oTa.value  = onlynum.substring(0,3) + "-" + onlynum.substring(3,7) + "-" + onlynum.substring(7,11);
	}
}

function RemoveComma(sNo)
{
	var reNo = ""
	for(var i=0; i<sNo.length; i++) {
		if ( sNo.charAt(i) != "," ) {
			reNo += sNo.charAt(i)
		}
	}
	return reNo
}

function RemoveDash2(sNo)
{
	var reNo = ""
	for(var i=0; i<sNo.length; i++) {
		if ( sNo.charAt(i) != "-" ) {
			reNo += sNo.charAt(i)
		}
	}
	return reNo
}
// 0-127 1byte, 128~ 2byte
function GetMsgLen(sMsg)
{ 
	var count = 0
	for(var i=0; i<sMsg.length; i++) {
		if ( sMsg.charCodeAt(i) > 127 ) {
			count += 2
		} 
		else {
			count++
		}
	}
	return count
}

function isValidDay(yyyy, mm, dd) {
    var m = parseInt(mm,10) - 1;
    var d = parseInt(dd,10);

    var end = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    if ((yyyy % 4 == 0 && yyyy % 100 != 0) || yyyy % 400 == 0) {
        end[1] = 29;
    }

    return (d >= 1 && d <= end[m]);
}

function on_LowerCase(frmName, valueName)
{
	eval("document."+frmName+"."+valueName+".value = document."+frmName+"."+valueName+".value.toLowerCase()");
}

function on_UpperCase() {
	var str_fname_eng = document.frmRegUser.cus_fname_eng.value;
	var str_lname_eng = document.frmRegUser.cus_lname_eng.value;

	document.frmRegUser.cus_fname_eng.value = "";
	document.frmRegUser.cus_fname_eng.value = str_fname_eng.toUpperCase();
	document.frmRegUser.cus_lname_eng.value = "";
	document.frmRegUser.cus_lname_eng.value = str_lname_eng.toUpperCase();
}

/**
 * Flash View
 *
 * @param url
 * @return nothing
 */

function flashView(flashUrl, flashWidth, flashHeight) {
	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="+flashWidth+" HEIGHT="+flashHeight+" id=navagation>");
	document.write("    <PARAM NAME=movie VALUE='"+flashUrl+"'>");
	document.write("    <PARAM NAME=quality VALUE=high>");
	document.write("    <param name=menu value=false>");
	document.write("    <param name=WMode value=Opaque>");
	document.write("    <param name=allowScriptAccess value=always>");
	document.write("	<EMBED src='"+flashUrl+"' quality=high menu=false  WIDTH="+flashWidth+" HEIGHT="+flashHeight+" NAME=navigation TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/go/getflashplayer ></EMBED>");
	document.write("</OBJECT>");
}

/**
 * use homepage menu flash
 *
 * @param 1depth menu
 * @param 2depth menu
 * @return nothing
 */
function home_flash_url(depth_1, depth_2)
{
	var depth_url;

	if(depth_1 != "" && depth_2 != "")
	{
		if(depth_1 == "1")																//회사소개
		{
			if(depth_2 == "1")
			{
				depth_url = "/company/ceo_message.jsp";									//ceo인사말
			}
			else if(depth_2 == "2")
			{
				depth_url = "/company/company_info.jsp";								//회사개요
			}
			else if(depth_2 == "3")
			{
				depth_url = "/company/company_history.jsp";								//회사연혁
			}
			else if(depth_2 == "4")
			{
				depth_url = "/company/company_customer.jsp";							//주요고객
			}
			else if(depth_2 == "5")
			{
				depth_url = "/company/company_manage.jsp";								//경영현황
			}
		}
		else if(depth_1 == "2")															//법인렌트
		{
			if(depth_2 == "1")
			{
				depth_url = "/rent/rent_info.jsp";										//법인렌트 장점
			}
			else if(depth_2 == "2")
			{
				depth_url = "/rent/rent_vs_rease.jsp";									//법인렌트 VS 리스
			}
			else if(depth_2 == "3")
			{
				depth_url = "/rent/rent_rule.jsp";										//이용절차
			}
		}
		else if(depth_1 == "3")															//상품안내
		{
			if(depth_2 == "1")
			{
				depth_url = "/product/product_long_rent.jsp";							//장기렌탈
			}
			else if(depth_2 == "2")
			{
				depth_url = "/product/product_short_rent.jsp";							//법인단기렌트
			}
			else if(depth_2 == "21")
			{
				depth_url = "/product/product_short_rent_amt.jsp";						//법인단기요금표
			}
			else if(depth_2 == "3")
			{
				depth_url = "/product/product_car_info.jsp";							//차량정보
			}
			else if(depth_2 == "4")
			{
				depth_url = "/product/special_car/special_car_list.jsp";				//스페셜 차량 보기
			}
			else if(depth_2 == "5")
			{
				depth_url = "/crms/short_reserv/short_reserv_frm.jsp";					//법인단기예약
			}
		}
		else if(depth_1 == "4")															//외주정비
		{
			if(depth_2 == "1")
			{
				depth_url = "/repair/repair/repair_estimate_list.jsp";					//정비 견적 신청 및 조회
			}
			else if(depth_2 == "2")
			{
				depth_url = "/repair/car_info/repair_car_list.jsp";						//차량 및 정비이력 조회
			}
			else if(depth_2 == "3")
			{
				depth_url = "/repair/car_receipt/car_receipt_list.jsp";					//차량 및 수리이력 조회
			}
		}
		else if(depth_1 == "5")															//CRMS
		{
			if(depth_2 == "1")
			{
				depth_url = "/crms/short_reserv/short_reserv_frm.jsp";					//법인단기예약
			}
			else if(depth_2 == "2")
			{
				depth_url = "/crms/estimate/estimate_detail_frm.jsp";					//견적신청
			}
			else if(depth_2 == "3")
			{
				depth_url = "/crms/estimate_check/estimate_check_frm.jsp";				//견적 및 발주
			}
			else if(depth_2 == "4")
			{
				depth_url = "/crms/motor_account/motor_account_main.jsp";				//차계부-이용안내
			}
			else if(depth_2 == "41")
			{
				depth_url = "/crms/motor_account/motor_account_car_frm.jsp";			//차계부-차종기본정보
			}
			else if(depth_2 == "42")
			{
				depth_url = "/crms/motor_account/motor_account_main_list.jsp";			//차계부-차량유지
			}
			else if(depth_2 == "43")
			{
				depth_url = "/crms/motor_account/motor_account_static_pay_list.jsp";	//차계부-통계
			}
			else if(depth_2 == "5")
			{
				depth_url = "/crms/car_rent/car_rent_list.jsp";							//차량대여현황
			}
			else if(depth_2 == "6")
			{
				depth_url = "/crms/car_repair_month/car_repair_month_list.jsp";			//월 정비현황
			}
			else if(depth_2 == "7")
			{
				depth_url = "/crms/car_repair/car_repair_list.jsp";						//차량이력현황 조회
			}
		}
		else if(depth_1 == "6")															//고객센터
		{
			if(depth_2 == "1")
			{
				depth_url = "/customer/maintenance/maintenance_main.jsp";				//정비예약
			}
			else if(depth_2 == "2")
			{
				depth_url = "/customer/board/board_list.jsp";							//고객의 소리
			}
			else if(depth_2 == "3")
			{
				depth_url = "/customer/notice/notice_list.jsp";							//News & Notice
			}
			else if(depth_2 == "4")
			{
				depth_url = "/customer/repair_info/repair_info.jsp";					//정비업체 안내
			}
			else if(depth_2 == "41")
			{
				depth_url = "/customer/repair_info/repair_info.jsp";					//정비업체 안내-Auto Oasis
			}
			else if(depth_2 == "42")
			{
				depth_url = "/customer/repair_info/repair_info_etc.jsp";				//정비업체 안내-기타정비업체 안내
			}
			else if(depth_2 == "5")
			{
				depth_url = "/customer/insurance/insurance.jsp";						//보험 및 사고처리
			}
			else if(depth_2 == "6")
			{
				depth_url = "/customer/emergency/emergency.jsp";						//비상연락망
			}
			else if(depth_2 == "7")
			{
				depth_url = "/customer/traffic/traffic_info.html";						//교통정보 안내
			}
		}
		else if(depth_1 == "7")															//외주사 관리
		{
			depth_url = "/repair/repair/repair_estimate_list.jsp";						//정비 견적 신청 및 조회
		}
		else if(depth_1 == "8")															//멤버십
		{
			if(depth_2 == "1")
			{
				depth_url = "/member/join/nameCheck.jsp";								//회원가입
			}
			else if(depth_2 == "2")
			{
				depth_url = "/login/login_frm.jsp";										//로그인
			}
			else if(depth_2 == "3")
			{
				depth_url = "/member/member_rule.jsp";									//이용약관
			}
			else if(depth_2 == "4")
			{
				depth_url = "/member/rent_term.jsp";								//개인정보 보호정책
			}
			else if(depth_2 == "5")
			{
				depth_url = "/member/member_sitemap.jsp";								//사이트맵
			}
			else if(depth_2 == "6")
			{
				depth_url = "/member/member_contact.jsp";								//Contact Us
			}
		}
		else if(depth_1 == "10")														//지점안내
		{
			depth_url = "/customer/guidance/guidance.jsp";
		}
		else if(depth_1 == "11")														//비상연락망
		{
			depth_url = "/customer/emergency/emergency.jsp";
		}
		else if(depth_1 == "12")														//Show Room
		{
			depth_url = "/common/show_room.html";
		}

		if(depth_url != "" && depth_url != "undefined")
		{
			if((depth_1 == "6" && depth_2 == "7") || depth_1 == "12")
			{
				window.open(depth_url, 'depth', 'width=1100,height=700,top=0,left=0,resizable=yes,scrollbars=no,status=yes');
			}
			else
			{
				document.writeln("<form name='frm_common_new_window' method='post' action='" + depth_url + "'>");
				document.writeln("<input type='hidden' name='sub_menu' value='" + depth_2 + "'>");
				document.writeln("<\/form>");
				document.frm_common_new_window.submit();
			}
		}
	}
	else
	{
		alert("error");
	}
}

function ImagesChange(image_id, image_url)
{
	document.all[image_id].src = image_url;
}
function changeFamily()
{
	if(document.all.familysite.value != "1")
	{
		window.open(document.all.familysite.value);
	}
}

/**
 * change spetail key to normal string
 * 
 * ex) <input type="text" onKeypress="isNumber();">
 */
function isNumberKeypress() 
{
    if ( event != null) 
    {
		if( (event.keyCode<48) || (event.keyCode>57))
		{
			if((event.keyCode==45) || (event.keyCode==46) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode==13))
			{
				return true;
			}
			else
			{
				event.returnValue = false;
			}
		}
    }
}

/**
 * change spetail key to normal string
 * 
 * ex) <input type="text" onKeypress="isNumber();">
 */
function isNumberForm(input) 
{
    var chars = "0123456789";
    for (var inx = 0; inx < input.value.length; inx++) 
    {
       if (chars.indexOf(input.value.charAt(inx)) == -1)
       {
           return false;
       }
    }

    return true;
}

function numOnly(obj,isCash)
{
	//사용예 : <input type="text" name="text" onKeyUp="javascript:numOnly(this,true);"> 
	//세자리 콤마 사용시 true , 숫자만 입력 시 false 
	try
	{
	if (event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39) return; 
	}
	catch(e){}
	var returnValue = ""; 
	for (var i = 0; i < obj.value.length; i++)
	{
		if (obj.value.charAt(i) >= "0" && obj.value.charAt(i) <= "9")
		{ 
			returnValue += obj.value.charAt(i); 
		}
		else
		{ 
			returnValue += ""; 
		}
	} 

	if (isCash)
	{ 
		obj.value = cashReturn(returnValue); 
		return; 
	} 
	obj.focus(); 
	obj.value = returnValue; 
} 
function cashReturn(numValue)
{ 
	//numOnly함수에 마지막 파라미터를 true로 주고 numOnly를 부른다. 
	var cashReturn = ""; 
	for (var i = numValue.length-1; i >= 0; i--)
	{ 
		cashReturn = numValue.charAt(i) + cashReturn; 
		if (i != 0 && i%3 == numValue.length%3) cashReturn = "," + cashReturn; 
	} 
	return cashReturn; 
}
