// JavaScript
function gcscChangeView(Obj) {
	var Obj =eval("document.all."+Obj);
	var vTmpObj = document.all.A;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}	
	vTmpObj = document.all.E;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	vTmpObj = document.all.F;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	vTmpObj = document.all.N;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	vTmpObj = document.all.M;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	vTmpObj = document.all.C;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	vTmpObj = document.all.O;
	for (i =0; i < vTmpObj.length; i++) {
		vTmpObj[i].style.display = 'none';	
	}
	
	if (Obj == null)
	return;
	
	for (i=0;i < Obj.length;i++) {
		if (Obj[i] == null) {
			
		} else if (Obj[i].style.display != "none") {
			Obj[i].style.display = "none" ;
			//document.all.LINE_STYLE.style.display = "";	
		} else  {
			Obj[i].style.display = "";
			//document.all.LINE_STYLE.style.display = "";	
		}		
	}
}

function chooseCountryByName(cntryCode, serverDomain, serverKind) {    
    var form = document.gcscForm;    
    var url = '';
      if( cntryCode == 'KOR' )
        url = serverDomain;
    else
        url = serverDomain.concat("/index_b2c.jsp");    
    form.action = url;
    form.target = '_blank';
    form.tc.value = 'hpi.command.HpiCmd';
    form.COUNTRY_CODE.value = cntryCode;
    form.SERVER_DOMAIN.value = serverDomain;
    form.SERVICE_KIND.value = serverKind;        
    form.method = 'post';
    form.submit();
}

function chooseCountry(flag) {
    
    var form = document.gcscForm;
    
    var cntryStr = form.selCountry.options[form.selCountry.selectedIndex].value;
    var cntryCode = cntryStr.substring(0, cntryStr.indexOf("|"));
    var serverDomain = cntryStr.substring(cntryCode.length+1 , cntryStr.lastIndexOf("|"));
    var serviceKind = cntryStr.substring(cntryCode.length+serverDomain.length+2);
    var url = '';
    
    if( cntryCode == 'KOR' )
        url = serverDomain;
    else
        url = serverDomain.concat("/index_b2c.jsp");    
            
    if(form.selCountry.selectedIndex == 0 ){
        alert("choose your country!!");  
        form.selCountry.focus();
        return;
    }  

    form.action = url;
    form.target = '_blank';
    form.tc.value = 'hpi.command.HpiCmd';
    form.COUNTRY_CODE.value = cntryCode;
    form.SERVER_DOMAIN.value = serverDomain;
    form.SERVICE_KIND.value = serviceKind;
    
    if( flag == 1 ){
        form.LANG_CODE.value='';
        form.LANGCODE_CHARSET.value='';
        form.COUNTRY_KIND.value='';
        form.BUYER_CODE.value='';       
    }    
    form.method = 'post';
    form.submit();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  if(selObj.selectedIndex == 1 || selObj.selectedIndex == 0 ) return;
  eval("window.open('" + selObj.options[selObj.selectedIndex].value+"', '" + targ + "')");
  if (restore) selObj.selectedIndex=0;
}

// --------------------------------------------------------------------------------------------- //

// Show pop-up image window
function showPhoto(url,imgw,imgh, title) {
  imgparam = "height=" + imgh + ",width=" + imgw +",location=0,scrollbars=no,toolbar=no,directories=no,menubar=no,status=no,resizable=yes";
  OpenWindow=window.open("","",imgparam);
  OpenWindow.document.writeln("<html><head><title>"+title+"</title>");
  OpenWindow.document.writeln("<script language='JavaScript'> function myClose() { window.close(); } </script>");
  OpenWindow.document.writeln("</head><body bgcolor='#5091F5' leftmargin='0' topmargin='0' rightmargin='0' bottommargin='0' marginheight='0' marginwidth='0'>");
  OpenWindow.document.write("<table width=100% height=100% cellpadding=0 cellspacing=0 border=0><tr><td align=center valign=middle>");
  OpenWindow.document.write("<a href='javascript: myClose();'><img src='");
  OpenWindow.document.write(url);
  OpenWindow.document.writeln("' border='0' alt='Закрыть' onLoad='window.resizeTo(this.width, this.height)'></a></td></tr></table>");
  OpenWindow.document.writeln("</body></HTML>");
}

// Check required fileds
function checkFields(user_form, msg) {
	for (var i = 0; i < user_form.length; i++) {
		if (user_form[i].type == "text" || user_form[i].type == "textarea" || user_form[i].type == "password") {
			if (user_form[i].id == 1 && user_form[i].value == '') {
				if (msg != '') alert(msg);
				user_form[i].focus();
				return false;
			}
		}
	}
	
	return true;
}

// Check field
function validateField(field, error_message) {	
	if (field.value == '') {
		if (error_message != '') alert (error_message);
		field.focus();
		return false; 
	}
	
	return true; 
}

// Check only digits input
function onlyDigits() {
	with (window.event) {
		if (shiftKey)
			return false;
		if (
			(keyCode>=48 && keyCode<=57) ||
			keyCode == 9 ||
			keyCode == 116 ||
			keyCode == 8 ||
			keyCode == 13 ||
			keyCode == 39 ||
			keyCode == 37 ||
			keyCode == 190 ||
			keyCode == 191 ||
			keyCode == 46
			)
			return true;
		else
			return false;
	}
}

// Show DIV
function openDiv(layerID) {
	// get element by id
	if (window.document.all[layerID].style.display == 'none') {
		window.document.all[layerID].style.display = '';
	} else {
		window.document.all[layerID].style.display = 'none';
	}
}

// Show calculate result
function showCalculate(user_form, id, lang_id, ctype, cost, reward, day, month, year) {
	var url;
	if (checkFields(user_form)) {
		url = "page.php?page_id="+id+"&lang="+lang_id+"&lang_id="+lang_id+"&calc_type="+ctype+"&cost="+cost+"&reward_rate="+reward+"&day="+day+"&month="+month+"&year="+year+"&calculate";
		showDoc(url, 900, 600);
		return true;
	}
	
	return false;
}

// Show document in new window
function showDoc(sDocPath, width, height) {
	var top, left;
	top = Math.floor((screen.height - height)/2-14);
	left = Math.floor((screen.width - width)/2);
	wparam = "left=" + left + ",top=" + top + ",height=" + height + ",width=" + width +",location=0,scrollbars=yes,toolbar=no,directories=no,menubar=yes,status=no,resizable=yes";
	window.open(sDocPath, '', wparam);
}
