//즐겨찾기추가
function favorite()
{
	try {
		if ( navigator.appName != 'Microsoft Internet Explorer' ) return;
		else window.external.AddFavorite('http://www.ipopcorn.co.kr','아이팝콘');
	} catch (e) { } 
	
	return;
}

function setStartPage ( ) 
{ 
	var url='http:///www.ipopcorn.co.kr';
	try {
		obj.style.behavior = 'url(#default#homepage)'; 
		obj.setHomePage(url); 
		delete obj;
		return true; 
	} catch (e) { } 
}

function getBrowser() 
{
	var browser = { agent: null, opera: false, msie: false, firefox: false, netscape: false, safari: false, version: false };
	var ua = window.navigator.userAgent.toLowerCase();
	var agent, version;
	if (ua.match("opera")) {
		browser.agent = "opera";
		browser.opera = true;
		browser.version = trim(ua.split("opera")[1]);
	}
	else if (ua.match("msie")) {
		browser.agent = "msie";
		browser.msie = true;
		browser.version = trim(ua.split("msie")[1].split(";")[0]);
	}
	else if (ua.match("firefox")) {
		browser.agent = "firefox";
		browser.firefox = true;
		browser.version = trim(ua.split("firefox")[1].split("/")[1]);
	}
	else if (ua.match("netscape")) {
		browser.agent = "netscape";
		browser.netscape = true;
		browser.version = trim(ua.split("netscape")[1].split("/")[1]);
	}
	else if (ua.match("safari")) {
		browser.agent = "safari";
		browser.safari = true;
		browser.version = trim(ua.split("safari")[1].split("/")[1]);
	}
	return browser;
}

function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);	
}

function MM_openBrModal(theURL,winName,features) {
	window.showModalDialog(theURL,winName,features);
}

function openWin(URL, w, h, scb)
{
	sx = (screen.width - w)/2;
	sy = (screen.height - h)/2 ;
	sub = window.open(URL, "pcornOpenWin" , 'toolbar=no,status=no,menubar=no,copyhistory=yes,scrollbars='+scb+',resizable=no,status=no,width='+w+',height='+h+',top='+sy+',left='+sx);

}

// 폼 검사
function form_check() {
//	$('#message').hide();


	var f = document.forms[0];
	var formstatus = true;
	var password = f.password.value;
//	var password = $('#Passwd').val();

	// 빈칸체크	함수
	var eval = function () {
		if(this.value == ''){
			$(this).effect("highlight", {color: '#8080ff'}, 5000);
			formstatus = false;
		}
	}
	
	//$("input[name$='letter']").val("a letter");
	// 빈칸 체크 수행
	$('input:not(#Intro,#Pass1,#Pass2)').each(eval);
	//$("input[name$='MemberPhone2']:not").each(eval);
	$('textarea').each(eval);
	
	if (formstatus == false) {
		//$('#message').slideDown().effect("highlight", {color: '#8080ff'}, 4000);
		alert('필수항목을 기입하세요');
		formstatus = false;
		return false;
	}
	
//	패스워드 체크
	if(password.length > 0) {
		if(password.length < 6 || password.length > 14){
			alert('비밀번호 자리수를 확인하세요');
			formstatus = false;
			return false;
		}
		
		if(password != f.passCheck.value){
			alert('비밀번호를 확인하세요');
			f.password.value = "";
			f.passCheck.value = "";
			formstatus = false;
			return false;
		}
	
	}

	if(formstatus == true) {
		f.submit();
	}
}


//입력폼체크
function chkform(f) {
	var formstatus = true;

	// 빈칸체크	함수
	var eval = function () {
		if(this.value == ''){
			$(this).effect("highlight", {color: '#8080ff'}, 5000);
			formstatus = false;
		}
	}

	// 빈칸 체크 수행
	$('input:not(#Intro,#LoginID,#LoginPW,#LoginBtn,#NiceId,#SendInfo,#ProcessType,#SIKey,#PingInfo,#ReturnURL,#OrderNo,#nofrmid,#myinfojumin)').each(eval);
	
	if (formstatus == false) {
		alert('필수항목을 기입하세요');
		formstatus = false;
		return false;
	}
	
	if(formstatus == true) {
		f.submit();
	}
}
/*

//입력폼체크
function chkform() {
	for (i = 0; i < fieldlist.length; i++) {
		if (fieldlist[i][0] == "") {
			alert(fieldlist[i][1] + " 항목을 확인하여주세요.");
			formstatus = false;
			return false;
		} else {
			formstatus = true;
			return true;
		}
	}
}
*/

//숫자 체크
function Num_chk(form) 
{	  	 
   	var str = form.value;
  	for(i=0;i<str.length;i++) 
  	{
  		Num = str.charAt(i);
  		if (Num < '0' || Num > '9') {
			form.value=form.value.substring(0,i); 
			alert("숫자만 입력하세요");
			form.focus(); 
			return false;
		}
  	}
}

//주민번호 검사
function CheckJumin(f)
{
	obj_jumin1  = f.userNo1;
	obj_jumin2  = f.userNo2;
	val_jumin1  = f.userNo1.value;
	val_jumin2  = f.userNo2.value;

	ju = [0,0,0,0,0,0,0,0,0,0,0,0,0];   // 주민번호 체크 배열선언
	for(i=0; i<6; i++)
	{
		ju[i] = val_jumin1.substring(i,i+1);
	}
	for(i=0; i<7; i++)
	{
		ju[i+6] = val_jumin2.substring(i,i+1);
	}
	for(sum=0,i=0; i<=11; i++)
	{
		sum+= ju[i] * ((i>7)?(i-6):(i+2));
	}

	mod = 11 - (sum % 11);
	if(mod	>=10) mod-= 10;

	if(mod	!=	ju[12])
	{
		alert('주민등록번호 오류입니다 !!\n\n주민등록번호 확인 후 다시 입력해주세요.');
		obj_jumin1.value = '';
		obj_jumin2.value = '';
		obj_jumin1.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function inputCheck(obj){
	var re = /[~\<>|*\()\+\']/gi;
	var i;
	
	for(i=0;i<obj.value.length;i++){ 
		if(re.test(obj.value)){
			alert("일부 특수문자는 입력하실수 없습니다.");
			obj.value = obj.value.replace(re,"");
			obj.focus();
		}
	}
}

// 이메일 체크 
function CheckMail(strMail) { 
   /** 체크사항 
     - @가 2개이상일 경우 
     - .이 붙어서 나오는 경우 
     -  @.나  .@이 존재하는 경우 
     - 맨처음이.인 경우 
     - @이전에 하나이상의 문자가 있어야 함 
     - @가 하나있어야 함 
     - Domain명에 .이 하나 이상 있어야 함 ㅡ
     - Domain명의 마지막 문자는 영문자 2~4개이어야 함 **/ 

    var check1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;  

    var check2 = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})$/; 
     
    if ( !check1.test(strMail) && check2.test(strMail) ) { 
        return true; 
    } else { 
        return false; 
    } 
}

// str은 모두 소문자여야하고 첫글자는 영문이어야 한다. 영문과 0~9, -, _, ^는 허용한다. 
function CheckChar(str) { 
    strarr = new Array(str.length); 
    var flag = true; 
    for (i=0; i<str.length; i++) { 
        strarr[i] = str.charAt(i) 
        if (i==0) { 
            if (!((strarr[i]>='a')&&(strarr[i]<='z'))) { 
                flag = false; 
            } 
        } else { 
            if (!((strarr[i]>='a')&&(strarr[i]<='z')||(strarr[i]>='0')&&(strarr[i]<='9')||(strarr[i]=='@')||(strarr[i]=='.')||(strarr[i]=='^'))) { 
                flag = false; 
            } 
        } 
    } 
    if (flag) { 
        return true; 
    } else { 
        return false; 
    } 
}

function win(f){
	if(f=="nospam")
	{
		var URL='/provision/spam.html';
		var w='520';
		var h='213';
		var scb='no';
	}	
	sx = (screen.width - w)/2;
	sy = (screen.height - h)/2 ;
	pop = window.open(URL, "gmnOpenWin" , 'toolbar=no,status=no,menubar=no,copyhistory=yes,scrollbars='+scb+',resizable=no,status=no,width='+w+',height='+h+',top='+sy+',left='+sx);
	
}

function hitEnterKey(){
	if(event.keyCode == 13){
		LoginCheck();
	}
 }
 
 
function uonMember(id) {
	alert("회원가입이 완료되었습니다.");
	external.SetPKValue(id);
	external.UnloadPopup(false);
}

//SNS 관련
function pstCLog(link,title,thumbnail,writer) {
	var href = "http://csp.cyworld.com/bi/bi_recommend_pop.php?url=" + encodeURIComponent(link) + "&thumbnail=" + encodeURIComponent(thumbnail) + "&title=" + encodeURIComponent(title) + "&writer=" + encodeURIComponent(writer);
	var a = window.open(href, 'clog', 'width=400, height=364, scrollbars=no, resizable=no');
	if ( a ) {
	 a.focus();
	}
}

function pstTwitter(msg,url) {
	var href = "http://twitter.com/home?status=" + encodeURIComponent(msg) + " " + encodeURIComponent(url);
	var a = window.open(href, 'twitter', '');
	if ( a ) {
	 a.focus();
	}
}
function pstMe2Day(msg,url) {
	var href = 'http://me2day.net/posts/new?new_post[body]="' + encodeURIComponent(msg) + '":' + encodeURIComponent(url);
	var a = window.open(href, 'me2Day', '');
	if ( a ) {
	 a.focus();
	}
}
function pstFaceBook(msg,url) {
	var href = "http://www.facebook.com/sharer.php?u=" +encodeURIComponent(url) + "&t=" + encodeURIComponent(msg);
	var a = window.open(href, 'facebook', '');
	if ( a ) {
	 a.focus();
	}
}

function pstYozmDaum(link,prefix,parameter) {
	var href = "http://yozm.daum.net/api/popup/prePost?sourceid=54&link=" + encodeURIComponent(link) + "&prefix=" + encodeURIComponent(prefix) + "&parameter=" + encodeURIComponent(parameter);
	var a = window.open(href, 'yozm', 'width=466, height=356');
	if ( a ) {
	 a.focus();
	}
}

//천기추가
function setComma(str) {
	
	var iNum = replaceComma(str.toString()); 
	var aNum = iNum.split("."); 
	
	var num = ""; 
	for(var i=0;i<aNum[0].length;i++) 
	{ 
		if(i > 1 && ((i+1) % 3) == 1) { 
			num = "," + num; 
		} 
		num = aNum[0].substr(aNum[0].length-i-1, 1) + num; 
	} 
	
	if(aNum.length > 1) { 
		return num + "." + aNum[1]; 
	} else { 
		return num; 
	}
}

function replaceComma(str) { // 콤마 없애기 
 	while(str.indexOf(",") > -1) { 
  		str = str.replace(",", ""); 
	} 
	return str;  
} 


function removeComma(str) {
	return parseInt(str.replace(/,/g,""));
}

//IE6 PNG 투명 정상처리
function setPng24(obj) { 
	obj.width=obj.height=1; 
	obj.className=obj.className.replace(/\bpng24\b/i,''); 
	obj.style.filter = 
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
	obj.src='';  
	return ''; 
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {	//while open
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
   }	//while close
   return null;
}
