//document.title = 'Ancom Electrical (HK) Limited';



function winPop() {
	goURL = "in2.htm";
	var w = screen.width
	var h = screen.height
	var l = (screen.width - w)/4;
	var t = (screen.height - h)/2;

	//if(screen.height>944) winTop=winTop-20;
	//var popWin = window.open(goURL,"full","resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,screenX=0,screenY=0,left="+l+",top="+t+",width="+w+",height="+h+"");
	//window.opener = this;
	//self.close();
}



//

function right(e) {  

if (navigator.appName == 'Netscape' &&  (e.which == 3 || e.which == 2))  

return false;  

else if (navigator.appName == 'Microsoft Internet Explorer' &&   

(event.button == 2 || event.button == 3)) {  

// 
return false;  


}  

return true;  

}  

/*
document.onmousedown=right;  

if (document.layers) window.captureEvents(Event.MOUSEDOWN);  

window.onmousedown=right;
*/

/* */
document.oncontextmenu = function(){return false;}
//document.onselectstart = function(){return false;}





/*
*/
function Trim( str ) {
		
	var resultStr = "";
		
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;	
	if (str+"" == "undefined" || str == null) return null;	
	str += "";
	
	if (str.length == 0) resultStr = "";
	else {	
		len = str.length;					
  		while ((i <= len) && (str.charAt(i) == " "))i++;   	
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
} 

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;	
	
	if (str+"" == "undefined" || str == null) return null;
	str += "";
		
	if (str.length == 0) resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
	  		resultStr = str.substring(0, i + 1);
	  	}
	  	
	  	return resultStr;  	
}


 
function onlyNumber(el) {
  el.value = el.value.replace(/\D/g,'');
}


function setInputAlert(field, fieldName) {	
	if(Trim(field.value) == "") {
		alert(fieldName +" 殮溘輿撮蹂.");
		field.focus();
		return false;
	}else{
		return true;
	}
}


function setSelectAlert(field, fieldName) {	
	if(Trim(field.value) == "") {
		alert(fieldName +" 摹鷗輿撮蹂.");		
		field.focus();
		return false;
	}else{
		return true;
	}
}


function setCheckAlert(field, fieldName) {	
	var temp = 0;
	for(i = 0; i < field.length; i++){
		if(field[i].checked == true){
			temp = temp + 1;
		}
	}
	
	if(temp == 0){
		alert(fieldName+" 摹鷗輿撮蹂.");
		return false;
	}else{
		return true;
	}
}

/*
chars = "ABC"
containsCharsOnly("string",chars)
*/
function containsCharsOnly(input,chars) {
	for(var inx = 0; inx < input.length; inx++) {
       	if (chars.indexOf(input.charAt(inx)) == -1){
           return false;
		}
    }
    return true;
}


/*
Auto Tab 
 : onKeyUp="return autotab(this, 6, event);" 
*/
function autotab(input,len, e) {
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keycd = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !iscontain(filter, keycd))
	{
	  input.value = input.value.slice(0, len);
	  input.form[(getindex(input)+1) % input.form.length].focus();
	}
}


function moveNext(src_id,dst_id,size) {

	var curSize  = document.getElementById(src_id).value.length;

	if (curSize == size) {
		document.getElementById(dst_id).focus();
	}
}



//
function checkSocialID(obj){
    var pattern = /^([0-9]{6})-?([0-9]{7})$/; 
	var num = obj.value;
    if (!pattern.test(num)){
		alert("輿團蛔煙廓蒂 檣輿撮蹂.");
		obj.focus();
		return false;
	}

    num = RegExp.$1 + RegExp.$2;

	var sum = 0;
	var last = num.charCodeAt(12) - 0x30;
	var bases = "234567892345";

	for (var i=0; i<12; i++){
		if (isNaN(num.substring(i,i+1))){
			alert("輿團蛔煙廓蒂 檣輿撮蹂.");
			obj.focus();
			return false;
		}

		sum += (num.charCodeAt(i) - 0x30) * (bases.charCodeAt(i) - 0x30);
	}

	var mod = sum % 11;
	if ((11 - mod) % 10 != last){
		alert("輿團蛔煙廓蒂 檣輿撮蹂.");
		obj.focus();
		return false;
	}

	return true;
}

//輿團蛔煙廓 匐餌
function socialIDCheck(userNo){
    var pattern = /^([0-9]{6})-?([0-9]{7})$/; 
	var num = userNo;
    if (!pattern.test(num)){
		return false;
	}

    num = RegExp.$1 + RegExp.$2;

	var sum = 0;
	var last = num.charCodeAt(12) - 0x30;
	var bases = "234567892345";

	for (var i=0; i<12; i++){
		if (isNaN(num.substring(i,i+1))){
			return false;
		}
		sum += (num.charCodeAt(i) - 0x30) * (bases.charCodeAt(i) - 0x30);
	}

	var mod = sum % 11;
	if ((11 - mod) % 10 != last){
		return false;
	}
	return true;
}

function stringLength(str){
	char_cnt = 0;

	for (var i = 0; i < str.length; i++)	{
		var chr = str.substr(i,1);
		chr = escape(chr);
		key_eg = chr.charAt(1);

		switch(key_eg){
		case "u":
			key_num = chr.substr(2,(chr.length - 1));
			char_cnt += 2;
			break;
		case "B":
			char_cnt += 2;
			break;
		default:
			char_cnt += 1;
		}
	}

	return char_cnt;
}

//
function checkEmail(obj)
{
	var exp = new RegExp ("^[A-Za-z0-9-_\\.]{2,}@[A-Za-z0-9-_\\.]{2,}\\.[A-Za-z0-9-_]{2,}$");

	// 
	if (stringLength(obj.value) == obj.value.length && exp.test(obj.value)){
		return true;
	}else{
		alert("檜詭橾 輿模蒂 檣輿撮蹂.");
		obj.focus();
		return false;
	}
}

//
function emailCheck(email)
{
	var exp = new RegExp ("^[A-Za-z0-9-_\\.]{2,}@[A-Za-z0-9-_\\.]{2,}\\.[A-Za-z0-9-_]{2,}$");

	//
	if (stringLength(email) == email.length && exp.test(email)){
		return true;
	}else{
		return false;
	}
}

//
function idCheck(id)
{
	var exp = new RegExp ("^[a-z]{1,}[a-z0-9]{5,8}$");

	if (exp.test(id)){
		return true;
	}else{
		return false;
	}
}

//
function pwCheck(pw)
{
	var exp = new RegExp ("^[a-z0-9]{6,8}$");

	if (exp.test(pw)){
		return true;
	}else{
		return false;
	}
}

function checkValue(checkbox) {
	var countChecked = 0;
	if(checkbox.checked) {
		countChecked = checkbox[i].value;
	} else {
		for( i=0 ; i<checkbox.length ; i++ ) {
			if( checkbox[i].checked ) {
				countChecked = checkbox[i].value;
			}
		}
	}
	return countChecked;
}

function isNumber(str){
	var exp = new RegExp ("^[0-9]{1,}$");

	if (exp.test(str)){
		return true;
	}else{
		return false;
	}	
}
function checkCount(checkbox) {
	var countChecked = 0;
	if(checkbox.checked){
		countChecked++;
	} else {
		for( i=0 ; i<checkbox.length ; i++ ) {
			if( checkbox[i].checked ) {
				countChecked++;
			}
		}
	}
	return countChecked;
}

// Flash
function swf_func(id_name,swf_name,width,height){ 
document.writeln("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='/asset/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' id='"+id_name+"' align='middle'>");
document.writeln("<param name='allowScriptAccess' value='always'>");
document.writeln("<param name='movie' value='"+swf_name+"'>");
document.writeln("<param name='quality' value='high'>");
document.writeln("<param name='bgcolor' value='#ffffff'>");
document.writeln("<param name='wmode' Value='Transparent'>");
document.writeln("<EMBED id='" + id_name + "' src='"+swf_name+"' width='"+width+"' height='"+height+"' type='application/x-shockwave-flash' wmode='transparent'></EMBED>");
document.writeln("</object>");
}

//
function mov_func(id,name,width,height,showcontrols){
document.writeln("<OBJECT classid='clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95' width='"+width+"' height='"+height+"' id='"+id+"'>");
if (name != "")
	{document.writeln("<PARAM NAME='Filename' VALUE='" +name+ "'>");
		}else{
			document.writeln("<PARAM NAME='TransparentAtStart' VALUE='1'>");
			document.writeln("<PARAM NAME='AnimationAtStart' VALUE='0'>");	
}
document.writeln("<PARAM NAME='Showcontrols' VALUE='"+showcontrols+"'>");
document.writeln("<PARAM NAME='Autostart' VALUE='true'>");
document.writeln("</OBJECT>");
}

//
// : openPopup('auth_write.asp','auth',667,500,'scrollbars=yes,width=667,height=500')
function openPopup( url, name, width, height, features) {
    var left= ( screen.width   - width ) / 2;
    var top = ( screen.height   - height ) / 2;
    return window.open(url, name, features + ',left=' + left + ', top=' + top);
}


//
function onlyKorean(str){
	for ( var i=0; i < str.length; i++ ) {
		if ( str.charCodeAt(i) < 0xAC00 || str.charCodeAt(i) > 0xD7A3){
			if (( str.charCodeAt(i) < 12593 || str.charCodeAt(i) > 12643 ) && ( str.charCodeAt(i) != 32)) {
				return true;
			}
		}
	}	
	return false;
}

//
function $() {
	var ret = [];
	for(var i=0; i < arguments.length; i++) {
		if (typeof arguments[i] == 'string') {
			ret[ret.length] = document.getElementById(arguments[i]);
		} else {
			ret[ret.length] = arguments[i];
		}
	}
	return ret[1]?ret:ret[0];
}

//
function setNull(obj) {
	while (0 < obj.options.length){
		obj.options[0] = null;
	}
}

//
function createOptions(sel,_options){
	if(_options == null || _options.length == 0){
		return;
	}

	for(var i = 0;i<_options.length;i++){
		opt = document.createElement("option");
		opt.value = _options[i].rtnVal;
		var op = document.createTextNode(_options[i].rtnName)
		if(_options[i].rtnStyle == '1'){
			opt.style.color = "#F9483A";
		}
		opt.appendChild(op);
		sel.appendChild(opt);
	}
}

//


function isValidPhone(input) {
	var format = /^(\d+)-(\d+)-(\d+)$/;
	return isValidFormat(input,format);
}


function isValidFormat(input,format) {
	if (input.value.search(format) != -1) {
		return true; 
	}
	return false;

}




function EmbedInclude(url,w,h){
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width="+w+" height="+h+"><param name='movie' value="+url+"><param name=quality value=high><param name=wmode value=transparent><embed src="+url+" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+w+" height="+h+" wmode=transparent></embed></object>");
}


function imgOver(obj,chk){



		var str = "" ;

		if (typeof(obj) == "object")
		{

			str = obj.src ;

			if(chk){

				str = str.replace(/_off/g, "_on") ;

			}else{

				str = str.replace(/_on/g, "_off") ;

			}

			obj.src = str;

			
		}else if(typeof(obj) == "string"){

			str = obj;

			if(chk){

				str = str.replace(/_off/g, "_on") ;

			}else{

				str = str.replace(/_on/g, "_off") ;

			}

			return str ;

		}


	
}



function openPop(url,width,height,scroll){ 
var popup = window.open(url,'popup','width='+width+',height='+height+',scrollbars=' + scroll);
popup.focus(); 
}

