
function showHiddenRow(obj){


 var aa=document.getElementsByName("hiddentr");
 

 for (var i = 0; i < aa.length; i ++){
	a=aa[i];
	if(a.style.visibility=="visible")
	{
		a.style.visibility="hidden";
        a.style.display="none";
        obj.className="button";
    
	}
	else
	{
		a.style.visibility="visible";
        a.style.display="inline";
        obj.className="button1";
	}
}
}



function getUnicodeLength(str){
   
	  if(str==null) return 0;
      /**
	   Commont, the feature is support by setting from varchar to nvarchar, it supported in Sql Server
	  var cArr = str.match(/[^\x00-\xff]/ig);
     return str.length + (cArr == null ? 0 : cArr.length);
      **/
    return str.length;
}


function isPositiveInt(inputVal)
{
   inputStr = inputVal.toString()
   if(inputStr=="0") return false;

   for (var i = 0; i < inputStr.length; i++) {
           var oneChar = inputStr.charAt(i)
           if (oneChar < "0" || oneChar > "9")
                   return false
   }
   return true
}


function isValid(aStr){
  var aRes=true;
  if(aStr==null || aStr=="" ) aRes=false;

  return aRes;

}

function isNumber(aValue){
   return isValid(aValue)  && !isNaN(aValue);

}

function checkInput(aFormObject){

    var checkFlag=true;
    var len=aFormObject.length;
    var alertMsg="";
    var firstField=null;
  
    for(var i=0;i<len;i++){
      var objItem=aFormObject.elements[i];
   
      if(objItem.disabled==true) continue;
      if(objItem.getAttribute("novalidate") !=null )  continue;
      res=checkField(objItem);           
      if(isValid(res)) {
         checkFlag=false;  
         alertMsg+=res+"\r\n";
         if(firstField==null) firstField=objItem;
      }

   }

    if(!checkFlag)  {
       alert(alertMsg);
	   try{
         firstField.focus();
	   }catch(e){}


    }



    return checkFlag;
 }
 
 
function checkFields(needCheckField, startIndex){                 
     var list = document.getElementsByName(needCheckField[0]);
      if (list != null && list.length>1 )
       		     
      for (var i = startIndex; i < list.length; i ++){		       
	       for(m=0;m<needCheckField.length;m++) {
	            fieldObj=document.getElementsByName(needCheckField[m])[i];
	            resultMsg= checkField(fieldObj);	             
	            if(resultMsg!="" )  { 
	               alert(resultMsg);
	               fieldObj.focus();
	           
	              return false; ; 
	             }		       
	       }	  
     }
   return true;
}
  
function checkField(objItem){
	 var resultMsg="";
	
	 if(objItem.getAttribute("notnull")!=null){	
		 if( !isValid(objItem.value)) {
			   resultMsg=objItem.getAttribute("caption")+ NOT_NULL_KEY ;		  
		 }
	  }


	 if(objItem.getAttribute("isnumber")!=null){
		 if( isValid(objItem.value) &&   !isNumber(objItem.value)) {
		    resultMsg=objItem.getAttribute("caption")+ SHOULD_BE_NUMBER ;		  
		}
	 }
	 
	 if(objItem.getAttribute("minvalue")!=null){
		if( isValid(objItem.value) && getFloat(objItem.value) < getFloat(objItem.getAttribute("minvalue"))  ) {
		     
			 resultMsg=objItem.getAttribute("caption")+ MIN_VALUE +objItem.getAttribute("minvalue") ;
			
		}
	 }
	 	 
	 if(objItem.getAttribute("maxvalue")!=null){
		 if( isValid(objItem.value) &&  getFloat(objItem.value) > getFloat(objItem.getAttribute("maxvalue")) ) {
		    resultMsg=objItem.getAttribute("caption")+ MIN_VALUE +objItem.getAttribute("maxvalue") ;		  
		}
	 }

     if(objItem.getAttribute("ispositiveint")!=null){
		 if( isValid(objItem.value) &&   !isPositiveInt(objItem.value)) {
		      resultMsg=objItem.getAttribute("caption")+SHOULD_BE_POSITIVE_INTEGER;
		}
	 }
	 
	


     if(objItem.getAttribute("minlength")!=null){
		 if( getUnicodeLength( objItem.value  )  <  parseInt(objItem.getAttribute("minlength"))) {
		     resultMsg=objItem.getAttribute("caption")+LENGH_SHOULD_BE_LESS_THAN +objItem.getAttribute("minlength") ;		
		}
	   }



     if(objItem.getAttribute("maxlength")!=null){
		 if( getUnicodeLength( objItem.value  ) > parseInt(objItem.getAttribute("maxlength"))  ) {
		    resultMsg=objItem.getAttribute("caption")+LENGH_SHOULD_BE_MORE_THAN+objItem.getAttribute("maxlength") ;		
		}
	  }

     //mask
     if(objItem.getAttribute("mask")!=null){
		 if( false ) {  //checkMask(objItem.value)
		     resultMsg=objItem.getAttribute("caption")+FORMAT_SHOULD_BE+objItem.getAttribute("mask") ;		
		}
	 }

     //regexp
     if(objItem.getAttribute("regexp")!=null){
		if(!checkRegexp(objItem.value,objItem.getAttribute("regexp"))  ) {
		    resultMsg=objItem.getAttribute("caption")+FORMAT_SHOULD_BE+objItem.getAttribute("regexp") ;		
		}
	 }

   
	 
	 //isDate
     if(objItem.getAttribute("isdate")!=null){
		if(isValid(objItem.value) &&   ! isDate(objItem.value)  ) {
		    resultMsg=objItem.getAttribute("caption")+SHOULD_BE_DATE;
		}
	 }
	 

     //isEmail
     if(objItem.getAttribute("isemail")!=null){
	 	if(isValid(objItem.value) &&   ! isEmail(objItem.value) ) {
		   resultMsg=objItem.getAttribute("caption")+SHOULD_BE_EMAIL; 
		}
	 }

     //isURL
     if(objItem.getAttribute("isurl")!=null){
		 if(isValid(objItem.value) &&   !isURL(objItem.value) ) {
		     resultMsg=objItem.getAttribute("caption")+SHOULD_BE_URL;		 
		}
	 }


     //isPhone
     if(objItem.getAttribute("isphone")!=null){
		 if(isValid(objItem.value) &&  ! isPhone(objItem.value) ) {
		    resultMsg=objItem.getAttribute("caption")+SHOULD_BE_PHONE_NUMBER;
	
		}
	  }
	  
     //isWordChar
     if(objItem.getAttribute("iswordchar")!=null){
		 if( isValid(objItem.value) &&   !isWordChar(objItem.value) ) {
		    resultMsg=objItem.getAttribute("caption")+SHOULD_BE_VALID_CHARACTER;
		}
	  }
	  	  
     return resultMsg;

}


function resetForm(formName){
  var elements = document.forms[formName].elements;
  if (elements != null) {
    for (i = 0;i < elements.length; i ++) {
      if (elements[i].getAttribute("resetdisable") != null) continue;    
      if (elements[i].tagName == 'SELECT') {
          elements[i].value = "";
      }
      
      if (elements[i].tagName == 'TEXTAREA') {
          elements[i].innerText = "";
      }
      
      if (elements[i].tagName == 'INPUT') {
          if (elements[i].type == 'text' || elements[i].type == 'password' || elements[i].type == 'hidden')
            elements[i].value = "";
          if (elements[i].type == 'checkbox' || elements[i].type == 'radio')
            elements[i].checked = false;
      }
    
    }
  }
}

function isEmail(str){
   var pattern=/[a-zA-Z0-9_.]{1,}@[a-zA-Z0-9_]{1,}.[a-zA-Z0-9_]{1,}/;
   return checkRegexp(str,pattern);
}


function isWordChar(str){
   var pattern=/^[a-zA-Z0-9_]*$/;
   return checkRegexp(str,pattern);
}



function isPassword(str){
   var pattern=/^(\w){6,20}$/;
   return checkRegexp(str,pattern);
}


function isPhone(str){
   var pattern=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
   return checkRegexp(str,pattern);
}

function isPostalCode(str){
	var pattern=/^[a-zA-Z0-9 ]{3,12}$/;
  	return checkRegexp(str,pattern);
}

function isDate(value) {
	if(value.length>10) return true;

	if (!checkRegexp(value, /^\d{4}-\d{2}-\d{2}$/)) return false;
	var ds = value.split("/");
    var date = new Date(ds[0], ds[1] ,ds[2]);
    if(!date){
		return false;
	}else{
     return true;
    }
    

 	//return (date.getFullYear() == ds[2] && date.getMonth() == ds[1] && date.getDate() == ds[0]);

	//return checkRegexp(value,/^(0|[1-9]\d{0,2}|[0-1]\d{3}|20\d{2}|20[0-4]\d|2050)-(\d|0\d|1[0-2])-(\d|[0-2]\d|3[0-1])$/);
}



function checkRegexp(strValue,strPattern){
// var pattern = /^-?d $/;
	if(strValue.match(strPattern)==null){
		return false;
	}else{
		return true;
	}
}












function isFilterNumber(value) {
	return isFilter(value, "isNumber");
}

function isFilterPositiveInt(value) {
	return isFilter(value, "isPositiveInt");
}

function isFilterDate(value) {
	return isFilter(value, "isDate");
}

function isFilter(value, type) {
	var vs = value.split(",");
	for (i = 0; i < vs.length; i ++) {
		if (vs[i].toUpperCase() == "NULL") {
			continue;
		} else if ((j = vs[i].indexOf("..")) != -1) {
			min = vs[i].substring(0, j);
			max = vs[i].substring(j + 2);
			if (type == "isNumber") {
				if (!isNumber(min) || !isNumber(max))
					return false;
			} else if (type == "isPositiveInt") {
				if (!isPositiveInt(min) || !isPositiveInt(max))
					return false;
			} else if (type == "isDate") {
				if (!isDate(min) || !isDate(max))
					return false;
			}
		} else {
			if (type == "isNumber") {
				if (!isNumber(vs[i]))
					return false;
			} else if (type == "isPositiveInt") {
				if (!isPositiveInt(vs[i]))
					return false;
			} else if (type == "isDate") {
				if (!isDate(vs[i]))
					return false;
			} 
		}
	}
	return true;
}

