﻿//----------------------------------------
// Return true if a string contains the specific Language
//----------------------------------------
function checkUnicodeLanguage(sString, sLang) {
	if (sLang=="S" || sLang=="T")
		return (sString.search(/[\u4e00-\u9fa5\uf900-\ufa2d]/g) > -1);
	else if (sLang=="K")
		return (sString.search(/[\u1100-\u11f9\uac00-\ud7a4]/g) > -1);
	else if (sLang=="R")
		return (sString.search(/[\u0401-\u045f]/g) > -1);
	else if (sLang=="E")
		return (sString.search(/[\u0041-\u005a\u0061-\u007a]/g) > -1);
	else if (sLang=="J")
		return (sString.search(/[\u3041-\u30fe\u4e00-\u9fa5\uf900-\ufa2d]/g) > -1);
	else return false;
}

//----------------------------------------
// Return true if a given object has empty value attribute
//----------------------------------------
function isEmptyString(obj, fieldname)
{
	if(obj.value == "")
	{ gfgdf = "fdfsd"
	    var lang = "<"
		alert("please fill " + ": " + fieldname + "!");
		obj.select();
		obj.focus();
		return true;
	}
	return false;
}

function isEnglishName(str)
{
	return (str.match(/[^\x00-\x7F]+/)==null);
	//return (str.match(/[^A-Za-z0-9\.\,\;\_\s\-\']+/)==null);
}

function isEnglishCompanyName(str)
{
	return isASCII_Code(str);
}

function isLoginName(str)
{
	return (str.match(/[^A-Za-z0-9\_\-\@\.\~]+/)==null);
}

function isASCII_Code(str)
{
	return (str.match(/[^\x00-\xFF]+/)==null);
}

function isValidEmailAddress(str) {
	//Allows [-] [_] [.]

	if (str.match(/[\s\(\)\[\]\<\>\\\;\:\,]+/) != null) {return false;}
	//if (str.match(/((\.\.)|(\.\-)|(\.\@)|(\-\.)|(\-\-)|(\-\@)|(\@\.)|(\@\-)|(\@\@))+/) != null) {return false;} //prevent abuse of special char
	if (str.match(/((\.\@)|(\@\.))+/) != null) {return false;} //prevent abuse of special char
	//if (str.indexOf("\'") != -1) {return false;}
	if (str.indexOf("\"") != -1) {return false;}
	if (str.match(/^[\@\-\_\.]/ig) != null) {return false;} //prevent abuse of starting char
	if (str.match(/^[^\@]+\@[^\@]+\.(A[C-GL-OQ-UWXZ]|B[ABD-JM-OR-TVWYZ]|C[ACDF-IK-ORUVX-Z]|D[EJKMOZ]|E[CEGR-U]|F[I-KMOR]|G[ABD-IL-NP-UWY]|H[KMNRTU]|I[DEL-OQ-T]|J[EMOP]|K[EG-IMNPRWYZ]|L[A-CIKR-VY]|M[AC-EGHK-Z]|N[ACE-GILOPRUZ]|OM|P[AE-HKL-NR-TWY]|QA|R[EOSUW]|S[A-EG-ORT-VYZ]|T[CDF-HJ-PRTVWZ]|U[AGKMSYZ]|V[ACEGINU]|W[FS]|XN|Y[ETU]|Z[AMW]|AERO|ARPA|ASIA|BIZ|CAT|COM|COOP|EDU|GOV|INFO|INT|JOBS|MIL|MOBI|MUSEUM|NAME|NET|ORG|PRO|TEL|TRAVEL)$/i) == null) {return false;}
	return true;
}

function isValidEmailAddressList(str) {

	if ( trim2(str) == "") return false; //whole string is empty
	if (str.match(/((\;\;)|(\;\,)|(\,\;)|(\,\,))+/) != null) {return false;} //prevent abuse of special char	
	str = " " + str + " "; //Why need this? IE javascript will not count empty string an array item in split
	
	//Allows using ";" and ',' to split multiple email
	var tempArray = str.split(/[\;\,]/)
	var i;
	var checkResult = true;

	if ( trim2(tempArray[0]) == "") return false; //first is empty
	for (i=0; i<=tempArray.length-1; i++) {
		if (i==tempArray.length-1 &&  trim2(tempArray[i])=="") {break;}
		if (!isValidEmailAddress( trim2(tempArray[i]) )) {
			checkResult = false;
			break;
		}
	}
	return checkResult;
}

function trim2(s) {
	return s.replace(/^\s+|\s+$/g, "");
}

function isValidWebSiteAddress(str) {
	if ( trim2(str) == "") return false; //whole string is empty
	if (str.match(/https?/) == null) {return false;}
}

/*
function ValidEmailAddress(obj, err_msg)
{
	// no space, minimum a@b.cc, length < 50
	email_addr = obj.value;
	len = email_addr.length;
	SpaceIndex = email_addr.indexOf(' ', 0);
	AtIndex = email_addr.indexOf('@', 1);
	DotIndex = email_addr.indexOf('.', AtIndex);
	
	if(len > 50)
	{
		alert(err_msg);
		obj.focus();
		obj.select();
		return true;
	}
		
	if ((SpaceIndex == -1) && 
		(AtIndex > 0) && 
		(DotIndex > (AtIndex + 1)) && 
		(len > (DotIndex + 2)) && 
		(email_addr.charAt(len-1) != '.'))
	{
		return false;
	} else {
		alert(err_msg);
		obj.focus();
		obj.select();
		return true;
	}
	return false;
}
*/
/*
function digitvalidation(entered, min, max, alertbox)
{
	with (entered)
	{
		digitcount = entered.value.replace(/[^0-9]/g, "").length;
		
		if ((digitcount < min) || (digitcount > max)) {
			alert(alertbox);
			return false;
		} else {
			return true;
		}
	}
} 
*/
/*
function digitvalidation2(entered)
{
	var dx = entered.value.replace(/[^0-9]/g, "").length
	alert(dx)
} 

function trim(s) {
	return s.replace(/^\s+|\s+$/g, "");
}
*/
