/**************************************************
GetSelectedCount(theForm,sName) ��ȡSelected �ĸ���
Input:
  theForm:�?����
  sName:select���

Output:
  int (CheckBox �� Selected �ĸ���)


Author:Roger 2000-12-27
***************************************************/
function GetSelectedCount(theForm,sName){
  var obj;
  var iCount=0;
  for (var iLoop=0;iLoop<theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];
	if ((obj.name==sName)&&(obj.checked)){
        iCount++;
	}
  }
  return iCount;

}

/*********************************************
selectAllCheckBox(theForm,sName) ȫѡ��ѡ��
Input:
  theForm:�?����
  sName:checkbox���

Author:Roger 2000-12-27
***********************************************/

function selectAllCheckBox(theForm,sName,aSelfObj){
  var obj;
  var value="";
  //alert(theForm.length+sName);
  for ( iLoop=0;iLoop<theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];
    if (obj.name==sName){
        obj.checked = aSelfObj.checked;
	}
  }
}


/*********************************************
GetSelectedValue(theForm,sName) ��ȡSelectedֵ
Input:
  theForm:�?����
  sName:select���

Output:
  string(�ԡ������ŷָ��ֵ��)

Author:Roger 2000-12-27
***********************************************/

function GetSelectedValue(theForm,sName){
  var obj;
  var value="";
  alert(theForm.length+sName);
  for ( iLoop=0;iLoop<theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];

    if ((obj.name==sName)&&(obj.checked)){

      value+=obj.value+",";
	}
  }
  return value.substr(0,value.length-1);
}





/********************************************
SetCheckBox(theForm,sCBName,vValue)

Input:
 theForm:�?����
 sCBName:CheckBox���
 vValue:ҪSET��CheckBox ��ֵ

Output:
   int(Checked�����Ŀ  )

Author; Roger 2000-12-27
**********************************************/

function SetCheckBox(theForm,sCBName,vValue){
  var obj;
  var iCount=0;

  for ( iLoop=0;iLoop<theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];
	if ((obj.name==sCBName)&&(obj.value==vValue)){
      obj.checked=true;
      iCount++;
	}


  }
  return iCount;
}



/********************************************
SetInputValue(theForm,sInputName,vValue)
Input:
  theForm:�?����
  sName:select���

Output:
  Boolean(�ɹ����)

Author; Roger 2000-12-27
*********************************************/
function SetInputValue(theForm,sInputName,vValue){
  var obj;
  var bSet=false;
//alert();
  for ( iLoop=0;iLoop>theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];
	//alert(obj.name);
	if (obj.name==sInputName){
      switch (obj.type){

        case "checkbox" :
		  if (obj.value==vValue){
		    obj.checked=true;
		    bSet=true;

		  }
		  break;

        case "radio" :
          if (obj.value==vValue){
		    obj.checked=true;
		    bSet=true;
		  }
		  break;

	case "select" :
		  for(iInLoop=0;iInLoop<obj.length;iInLoop++){
			if (obj.options [iInLoop].value==vValue) {
				//alert(obj.options [iInLoop].value);
			  obj.selectedIndex =iInLoop;
			}
		  }
		  bSet=true;
		  break;

		default:
		  obj.value=vValue;
          bSet=true;

	   }
	 //break;
	}
  }
  return bSet;
}


/*********************
ShowMessage(sPath)
  ��ʾ��Ϣ����





**********************/
function ShowMessage(sPath){
  var sRet="";
  while ((sRet=="")||(sRet==undefined)){
    sRet=window.showModalDialog(sPath,'','dialogwidth=776px;dialogheight=600px;status=no;toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no');
    //alert(sRet);
  }

  switch (sRet){

    case "back":
      history.back();
      break;

    case "pending":
      window.location='../workfolder/pending_job.asp';
      break;

    case "regist":
      window.location='../default.asp';
      break;

    case "home":
      window.location='../index.asp';
      break;

    default:
  }

}

/**
*  ȡForm��Ķ���
*  tTheForm:Form����
*  tObjName:������
* /
  function getObjByName(tTheForm,tObjName) {
       myform = tTheForm;
       for ( iLoop=0;iLoop<tTheForm.length;iLoop++) {
           obj = tTheForm.elements[iLoop];
           if (obj.name==tObjName){
               return obj;
           }
        }
    }





/*********************
IsDate(sDate)
  �Ƿ�Ϸ�����
Input:
  sDate:��'-'�ŷָ�������ַ� �磺'1999-5-6'

Return:
  boolean


**********************/
function IsDate(sDate){
  var re='[0-9]{4}-[0-1]{0,1}[0-9]-[0-1]{0,1}[0-9]';
  return (sDate.match(re)!=null) ;

}




function GetRadioValue(theForm,sInputName){
  var obj;
  var bMatch=false;

  for ( iLoop=0;iLoop<theForm.length;iLoop++) {
    obj = theForm.elements[iLoop];
	if (obj.name==sInputName){
	  if (obj.checked==true){
		return obj.value;
	  }
	}
  }

  return null;
}


/**
 * �ж�������ַ��Ƿ��Ҫ��
 * ������ַ�
 * ���뷶Χ�ַ�
 * ��Ϸ���true���� false
 * **/
function checkStr(aSource,aLand){
    var checkOK = aLand;
    var checkStr = aSource;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)        {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)  if (ch == checkOK.charAt(j))  break;
        if (j == checkOK.length)  {
            allValid = false;
            break;
        }
        if (ch == ".")   {
            allNum += ".";
            decPoints++;
        }else if (ch != ",")  allNum += ch;
    }
    if (!allValid) {
        return (false);
    }else{
        return (true);
    }
}

/**
 * �Ƿ��Ѿ�ѡ�˵���ѡ��
 * ���أ�true �Ѿ�ѡ��
 *       false û��ѡ��
 * **/
function checkRadioIsSelect(theForm,objName,param) {
    var obj;
    for (var iLoop=0;iLoop<theForm.length;iLoop++) {
        obj = theForm.elements[iLoop];
        if (obj.name==objName && obj.checked==true){
            	return (true);
        }
    }
    setRadioFocus(theForm,objName)
    return (false);
}

/**
 * ʹ��ObjNameRadio �õ�����
 * **/
function setRadioFocus(theForm,objName){
     var obj;
     var iLoop;
      for ( iLoop=0;iLoop<theForm.length;iLoop++) {
        obj = theForm.elements[iLoop];
            if (obj.name==objName){
              obj.focus();
              return;
            }
      }
}





/**
LogicalValue:�����ж϶����ֵ�Ƿ�������������ṩ��ѡ���У�
integer�����ͣ������ж������ͺ͸�����
number ����ֵ�ͣ�ͬ����ж���
date �������ͣ���֧�����Զ���ָ������ڸ�ʽ��ȱʡ����'-'Ϊ�ָ��
string ���ж�һ���ַ��(�򲻰�(ĳЩ�ַ�
����ֵ��
true��false

����
ObjStr �������ʶ��������
ObjType����������('integer','number','date','string'֮һ)

����˵��
������ֵΪ��ʱ���򷵻ش���

Author:PPDJ

���ӣ�
example 1:Ҫ����������text1����������Ƿ��ǡ����͡���ݣ����ǣ�����ʾ
if (!LogicalValue('text1','integer')) alert('Error: Your must input a integer number');
example 2:Ҫ����������text1����������Ƿ��ǡ������͡���ݣ����ǣ�����ʾ
if (!LogicalValue('text1','integer','+')) alert('Error: Your must input a positive integer number');
example 3:Ҫ����������text1����������Ƿ��ǡ������͡���ݣ����ǣ�����ʾ
if (!LogicalValue('text1','integer','-')) alert('Error: Your must input a negative integer number');
exmaple 4:Ҫ����������text1����������Ƿ�����ֵ�����ǣ�����ʾ
if (!LogicalValue('text1','number')) alert('Error: Your must input a number');
exmaple 5:Ҫ����������text1����������Ƿ��ǡ�����ֵ�����ǣ�����ʾ
if (!LogicalValue('text1','number','+')) alert('Error: Your must input a number');
exmaple 6:Ҫ����������text1����������Ƿ��ǡ�������ֵ�����ǣ�����ʾ
if (!LogicalValue('text1','number','-')) alert('Error: Your must input a number');
example 7:Ҫ����������text1����������Ƿ��������ͣ����ǣ�����ʾ
if (!LogicalValue('text1','date')) alert('Error: Your must input a logical date value');
����ķָ��ΪA����A����һ������糣�õ�'-'��'/'�����������﷨
if (!LogicalValue('text1','date',A)) alert('Error: Your must input a logical date value');
�򵱷ָ��Ϊ'/'ʱ
if (!LogicalValue('text1','date','/')) alert('Error: Your must input a logical date value');
���ָ��Ϊ'-'ʱ���ɲ�Ҫ����'-'���ɴ���
example 8:Ҫ����������text1�������ʾ��ɫ���ַ��Ƿ���?����?����ʾ
if (!LogicalValue('text1','string','0123456789ABCDEFabcdef')) alert('Error: Your must input a logical color value');
example 9:Ҫ����������text1�������ʾ������ַ��Ƿ񲻺���'"@#$%&^*����Щ�ַ����У�����ʾ
if (!LogicalValue('text1','string','\'"@#$%&^*',false)) alert('Error: Your password can not contain \'"@#$%&^*');
����false��ʾ������ĳЩ�ַ�true��ʾ��������Щ�ַ�ȱʡֵΪtrue
*/

function IsInteger(string ,sign){
    var integer;
    if ((sign!=null) && (sign!='-') && (sign!='+')){
        alert('IsInter(string,sign)�Ĳ����?\nsignΪnull��"-"��"+"');
        return false;
    }
    integer = parseInt(string);
    if (isNaN(integer)){
        return false;
    }else if (integer.toString().length==string.length){
        if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0)){
            return true;
        }else return false;
    }else return false;
}

/**
IsDate: �����ж�һ���ַ��Ƿ������ڸ�ʽ���ַ�

����ֵ��
true��false

����
DateString�� ��Ҫ�жϵ��ַ�
Dilimeter �� ���ڵķָ��ȱʡֵΪ'-'

Author: PPDJ
sample:
var date = '1999-1-2';
if (IsDate(date))
{
alert('You see, the default separator is "-");
}
date = '1999/1/2";
if (IsDate(date,'/'))
{
alert('The date\'s separator is "/");
}
*/


function IsDateL(DateString , Dilimeter){
    if (DateString==null) return false;
    if (Dilimeter=='' || Dilimeter==null) Dilimeter = '-';
    var tempy='';
    var tempm='';
    var tempd='';
    var tempArray;
    if (DateString.length<8 && DateString.length>10) return false;
    tempArray = DateString.split(Dilimeter);
    if (tempArray.length!=3) return false;
    if (tempArray[0].length==4){
        tempy = tempArray[0];
        tempd = tempArray[2];
    }else{
        tempy = tempArray[2];
        tempd = tempArray[1];
    }
    tempm = tempArray[1];
    var tDateString = tempy + '/'+tempm + '/'+tempd+' 8:0:0';//�Ӱ�Сʱ����Ϊ���Ǵ��ڶ�����
    var tempDate = new Date(tDateString);
    if (isNaN(tempDate)) return false;
    if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd)))
    {
        return true;
    }else{
        return false;
    }
}

/**
IsNumber: �����ж�һ���������ַ��Ƿ�Ϊ��ֵ�ͣ�
�����ж��Ƿ�����������ֵΪtrue��false
string: ��Ҫ�жϵ��ַ�
sign: ��Ҫ�ж���������ʹ�ã�������'+'����'-'���������ʾ�����ж�
Author: PPDJ
sample:
var a = '123';
if (IsNumber(a))
{
alert('a is a number');
}
if (IsNumber(a,'+'))
{
alert(a is a positive number);
}
if (IsNumber(a,'-'))
{
alert('a is a negative number');
}
*/

function IsNumber(string,sign){
    var number;
    if (string==null) return false;
    if ((sign!=null) && (sign!='-') && (sign!='+')){
        alert('IsNumber(string,sign)�Ĳ����?\nsignΪnull��"-"��"+"');
        return false;
    }
    number = new Number(string);
    if (isNaN(number)){
        return false;
    }else if ((sign==null) || (sign=='-' && number<0) || (sign=='+' && number>0))   {
        return true;
    }else return false;
}


    //ʹ�÷���
    function showOjb(theForm){

        if (checkIsNull(theForm,"wenhao_int,total_area")){
            alert( " null ok" )
        }else{
            alert(" null lost " );
        }


        if (checkIsNumber(theForm,"wenhao_int,total_area","0123456789")){
            alert( " number ok" )
        }else{
            alert(" number lost " );
        }


        if (checkIsSelected(theForm,"plan_year_e")){
            alert( " selected ok" )
        }else{
            alert(" selected lost " );
        }


        if (checkIsDate(theForm,"city_seal_date")){
            alert( " date ok" )
        }else{
            alert(" date lost " );
        }

    }


    /**
     * ���ϣ�������еĶ����Ƿ�Ϊ��
     * theForm:��ǰ�ƣ���
     * �ϣ��̣���Ҫ���Ķ���ģ������б?
     */
    function checkIsNull( theForm,objList) {
        var coll = theForm.elements;
        var s ="";
        var checkLoop = 0 ;
        if (coll!=null) {
            for (checkLoop=0; checkLoop<coll.length;checkLoop++){
                if (objList.indexOf(coll.item(checkLoop).name) > -1  ) {
                    var obj = coll.item(checkLoop);
                    if (obj.value == "" ) {
                        alert( "��û������" + obj.text  );
                        obj.focus();
                        return (false);
                    }
                }
            }
        }
        return (true);
    }

    /**
     * ���ϣ�������еĶ�����ѡ����һ��ֵ
     * theForm:��ǰ�ƣ���
     * �ϣ��̣���Ҫ���Ķ���ģ������б?
     */

    function checkIsSelected( theForm,objList) {
        var coll = theForm.elements;
        var s ="";
        var checkLoop = 0 ;
        if (coll!=null) {
            for (checkLoop=0;checkLoop <coll.length;checkLoop++){
                if (objList.indexOf(coll.item(checkLoop).name) > -1  ) {
                    var obj = coll.item(checkLoop);
                    if (obj.selectedIndex == 0 ) {
                        alert("��ѡ��"  + obj.text );
                        obj.focus();
                        return (false);
                    }
                }
            }
        }
        return (true);
    }


    /**
     * ���ϣ�������еĶ�����Ϊ��Ч����
     * theForm:��ǰ�ƣ���
     * �ϣ��̣���Ҫ���Ķ���ģ������б?
     */

    function checkIsDate( theForm,objList) {
        var coll = theForm.elements;
        var s ="";
        var checkLoop = 0 ;

        if (coll!=null) {
            for (checkLoop=0; checkLoop<coll.length;checkLoop++){
                if (objList.indexOf(coll.item(checkLoop).name) > -1  ) {
                    var obj = coll.item(checkLoop);
                    if ( IsDate(obj.value)  == false ) {
                        alert(  obj.text+"��������");
                        obj.focus();
                        return (false);
                    }
                }
            }
        }
        return (true);
    }

/**
 * �洢Cookie
 * @param name��cookie��ʶ�ֶ�name
 * @param value��name��Ӧ��value
 * @param expiresDate��cookie����ʱ��
 * @param path��cookie����·��
 * @param domain��cookie������ 
**/
function saveCookie(name, value, path, domain) {
  document.cookie = encodeURI( name+"="+value
  				   +"; path="+path
  				   +"; domain="+domain )
}

/**
 *��ȡCookie
 *@param name��cookie�ı�ʶ�ֶ�name
 *
 *return value
**/
function loadCookieValueByName( name ) {
  var cookieString = decodeURI(document.cookie);
  var cookieArray  = cookieString.split("; ");
  var param;
  for (var count = 0; count < cookieArray.length; ++count) {
    param = cookieArray[count];
    if (param.substring(0, param.indexOf("=")) == name) {
      param = param.substring(param.indexOf("=") + 1, param.length);
      break;
    }
  }
  return param;
}

/**
 *������Ʒ��Ϣ��cookie
 *@param goodsID
 *@param goodsName
 *@param price
 *@param unit
**/
function saveGoods( goodsID ) {
  var path  = location.pathname;
  var value = 1;
  var name  = "GoodsID"+goodsID;
  document.cookie = encodeURI( name+"="+value
  				   +"; path="+path);
}

/**
 *������Ʒ��Ϣ��cookie
 *@param goodsID
 *@param goodsName
 *@param price
 *@param unit
**/
function saveGoodsValueAdd( goodsID,words ) {
  var cookieString = decodeURI(document.cookie);
  var cookieArray  = cookieString.split("; ");
  if ( cookieString.length > 0 ) {
    for (var count=0; count < cookieArray.length; ++count) {
      param = cookieArray[count];
      if ( param.indexOf("GoodsID") > -1 ) {
        if (param.indexOf(goodsID) != -1)
          alert(words);
        else
          param = param+goodsID+"&";
        break;
      }
      if (count == cookieArray.length-1) {
        param = "GoodsID=&"+goodsID+"&";
      }
    }
  }
  var path = location.pathname;
  document.cookie = encodeURI( param )+"; path=/";
  //var value = 1;
  //if ( cookieString.length > 0 ) {
  //  for (var count = 0; count < cookieArray.length; ++count) {
  //    param = cookieArray[count];
  //    var param;
  //    if ( param.indexOf(goodsID) > 1 ) {
  //      param = param.substring( param.indexOf("=") + 1 , param.length );
  //      value = parseInt(param) + 1;
  //      break;
  //    }
  // }
  //}
  //var path = location.pathname;
  //path = path.substring(0,path.lastIndexOf("/")+1);
}

/**
 *��ȡcookie
**/
function loadGoodsFormCookie() {
  var cookieString = decodeURI(document.cookie);
  alert(cookieString);
}

/**
 *��cookie��ɾ���ѡ����Ʒ
 *@param goodsID
**/
function deleteGoodsFromCookie( goodsId ) {  
  var cookieString = decodeURI(document.cookie);
  var cookieArray  = cookieString.split("; ");
  if ( cookieString.length > 0 ) {
    for (var count = 0; count < cookieArray.length; ++count) {
      param = cookieArray[count];
      if ( param.indexOf("GoodsID") > -1 ) {
		tmp1 = param.substring(0,param.indexOf(goodsId));
		tmp2 = param.substring(param.indexOf(goodsId)+26,param.length);
		param = tmp1+tmp2;
  		document.cookie = encodeURI( param )+"; path=/";
      }
    }
  }
}

/*********************************************
stringCut(param,length) ��ȡ�ַ�
Input:
  param:�ַ�
  length��Ҫ��ȡ�ĳ���

Author:Ping 2007-01-10
***********************************************/
function stringLimitLength(param,length) {
  if(param.length > length) {
    param = param.substring(0, length) + "...";
  }
  return param;
}
/**
 * Сͼ��ͼ�л���ʾ
**/
function changeBigImage( theForm, obj) {
  var tmpSmall = theForm.bigImage.small;
  var tmpBig   = theForm.bigImage.src;
  theForm.bigImage.small = obj.src;
  theForm.bigImage.src   = obj.big;
  obj.src = tmpSmall;
  obj.big = tmpBig;
  return (true);
}
/**
 * ����ı����Ƿ�Ϊ��
**/
function isTestEmpty(obj, param) {
  if ( obj.value == "" ) {
    alert(param);
    obj.focus();
    return (true);
  }
  else {
    return (false);
  }
}
/**
 * ����ı��������ʽΪ����
**/
function checkValueIsNum(obj) {
  var numStr = "0123456789.-()";
  if (obj.value != "" ) {
	if ( checkStr(obj.value, numStr) == false ) {
	  alert("ֻ�����������ֶ�:'"+ numStr + "'");
      obj.focus();
      return (false);
    }
  }
}
/**
 * ���Email��ʽ��ע��js�汾Ҫ��5.5����
**/
function checkEmailFormat(email,warnWord) {
  var re = new RegExp("^([a-z0-9A-Z]+[_|-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$","ig");
  if ( !re.test(email) ) {
    alert(warnWord);
    registerForm.loginId.focus();
    return false;
  }
  else {
    return true;
  }
}

function returnIsEmail(email,warnWord) {
  var re = new RegExp("^([a-z0-9A-Z]+[_|-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$","ig");
  if ( !re.test(email) ) {
    alert(warnWord);
    return false;
  }
  else {
    return true;
  }
}
/**
 * ������֤�����ʽ
**/
function checkCrediCardNum(cardNum, brithDate) {
  var brithDateArray = brithDate.split("-");
  var brithDateCode = "";
  if ( brithDateArray[1]<13 && brithDateArray[2]<31 ) {
    brithDateCode = brithDateArray[0]+brithDateArray[1]+brithDateArray[2];
  }
  else {
    alert('Birthday format wrong!');
    registerForm.birthday.focus();
    return (false);
  }
  if ( cardNum.length==15 || cardNum.length==18 ) {
    var datePosition = cardNum.indexOf(brithDateCode);
    if (datePosition==6) {
      return (true);
    } else {
      alert('Credicard number wrong!');
      registerForm.idCardNo.focus();
      return (false);
    }
  }
  else{
    alert('Credicard format wrong!');
    registerForm.idCardNo.focus();
    return (false);
  }
}
function addTown() {
  document.all.town.options[document.all.town.options.length] = new Option("石岐区","石岐区",false);
  document.all.town.options[document.all.town.options.length] = new Option("西区","西区",false);
  document.all.town.options[document.all.town.options.length] = new Option("南区","南区",false);
  document.all.town.options[document.all.town.options.length] = new Option("东区","东区",false);
  document.all.town.options[document.all.town.options.length] = new Option("火炬开发区","火炬开发区",false);
  document.all.town.options[document.all.town.options.length] = new Option("小榄镇","小榄镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("黄圃镇","黄圃镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("民众镇","民众镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("东凤镇","东凤镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("东升镇","东升镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("古镇","古镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("沙溪镇","沙溪镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("坦洲镇","坦洲镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("三角镇","三角镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("横栏镇","横栏镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("南头镇","南头镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("阜沙镇","阜沙镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("南朗镇","南朗镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("三乡镇","三乡镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("板芙镇","板芙镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("大涌镇","大涌镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("神湾镇","神湾镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("港口镇","港口镇",false);
  document.all.town.options[document.all.town.options.length] = new Option("五桂山镇","五桂山镇",false);
}
