﻿function ObjectValidate(){
	
	var inputCount, divCount, filCount, ddlCount, chbCount, rdoCount   ;
	var txtId, divId, fileId, ddlId, chbId, rdoId ;
	var	objValue, objFocus, objDataType, objDataErrMsg, objNullErrMsg, objEqualValue, objEqualErrMsg, objLengthMin, objLengthErrMsg ;
	var chbNameArray, rdoNameArray ; 

	inputCount = document.body.all.tags('input').length;
	divCount = document.body.all.tags("div").length;
	ddlCount = document.body.all.tags('select').length;	
	
	for(var i=0; i<inputCount; i++){					
		txtId = document.body.all.tags('input')[i].id;		
		if( document.getElementById(txtId).type == "text") {
			objValue		= document.getElementById(txtId).value;	
			objFocus		= document.getElementById(txtId).focus();
			objDataType		= document.getElementById(txtId).DataType;				
			objDataErrMsg	= document.getElementById(txtId).DataErrMsg;
			objNullErrMsg	= document.getElementById(txtId).NullErrMsg;
			objEqualValue	= document.getElementById(txtId).EqualValue;
			objEqualErrMsg	= document.getElementById(txtId).EqualErrMsg;
			objLengthMin	= document.getElementById(txtId).LengthMin;
			objLengthErrMsg	= document.getElementById(txtId).LengthErrMsg;			
			if( typeof(objDataType ) != 'undefined' ){
				if(objDataType == "string" ){
					if(typeof(objNullErrMsg) != "undefined" ) {								
						if(objValue.length <= 0 ){
							alert(objNullErrMsg);
							objFocus;
							return false;
						}//end if								
					}//end if
				}//end if				
				if(objDataType == "integer" ){
					if(typeof(objNullErrMsg) != "undefined" ) {							
						if(objValue.length <= 0 ){
							alert(objNullErrMsg);
							objFocus;
							return false;
						}//end if						
						if(!isInteger(objValue) ){
							alert(objDataErrMsg);
							objFocus;
							return false;
						}//end if								
					}//end if
				}//end if
			}				
			if( typeof(objEqualValue ) != 'undefined' ){
				if(objValue != objEqualValue ){						
					alert(objEqualErrMsg);
					objFocus;
					return false;						
				}//end if
			}			
			if( typeof(objLengthMin ) != 'undefined' ){
				if(objValue.length < objLengthMin ){						
					alert(objLengthErrMsg);
					objFocus;
					return false;						
				}//end if
			}
		}
	}//end for	
	for(var i=0; i<inputCount; i++){								
		chbId = document.body.all.tags('input')[i].id;		
		if(document.getElementById(chbId).type == "checkbox" ){					
			var temp = "0";
			objValue		= document.getElementById(chbId).value;
			objFocus		= document.getElementById(chbId).focus();
			objNullErrMsg	= document.getElementById(chbId).NullErrMsg;				
			chbNameArray	= document.getElementsByName(chbId);

			if( typeof( objNullErrMsg ) != "undefined" ) {
				for(var j = 0; j < chbNameArray.length; j++ ) {
					if(chbNameArray[j].checked ){ 
						temp += j;
					}
				}						
				if( temp == "0" ) {
					alert( objNullErrMsg );
					return false;
				}	
			}
		}				
	}	
	for(var i=0; i<inputCount; i++){								
		rdoId = document.body.all.tags('input')[i].id;	
		if(document.getElementById(rdoId).type == "radio" ){	
			var temp = "0";
			objValue		= document.getElementById(rdoId).value;
			objFocus		= document.getElementById(rdoId).focus();
			objNullErrMsg	= document.getElementById(rdoId).NullErrMsg;				
			rdoNameArray	= document.getElementsByName(rdoId);

			if( typeof( objNullErrMsg ) != "undefined" ) {
				for(var j = 0; j < rdoNameArray.length; j++ ) {
					if(rdoNameArray[j].checked ){ 
						temp += j;
					}
				}						
				if( temp == "0" ) {
					alert( objNullErrMsg );
					return false;
				}	
			}
		}				
	}	
	for(var j=0; j < ddlCount; j++) {

		ddlId = document.body.all.tags("select")[j].id;				
		if(typeof(objNullErrMsg) != "undefined" ) {			
			objValue		= document.getElementById(ddlId).value;
			objFocus		= document.getElementById(ddlId).focus();
			objNullErrMsg	= document.getElementById(ddlId).NullErrMsg;			
			if(objValue.length <= 0 ){
				alert(objNullErrMsg);
				objFocus;
				return false;
			}//end if					
		}//end if		
	}//end for
	return true;
}//end function


function itemOrder(item, ino, gtype)
{
	orderForm.item_no.value = ino;
	orderForm.gtype.value = gtype;
	
	orderWindow  =  window.open(item+'Order.aspx?no='+ino+'&gtype='+gtype,'','scrollbars=no,resizable=no,width=448,height=242,left=410,top=0');  
	orderWindow.focus();
}

function shopItemOrder(ino, mbid, stype)
{
	shopViewFrm.ino.value = ino;
	
	shopViewWindow  =  window.open('../PopUp/itemOrder.aspx?ino='+ino+'&stype='+stype+'&mbid='+mbid,'','scrollbars=no,resizable=no,width=448,height=320,left=0,top=0');  
	shopViewWindow.focus();
}

function shopHold(ino, mbid, stype)
{
	shopViewFrm.ino.value = ino;
	
	shopViewWindow  =  window.open('../PopUp/popRepuest.aspx?ino='+ino+'&stype='+stype+'&mbid='+mbid,'','scrollbars=no,resizable=no,width=448,height=330,left=0,top=0');  
	shopViewWindow.focus();
}

//관심메뉴 등록시 호출
function regMyMenu(event_no)
{
	//location.href='http://mypage.cokeplay.com/myMenuWrite.aspx?event_no='+event_no;
	window.open('http://mypage.cokeplay.com/myMenuWrite.aspx?event_no='+event_no,'','scrollbars=no,resizable=no,width=448,height=330,left=0,top=0');  
}


function checkLogin(url)
{
	alert('로그인 후 사용하실 수 있습니다.');
	document.location.href = 'http://www.cokeplay.com/Member/loginMember.aspx?return='+url;	
}

function gradeErrorMgs()
{
	alert('골드회원이상이 되시면 이용하실 수 있는 아이템입니다.\n코드를 입력하고 레벨을 올려주세요~');
}

//html 페이지 reload 처리
function gradeRefresh()
{
	document.location.reload();
}


// 주소 검색 결과 처리
function findSchoolResult(school, address)
{
	var f = opener.document.classFrm;
	
	f.txtSchool.value = school;
	f.address.value = address;
	self.close();
}

// 동입력 확인
function checkInput()
{
	if(document.findForm.txtSchool.value == "")
	{
		alert('학교를 입력하세요.');
		document.findForm.txtSchool.focus();
		return false;
	}
	else
		return true;
}


// 한글 확인
function checkEnglish(value) {
	var english = /[^A-Za-z0-9.`\'\s]/;
	
	if (english.test(value))
		return true;		// If return value is true, it is error.
	return false;
}

/********************************************************
	Check the formal type
	of the Social Security Number.
********************************************************/
function fgn_no_chksum(reg_no) {
    var sum = 0;
    var odd = 0;
   
    buf = new Array(13);
    for (i = 0; i < 13; i++) buf[i] = parseInt(reg_no.charAt(i));

    odd = buf[7]*10 + buf[8];
    
    if (odd%2 != 0) {
      return false;
    }

    if ((buf[11] != 6)&&(buf[11] != 7)&&(buf[11] != 8)&&(buf[11] != 9)) {
      return false;
    }
    	
    multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
    for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);


    sum=11-(sum%11);
    
    if (sum>=10) sum-=10;

    sum += 2;

    if (sum>=10) sum-=10;

    if ( sum != buf[12]) {
        return false;
    }
    else {
        return true;
    }
}

// 주민번호 체크
function ssn_check(ssn1, ssn2) {

	var len1   = ssn1.length;
	var yy     = ssn1.substring(0, 2);
	var mm     = ssn1.substring(2, 4);
	var dd     = ssn1.substring(4, 6);
	var len2   = ssn2.length;
	var gender = ssn2.substring(0, 1);

	if (gender>4 && gender<10)
	{		
        if (fgn_no_chksum(ssn1+ssn2) == false)
            return true;
        else
            return false;
	} else {
		//if (len1 != 6 || yy < 25 || mm < 1 || mm > 12 || dd < 1 || dd > 31)		// If return value is true, it is error.
		if (len1 != 6 || mm < 1 || mm > 12 || dd < 1 || dd > 31)		// 00년 생이 있을경우 처리때문에 수정
			return true;
		
		if (len2 != 7 || (gender != 1 && gender != 2 && gender != 3 && gender != 4))
			return true;
		
		var i    = 0;
		var temp = 0;
		
		for (i = 0; i <= 5; i++)
			temp += (i % 8 + 2) * parseInt(ssn1.substring(i, i + 1));
		for (i = 6; i <= 11; i++)
			temp += (i % 8 + 2) * parseInt(ssn2.substring(i - 6, i - 5));
		temp = 11 - (temp % 11);
		temp %= 10;
		if (temp != ssn2.substring(6, 7))
			return true;
		return false;
	}
}

// 포커스 이동
function moveFocus(focus1, focus2, len)
{
	if(focus1.value.length==len)
		focus2.focus();
}


// 숫자 형식 체크
function isInteger(str)
{
	if (!isEmpty(str))
	{
		for (j = 0; j < str.length; j++)
			if (((str.substring(j, j+1) < "0") || (str.substring(j, j+1) > "9")))
				return false;
	}
	else
	{
		return false;
	}
	return true;
}

//빈 문자열 체크
function isEmpty(toCheck)
{
	var chkstr = toCheck + "";
	var is_Space = false;

	if (( chkstr == "") || (chkstr == null))
		return true;

	for (j = 0;  j < chkstr.length; j++) {
		if (chkstr.substring(j, j+1) == " ")
			is_Space = true ;
	}

	return is_Space;
}

// 이메일 형식 검증
function isEmail(strEmail)
{
    /** 금지사항
     - @가 2개이상
     - .이 붙어서 나오는 경우
     -  @.나  .@이 존재하는 경우
     - 맨처음이.인 경우 **/
    var regDoNot = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
    /** 필수사항
     - @이전에 하나이상의 문자가 있어야 함
     - @가 하나있어야 함
     - Domain명에 .이 하나 이상 있어야 함
     - Domain명의 마지막 문자는 영문자 2~4개이어야 함 **/
    var regMust = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})$/;

    if ( !regDoNot.test(strEmail) && regMust.test(strEmail) )
        return true;
    else
        return false;
}

//이벤트 메일 팝업
function SendMail(type){
	var w=window.screen.availWidth/2;
	var h=window.screen.availHeight/2;
	w=w-(400/2);
	h=h-(500/2);
//	window.open('http://www.cokeplay.com/Member/Popup/Login.aspx?url='+url,'login','scrollbars=no,resizable=no,width=398,height=380,left=10,top=10'); 
	window.open('./sendMessage.aspx?type='+type,'mailpop','scrollbars=no,resizable=no,width=410,height=515,left='+w+',top='+h); 
}

//하단 팝업창
function foot(type){
	window.open('./'+type,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=565 top=0,left=0');
}

//환타 마이크로 이벤트 참여하기 
function FantaMicroEvent(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 1010) / 2; 
	var wint = (screen.height - 700) / 2; 
	winprops = 'height=700,width=1010,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('/fanta/event/main.html', 'event_main', winprops) ; 
}

//환타 마이크로 이벤트 미니앨범 제작 및 수정 팝업
function FantaMicroAlbum(pKind){
	//미니앨범 제작하기
	if(pKind == 'insert'){
		window.open('http://imory10.imory.co.kr/imory/shop/fantaplay/auth.html','FantaMicroAlbum_I','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=395,height=220 top=0,left=0')
	}
	//미니앨범 수정하기
	else if(pKind == 'update'){
		window.open('http://imory10.imory.co.kr/imory/shop/fantaplay/mobile.php?target=self&retUrl=http://imory10.imory.co.kr/imory/shop/fantaplay/keeper.php','FantaMicroAlbum_U','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=277,height=248 top=0,left=0')
	}
}

//환타 코드 이벤트 당첨 팝업
function FantaPrize(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 578 ) / 2; 
	var wint = (screen.height - 412) / 2; 
	winprops = 'height=412,width=578 ,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popFantaPrize.aspx', 'FantaPrize', winprops) ; 
}

//환타 코드 이벤트 비당첨 팝업
function FantaFailure(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 578 ) / 2; 
	var wint = (screen.height - 412) / 2; 
	winprops = 'height=412,width=578 ,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popFantaFailure.aspx', 'FantaFailure', winprops) ; 
}
//환타 Schedule
function FantaSchedule(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 595  ) / 2; 
	var wint = (screen.height - 720 ) / 2; 
	winprops = 'height=720 ,width=595,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popFantaSchedule.aspx', 'FantaFailure', winprops) ; 
}


//소켄비차 팝업
function EventSokenbicha(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 494) / 2; 
	var wint = (screen.height - 700) / 2; 
	winprops = 'height=700,width=494,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popSokenbicha.html', 'FantaFailure', winprops) ; 
}

//조지아커피 메일보내기
function SendMailGeorgia(){
	//window.open('http://www.cocacola.co.kr/','FantaMicroEvent','')
	var winl = (screen.width - 385) / 2; 
	var wint = (screen.height - 464) / 2; 
	winprops = 'height=464,width=385,top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Brand/popGeorgiaMail.aspx', 'FantaFailure', winprops) ; 
}

//파워에이드 
function Powerade(pWidth, pHeight, imgName){		
	var winl = (screen.width - pWidth) / 2; 
	var wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Brand/popPowerade.aspx?imgName='+imgName+'&pWidth='+pWidth+'&pHeight='+pHeight, 'powerade', winprops) ; 
}

//파워에이드 올림픽 이벤트
function PoweradeOlympic(pWidth, pHeight){		
	var winl = (screen.width - pWidth) / 2; 
	var wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popPowerAdeOlympic.aspx', 'poweradeOlympic', winprops) ; 
}

//소켄비차 서포터즈 팝업
function EventSokenbicha2(pWidth, pHeight, obj){		
	var winl = (screen.width - pWidth) / 2; 
	var wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popSokenbicha'+obj+'.html', 'EventSokenbicha2', winprops) ; 
}

//파워에이드 당첨자 팝업 
function PoweradeOlympicPrize(pWidth, pHeight){		
	var winl = (screen.width - pWidth) / 2; 
	var wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/popWinnerList1.html', 'poweradeOlympicPrize', winprops) ; 
}

//코카제로 007
function CokeZero_007(pWidth, pHeight){		
	var winl = (screen.width - pWidth) / 2; 
	var wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open('./Event/eventCokeZero007_01.aspx', 'poweradeOlympicPrize', winprops) ; 
}

//공통팝업
function CommonPopup(pWidth, pHeight, filename){
	winl = (screen.width - pWidth) / 2; 
	wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open(filename, 'CommonPopup', winprops) ; 
}

//공통팝업2
function CommonPopup2(pWidth, pHeight, filename){
	winl = (screen.width - pWidth) / 2; 
	wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open(filename, 'CommonPopup2', winprops) ; 
}

//공통팝업3
function CommonPopup3(pWidth, pHeight, filename){
	winl = (screen.width - pWidth) / 2; 
	wint = (screen.height - pHeight) / 2; 
	winprops = 'width='+pWidth+',height='+pHeight+',top='+wint+',left='+winl+',scrollbars=no ,resizable=no' ;
	win = window.open(filename, 'CommonPopup3', winprops) ; 
}

//텍스트박스 초기화이미지설정
function clearBg(obj) {
	obj.style.backgroundImage = "none";
}

function ToDay2(){
	var now = new Date();
	yyyy	= now.getYear();
	mm		= now.getMonth()+1;
	dd		= now.getDate()-1; 
	hh		= now.getHours();		
	
	return yyyy + '-'+ DateLength2(String(mm)) + '-'+ DateLength2(String(dd)) ;
}
function DateLength2(pDate){
	var retValue = "";
	
	if(pDate.length == 1){
		
		retValue = "0"+pDate;
	}
	else{
		
		retValue = pDate;
	}	
		
	return retValue;
}	

//이벤트 종료확인			
//응모기간이 2008년 9월03일까지라면 2008-09-03 입력하면 04일부터는 에러를 출력한다
function DateEnd(eDate, msg){					
	if(eDate <= ToDay2()) {
		alert(msg);	
		return "over";
	}	
}