﻿function LTrim(s) {
	return s.replace(/^\s+/g,"");
}

function RTrim(s) {
	return s.replace(/\s+$/g,"");
}

function Trim(s) {
	return LTrim(RTrim(s));
}

function Len(s) {
	var s1 = Trim(s);
	return s1.length;
}

function num_only()
{
	if(((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode != 46)) {
	event.returnValue=false;
	}
}

function CheckNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!(s.charAt(i) >= "0" && s.charAt(i) <= "9")) 
            return false;
	}

    return true;
}

function CheckStrNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!((s.charAt(i) >= "a" && s.charAt(i) <= "z") ||
	      (s.charAt(i) >= "A" && s.charAt(i) <= "Z") ||
	      (s.charAt(i) >= "0" && s.charAt(i) <= "9")))
            return false;
	}

    return true;
}

function CheckExceptStrNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!((s.charAt(i) >= "a" && s.charAt(i) <= "z") ||
	      (s.charAt(i) >= "A" && s.charAt(i) <= "Z") ||
	      (s.charAt(i) >= "0" && s.charAt(i) <= "9") ||
	      (s.charAt(i) == "_"))) 
            return false;
	}

    return true;
}

function CheckSpace(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (s.charAt(i) == " ") 
            return false;
	}

    return true;
}

function namosw_exchange_src() { 
	str = namosw_exchange_src.arguments[0];
	str = (navigator.appName == 'Netscape') ? 'document.' + str : 'document.all.' + str;
	img = eval(str);
	if (img) {
		if (img.ori_src == null) {
			img.ori_src = img.src;
			img.src     = namosw_exchange_src.arguments[1];
		} else {
			var temp    = img.src;
			img.src     = img.ori_src;
			img.ori_src = temp;
		}
	} 
}

function namosw_preload_img() { 
	var img_list = namosw_preload_img.arguments;
	if (document.preloadlist == null) document.preloadlist = new Array();

	var top = document.preloadlist.length;

	for (var i=0; i < img_list.length; i++) {
		document.preloadlist[top+i]     = new Image;
		document.preloadlist[top+i].src = img_list[i];
	} 
}
function CheckLogin(theForm) {
	if (Len(theForm.member_id.value) == 0) {
		alert('Fill in the account member ID.');
		theForm.member_id.focus();
		return false;
	}
	
	if (Len(theForm.passwd.value) == 0) {
		alert('Fill in the Password.');
		theForm.passwd.focus();
		return false;
	}
	
	return true;
}

function CheckSearch(theForm) {
	if (Len(theForm.search_value.value) == 0) {
		alert('Fill in the search word.');
		theForm.search_value.focus();
		return false;
	}

	if (theForm.search_key.options[theForm.search_key.selectedIndex].value == '') {
		alert('Select the search options');
		theForm.search_key.focus();
		return false;
	}

	theForm.action = theForm.search_key.options[theForm.search_key.selectedIndex].value;
	return true;
}

function CheckEmail(s) {
	var strEmail = s;
	var invalidChars = "~`!@#$%^&*()+=|\<,>?/'";
	
	if (Len(strEmail) == 0) {
		alert('Fill in the email address.');
		return false;
	}
	
	if (strEmail.indexOf("@") < 1) {
		alert('Wrong Email form.\n type : accountname@servername');
		return false;
	}
	
	var atPos = strEmail.indexOf("@", 1);
	var strID = strEmail.substring(0, atPos);
	var strServerName = strEmail.substring(atPos + 1);
	
	for(var i=0; i<invalidChars.length; i++ ) {
		var strBadChar = invalidChars.charAt(i);
		
		if (strID.indexOf(strBadChar) > -1) {
			alert('Email Wrong address. Confirm again please');	
			return false;
		}	
	}
	
	if (strServerName.indexOf(".") < 1) {
		alert('Email Wrong address. Confirm again please');	
		return false;
	}	
	
	for(var i=0; i<invalidChars.length; i++ ) {
		var strBadChar = invalidChars.charAt(i);
		
		if (strServerName.indexOf(strBadChar) > -1) {
			alert('Email Wrong address.Confirm again please');	
			return false;
		}	
	}
	
	return true;
}