//
// isWhitespace (s)                    Check whether string s is empty or whitespace.
// isLetter (c)                        Check whether character c is an English letter 
// isDigit (c)                         Check whether character c is a digit 
// isLetterOrDigit (c)                 Check whether character c is a letter or digit.
// isInteger (s [,eok])                True if all characters in string s are numbers.
// isFloat (s [,eok])                  True if string s is an unsigned floating point (real) number. (Integers also OK.)// isAlphabetic (s [,eok])             True if string s is English letters 
// isAlphanumeric (s [,eok])           True if string s is English letters and numbers only.
// isEmail (s [,eok])                  True if string s is a valid email address.
// isYear (s [,eok])                   True if string s is a valid Year number.
// isIntegerInRange (s, a, b [,eok])   True if string s is an integer between a and b, inclusive.
// isMonth (s [,eok])                  True if string s is a valid month between 1 and 12.
// isDay (s [,eok])                    True if string s is a valid day between 1 and 31.
// daysInFebruary (year)               Returns number of days in February of that year.
// isDate (year, month, day)           True if string arguments form a valid date.
// isTel(s)
// isFax(s)
// isURL(s)
// isLoginName(s)

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var whitespace = " \t\n\r";
// decimal point character differs by language and culture
var decimalPointDelimiter = "."
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- （）,";
var validUSPhoneChars = digits + phoneNumberDelimiters;

// Returns true if string s is empty or 
// whitespace characters only.

// Check whether string s is empty.

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   

	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c=="_") )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

	if(sLength>50) return false;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function isYear (s)
{   if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isMonth (s)
{
	if (s.substring(0,1) == '0') s=s.substring(1,2)
    if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{
	if (s.substring(0,1) == '0') s=s.substring(1,2)
    if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}


function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
	if (month.substring(0,1) == '0') month=month.substring(1,2)
	if (day.substring(0,1) == '0') day=day.substring(1,2)
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// isTel(s)
function isTel(s)
{
	if(s.length>40) return false;
	
	var ix;
	for(ix=0;ix<s.length;ix++)
	{
		var c = s.charAt(ix);
		if (validUSPhoneChars.indexOf(c)==-1) return false;
	}
	return true;	
}

// isFax(s)
function isFax(s)
{
	if(s.length>20) return false;
	
	var ix;
	for(ix=0;ix<s.length;ix++)
	{
		var c = s.charAt(ix);
		if (validUSPhoneChars.indexOf(c)==-1) return false;
	}
	return true;	
}

// isURL(s)
function isURL(s)
{
	if(s.length>40) return false;
	return true;
}

// isMobile(s)
function isMobile(s)
{
	if(s.length>11) return false;
	var first_c= s.charAt(0);
	var second_c= s.charAt(1);
	if( (first_c!="1")||(second_c!="3") ) return false; 
	return isDigit(s);
}

// isCorpName(s)
function isCorpName(s)
{
	if(s.length>30) return false;
	return true;
}
// isShortName(s)
function isShortName(s)
{
	if(s.length>6) return false;
	return true;
}
// isCorpCode(s)
function isCorpCode(s)
{
	if(s.length>30) return false;
	return isAlphanumeric(s);
}
// isPostal(s)
function isPostal(s)
{
	if(s.length>10) return false;
	return isDigit(s);
}

function isLoginName(s)
{
	if(s.length>30) return false;
	return isAlphanumeric(s);
}

var province=new Array("全国","安徽","北京","福建","甘肃","广东","广西","贵州","海南","河北","河南","黑龙江","湖北","湖南","吉林","江苏","江西","辽宁","内蒙古","宁夏","青海","山东","山西","陕西","上海","四川","天津","西藏","新疆","云南","浙江","重庆","台湾","香港","澳门")

function Province_Print(v_province)
{
	document.writeln("<select name=province style='width:100px'>");
	document.writeln("<option value=''>请选择</option>");
	for (var i=0; i<province.length; i++)
	{
	if (province[i] == v_province)
	{
		document.writeln("<option value=" + province[i] + " selected>" + province[i] + "</option>");
	}
	else
	{
		document.writeln("<option value=" + province[i] + ">" + province[i] + "</option>");
	}
	}
	document.writeln("</select>");
}

var industry=new Array("勘察设计","建筑施工","建筑安装","建筑装饰","建设监理","房地产开发","建筑材料","建筑设备","行政机关","其他")
function Industry_Print(v_industry)
{
	document.writeln("<select name=industry style='width:100px'>");
	document.writeln("<option value=''>请选择</option>");
	for (var i=0; i<industry.length; i++)
	{
	if (industry[i] == v_industry)
	{
		document.writeln("<option value=" + industry[i] + " selected>" + industry[i] + "</option>");
	}
	else
	{
		document.writeln("<option value=" + industry[i] + ">" + industry[i] + "</option>");
	}
	}
	document.writeln("</select>");
}

var education=new Array("无","初中","高中","中技","中专","大专","本科","硕士","博士","其他");
function Education_Print(v_edu)
{
	document.writeln("<select name=edu style='width:100px'>");
	document.writeln("<option value=''>请选择</option>");
	for (var i=0; i<education.length; i++)
	{
	if (education[i] == v_edu)
	{
		document.writeln("<option value=" + education[i] + " selected>" + education[i] + "</option>");
	}
	else
	{
		document.writeln("<option value=" + education[i] + ">" + education[i] + "</option>");
	}
	}
	document.writeln("</select>");
}


var Professional=new Array("城乡规划","园林景观","建筑设计","室内设计","建筑结构","给水排水","暖通空调","电气工程","岩土工程","工程造价","建筑施工","建筑安装","市政工程","建筑监理","地产物业","路桥隧道","其他类别");
function Professional_Print(v_prof)
{
	document.writeln("<select name=prof style='width:100px'>");
	document.writeln("<option value=''>请选择</option>");
	for (var i=0; i<Professional.length; i++)
	{
	if (Professional[i] == v_prof)
	{
		document.writeln("<option value=" + Professional[i] + " selected>" + Professional[i] + "</option>");
	}
	else
	{
		document.writeln("<option value=" + Professional[i] + ">" + Professional[i] + "</option>");
	}
	}
	document.writeln("</select>");
}

var IdentityName=new Array("身份证","护照","军人证","其他");

function Identity_Print(v_identity)
{
	document.writeln("<select name=identity_name style='width:100px'>");
	document.writeln("<option value=''>请选择</option>");
	for (var i=0; i<IdentityName.length; i++)
	{
	if (IdentityName[i] == v_identity)
	{
		document.writeln("<option value=" + IdentityName[i] + " selected>" + IdentityName[i] + "</option>");
	}
	else
	{
		document.writeln("<option value=" + IdentityName[i] + ">" + IdentityName[i] + "</option>");
	}
	}
	document.writeln("</select>");
}


function show_user(login_name) {

	newwin= window.open('http://www.zhulong.com/tech/show_user.asp?u='+login_name );
	newwin.focus();
}


function chkblank(obj,msg) {
		if(isWhitespace(obj.value)) {
			alert(msg);
			obj.focus();
			return false;
		}

	return true;
}

function confbuy(u,buy_price) {
	if(u=='') {
		alert("您还没有登陆网站，请先从页面上端登陆\n\n如果您还不是筑龙网的注册会员，请先点击页面上端的<新注册>免费成为筑龙网会员");
		return false;
	}
              	if(confirm("                         此资料价格为" + buy_price + "筑龙币，确定要购买吗?\n\n\说明：\n1、点击<确定>后完成资料购买，您可以在三天之内随时点击网页最上端的<提货区>下载\n\n2、如果您在三天之内购买过此资料，系统不会重复从您的帐户扣除筑龙币\n\n3、明明白白消费，您的筑龙币使用记录请点击网页最上端的<我的帐户>查询")) 
              		return true;
              		
              	return false;
}
function chkcart(u) {
	if(u=='') {
		alert("只有注册用户可以使用购物车，请先登陆！");
		return false;
	}
}

function GetStringLen(s)
{
	en_num=0;
	cn_num=0;
	for( var char_ix=0;char_ix<s.length;char_ix++) 
	{
		if(isLetterOrDigit(s.charAt(char_ix)))
			en_num++;
		else
			cn_num++;
	}
	return en_num+cn_num*2;
	
}	
