// JavaScript Document
var badword = new Array("shit","fuck","asshole","suck","pussy","penis","dick","bitch","damn","sucker","fucker");
var symbol = new Array("~","`","!","#","$","%","^","&","*","=","+","|","<",">","?","/",";",":","[","]","{","}","'","\\");

function checkNumber(conName) {
 var selname = document.getElementById(conName);
  if (selname.length > 0) {
	for(i=0;i<selname.length;i++) {
		if(isNaN(selname[i].value)) {
			alert("数字のみ入力可能です。");
			selname[i].focus();			
			return -1;
			break;			
			
		}
	}   
  }else{
	if(isNaN(selname.value)) {  
	alert("数字のみ入力可能です。");
	selname.focus();	
	return -1;
	}
  }
	 return 1;
}


function checkBlank(conName,alt)  {
 var selname = document.getElementById(conName);
 if (selname.length > 0) {
	for(i=0;i<selname.length;i++) {
		if(selname[i].value == "") {
		  alert(alt);
		  selname[i].focus();
		  return -1;
		  break;
		}
	}
 }else{
	if (selname.value == "") {
		  alert(alt);
		  selname.focus();
		  return -1;
	}
 }
 return 1;
 

}

function checkRadio(conName) {	
  
 }



function addSelectBox(conName,strArray) {
	
		var sel_name = document.getElementById(conName);
	    sel_name.selectedindex = 0;
		var strV=""
		var strT=""
	    //alert("ddd"); 
       
          optno = 0   
		  
		  
		  //alert(strArray.length);
		  for(i=0;i<strArray.length;i++) { 
		  var opt = document.createElement("OPTION");
		  strSubString = strArray[i].substring(strArray[i].indexOf("$"),strArray[i].length);
		  strV = strArray[i].substring(strArray[i].indexOf("$")+1,strArray[i].lastIndexOf("$"));
		  strT = strArray[i].substring(strArray[i].lastIndexOf("$")+1,strArray[i].length);
		  
		  opt.text = strT; 
		  opt.value = strV; 
		  sel_name.add(opt,optno); 
		  optno = optno + 1
		  }
		  
		  sel_name.options.length = optno; 		  
  	
}

function addSelectBoxSing(conName,strV,strT,addIndex) {
var sel_name = document.getElementById(conName);
	      sel_name.selectedindex = 0;

          optno = addIndex 
		  var opt = document.createElement("OPTION");
		  opt.text = strT;
		  opt.value = strV;
		  sel_name.add(opt,optno);
		  sel_name.options.length = optno+1;

}




function selectSelectBox(conname,value) {
	 var selName = document.getElementById(conname) 
	 for(i=0;i<selName.length;i++) {
		  if(selName[i].value == value) {
			  selName[i].selected = true;  
		  }
	 }
	
	
}




function wino(url,target,spec) {	
	window.open(url,target,spec);	
}



function leapYear(year) {
if (year % 4 == 0) return true;	
}
function getLastday(year,month) {
var arrID = new Array();
arrID[0] = 31
arrID[1] = (leapYear(year)) ? 29 : 28
arrID[2] = 31
arrID[3] = 30
arrID[4] = 31
arrID[5] = 30
arrID[6] = 31
arrID[7] = 31
arrID[8] = 30
arrID[9] = 31
arrID[10] = 30
arrID[11] = 31
return arrID[month-1]
}





function checkJumin(conId1,conId2) {

    var objid1 = document.getElementById(conId1);
	var objid2 = document.getElementById(conId2);

  if (JuminCheck(objid1.value,objid2.value) == -1) {
  alert("Incorrect Data!");
  objid1.focus();
  return -1;
  }
}

function JuminCheck(no1,no2) {	     

        if (no1.length != 6)
        {
           return -1; 
         }        
        else if (no2.length != 7)
        {
           return -1;   	
         }        
        else {
           var str_serial1 = no1;
           var str_serial2 = no2; 
           var digit=0
           for (var i=0;i<str_serial1.length;i++){
           var str_dig=str_serial1.substring(i,i+1);
           if (str_dig<'0' || str_dig>'9'){ 
           digit=digit+1 
             }
           }
		
         if ((str_serial1 == '') || ( digit != 0 ))
         {            
            return -1;   	
          }
		  
         var digit1=0
            for (var i=0;i<str_serial2.length;i++){
                var str_dig1=str_serial2.substring(i,i+1);
                 if (str_dig1<'0' || str_dig1>'9'){ 
                     digit1=digit1+1 
                    }
            }
    
	    if ((str_serial2 == '') || ( digit1 != 0 ))
         {            
            return -1;   
          }

        if (str_serial1.substring(2,3) > 1)
         {          
            return -1;   
          }
		  
         if (str_serial1.substring(4,5) > 3)
         {            
            return -1;   	
          } 
		  
         if (str_serial2.substring(0,1) > 4 || str_serial2.substring(0,1) == 0)
         {         	
            return -1;   	
          }
		  
            var a1=str_serial1.substring(0,1)
            var a2=str_serial1.substring(1,2)
            var a3=str_serial1.substring(2,3)
            var a4=str_serial1.substring(3,4)
            var a5=str_serial1.substring(4,5)
            var a6=str_serial1.substring(5,6)         
            var check_digit=a1*2+a2*3+a3*4+a4*5+a5*6+a6*7

            var b1=str_serial2.substring(0,1)
            var b2=str_serial2.substring(1,2)
            var b3=str_serial2.substring(2,3)
            var b4=str_serial2.substring(3,4)
            var b5=str_serial2.substring(4,5)
            var b6=str_serial2.substring(5,6)
            var b7=str_serial2.substring(6,7)         
            var check_digit=check_digit+b1*8+b2*9+b3*2+b4*3+b5*4+b6*5 
        
            check_digit = check_digit%11
            check_digit = 11 - check_digit
            check_digit = check_digit%10

         if (check_digit != b7 || str_serial1+str_serial2 == 1111111111118)
         {
            return -1;   	
         }        
         else
         {         
                        return 1;   	            			
         }
		 
		 
 } 
 

}


function checkEmail(str) {
	
	//ｱ貘ﾌ ﾃｼﾅｩ
   if(str.length < 8) {
		alert("メールアドレス形式ではありません。");
		return -1;
	}       	

   for(i=0;i<=str.length;i++){
		if(str.charCodeAt(i)>12543){  
		alert("メールアドレス形式ではありません。");
		return -1;
		break;
		}
	}		
	
        
   if ( str.search(/(^\..*)|(.*\.$)/) != -1 || str.search(/\S+@(\S+)\.(\S+)/) == -1 ) {  
		alert("メールアドレス形式ではありません。");
		return -1;
	}	

        if (EmailCheck(str) == false ) {
		return -1;	
	}		

    for(var i=0;i<badword.length;i++) {
    if (str.indexOf(badword[i])>=0) {
		alert("\'"+badword[i]+"\'メールアドレス形式ではありません。");
		return -1;
        	}
        }

    for(var i=0;i<symbol.length;i++) {
    if (str.indexOf(symbol[i])>=0) {
		alert("メールアドレス形式ではありません。");
		return -1;
        	}
        }
} 
function EmailCheck (emailStr)           
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var firstChars=validChars
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom="(" + firstChars + validChars + "*" + ")"
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray = emailStr.match(emailPat)
	if (matchArray == null) 
	{
		alert("Incorrect Data!")
		return false
	}
	var user = matchArray[1]
	var domain = matchArray[2]

	if (user.match(userPat) == null) 
	{
		alert("Incorrect Data!")
		return false
	}

	var IPArray = domain.match(ipDomainPat)
	if (IPArray != null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i] > 255) 
			{
				alert("Incorrect Data!")
				return false
			}
		}
		return true
	}

	var domainArray = domain.match(domainPat)
	if (domainArray == null) 
	{
		alert("Incorrect Data!")
		return false
	}

	var atomPat = new RegExp(atom,"g")
	var domArr = domain.match(atomPat)
	var len = domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length > 3) 
	{
		alert("Incorrect Data!")
		return false
	}

	if (domArr[domArr.length-1].length == 2 && len < 3) 
	{
		alert("Incorrect Data!")
		return false
	}

	if (domArr[domArr.length-1].length == 3 && len < 2) 
	{
		alert("Incorrect Data!")
		return false
	}
	return true;
}

function objectView(flag,imgid) {
var selfield = document.getElementById(imgid);
if (flag == 0) {
selfield.style.display="none";
}else if(flag == 1) {
selfield.style.display = "";	
}

}


function showPost(conPost,conAddr) {
 window.open('/include1/post.asp?conPost='+conPost+'&conAddr='+conAddr,'WinPost','width=418 height=200 scrollbars=yes');		
}

function showIdcheck(conName) {
 var conid = document.getElementById(conName);
 var strid = conid.value;
 window.open('include/idcheck.asp?mem_id='+strid+'&conName='+conName,'winIdcheck','width=300 height=200');
	
}


function checkKorean(str) {
   for(i=0;i<=str.length;i++){
		if(str.charCodeAt(i)>12543){  
		alert("Incorrect Data!");
		return -1;
		break;
		}
	}			
}


function showUpload(strW,strH,strFieldName) {
	window.open('/upload/reg_scr.asp?imgWidth='+strW+'&imgHeight='+strH+'&imgField='+strFieldName,'imgUp','width=500 height=500 scrollbars=yes'); 
	
}

function showOrder(idx) {
	  window.open('/admin/view/order_view.asp?order_idx='+idx,'newOrder','width=650 height=500 scrollbars=yes');
}

function showProduct(idx) {
	 window.open('/admin/view/product_view.asp?pd_idx='+idx,'newProduct','width=680 height=500 scrollbars=yes');
}

function showMember(idx,id) {
	 window.open('member_view.asp?mem_idx='+idx+'&mem_id='+id,'newMember','width=680 height=470 scrollbars=yes');	
}


function showZoomImg(fileName,width,height) {
	window.open('/view/imgViewer.asp?fileName='+fileName+'&imgWidth='+width+'&imgHeight='+height,'newZoom','scrollbars=yes'); 
}


function showOrderPrint(order_oid) {
	window.open('/order/order_print.asp?order_oid='+order_oid,'orderPRINT','width=650 height=300 scrollbars=yes');
}

function showOPD(order_oid) {
	window.open('/admin/order/orderProduct_list.asp?order_oid='+order_oid,'opd','width=655 height=400 scrollbars=yes');
	
}

function showEmailSend(pd_idx) {
	window.open('/mailing/mail_scr.asp?pd_idx='+pd_idx,'newMail','width=630 height=500 scrollbars=yes');
}

function showwebmail() {
	window.open('http://email.gilink.co.kr','WebMail','width=900 height=650 scrollbars=yes');
}
function showwebhard(user_id) {
	window.open('../webhard/index.htm?user_id='+user_id,'Webhard','width=950 height=600 scrollbars=yes');
}
function showadmin(user_auth) {
	window.open('../MailAdmin/index.asp?user_auth='+user_auth,'MailAdmin','width=800 height=600 scrollbars=yes');
}
