<!-- null check -->

function isNull(input) {
    if (input.value == null || input.value == "") {
        return true;
    }else{
	    return false;
	}
}

<!-- empty check -->

function isEmpty(input) {
    if (input.value == null || input.value.replace(/ /gi,"") == "") {
        return true;
    }
    return false;
}
  
<!-- bad special character check-->

function containsChars(input,chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) != -1)
           return true;
    }
    return false;
}


<!-- special character check  --> 

function containsCharsOnly(input,chars) {
	var result = false;
	
    for (var inx = 0; inx < input.value.length; inx++) { 
       if (chars.indexOf(input.value.charAt(inx)) == -1){			
			return false;
		}
    }
    return true;
}

<!-- Alphabet check  -->

function isAlphabet(input) {
 	//var format= new RegExp(/^([A-Za-z])$/i);
 	//return isValidFormat(input,format);
 	
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return containsCharsOnly(input,chars);	
}

<!-- Alphabet UpperCase check -->

function isUpperCase(input) {
	//var format= new RegExp(/^([A-Z])$/i);
	//return isValidFormat(input,format);
	
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return containsCharsOnly(input,chars);
}
  
<!-- Alphabet LowerCase check -->
function isLowerCase(input) {
	//var format= new RegExp(/^([a-z])$/i);
	//return isValidFormat(input,format);
	var chars = "abcdefghijklmnopqrstuvwxyz";
	return containsCharsOnly(input,chars);
}
  
<!-- Number check -->
function isNumber(input) {

/*
	if(!isNaN(input.value)){
		return true;
	}else{
		return false;
	}
*/
    var chars = "0123456789";
    return containsCharsOnly(input,chars);
}
  
<!-- Alphabet or Number check -->

function isAlphaNum(input) {
    //var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    //return containsCharsOnly(input,chars);
    var format= new RegExp(/^([A-Za-z0-9]{4,8})$/i);
	return isValidFormat(input,format);
}
  
<!-- Number value '-' check -->

function isNumDash(input) {
    var chars = "-0123456789";
    return containsCharsOnly(input,chars);
}
 
<!-- Number value Comma check -->
function isNumComma(input) {
    var chars = ",0123456789";
    return containsCharsOnly(input,chars);
}
  
<!-- Valid Format check  -->

function isValidFormat(input,format) {

	if (format.test(input.value)) { 
   		return true; 
	}else{
		return false;
	}
	return false;
/*
    if (input.value.search(format) != -1) {
        return true; //right
    }else{
    	return false;
    }
    return false;
*/
}
  
<!-- Email Format check  -->

function isValidEmail(input) {
//    var format = /^(\S+)@(\S+)\.([A-Za-z]+)$/;
//    var format = /^((\w[\-\.])+)@((\w[\-\.])+)\.([A-Za-z]+)$/; 
   
	var format=new RegExp(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
	return isValidFormat(input,format);
}

<!-- Phone Formmat check-->

function isValidPhone(input) {
    var format = /^(\d+)-(\d+)-(\d+)$/;
    return isValidFormat(input,format);
}
  
<!-- Byte Length -->

function getByteLength(input) {
    var byteLength = 0;
    for (var inx = 0; inx < input.value.length; inx++) {
        var oneChar = escape(input.value.charAt(inx));
        if ( oneChar.length == 1 ) {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1) {
            byteLength += oneChar.length/3;
        }
    }
    return byteLength;
}
  
<!-- Remove Comma -->

function removeComma(input) {
    return input.value.replace(/,/gi,"");
}
  
<!-- Radio button checked check -->

function hasCheckedRadio(input) {

    if (input.length > 1) {
        for (var inx = 0; inx < input.length; inx++) {
            if (input[inx].checked) return true;
        }
    }else{
    	if(input.checked) return true;
    }
    return false;
}
  
<!-- Checkbox checked check -->

function hasCheckedBox(input) {
    return hasCheckedRadio(input);
}


<!-- window open -->

function openPopup(page, width, height, scroll){
	window.open(page, "pop",  "scrollbars="+scroll+", width="+width+", height="+height);
}

<!-- file check -->

function fileCheck(obj) {
	// format substring
	pathpoint = obj.lastIndexOf('.');
	filepoint = obj.substring(pathpoint+1,obj.length);
	filetype = filepoint.toLowerCase();
	 
	// image size check
	if(filetype=='jpg' || filetype=='gif' || filetype=='png' || filetype=='jpeg' || filetype=='bmp') {

		var wwd=200;  //width
		var hhd=100;  //height

		ImageWidth=document.F.preview.width; //width check
		ImageHeight=document.F.preview.height; //height check

		//file width over message
		if(ImageWidth > wwd){ 
			alert('file width over');
			return false;
		}

		//file height over message
		if(ImageHeight > hhd){ 
			alert('file height over');
			return false;
		}
   
	} else {
		alert('not image fail');
		F.preview.src = '';
		return false;
	}
	  
	// BMP file fail
	/*
	if(filetype=='bmp') {
		upload = confirm('BMP file fail');
		if(!upload) return false;
	}
	*/
}

	function imgFormatCheck(obj){
	pathpoint = obj.lastIndexOf('.');
	filepoint = obj.substring(pathpoint+1,obj.length);
	filetype = filepoint.toLowerCase();
	 
	// image size check
	if(filetype=='jpg' || filetype=='gif' || filetype=='png' || filetype=='jpeg' || filetype=='bmp') {
		return true;
	}else{
		return false;
	}
	
	function reSize(logo){
	
		//var imginfo = new image();
		//imginfo.src=obj;
		var width = eval("document.getElementById('"+logo+"').width");
		var height = eval("document.getElementById('"+logo+"').height");
		
		pix_width = 200;
		pix_height = 200;		
		var num = 0;
		var max_height;
		var max_width;
		
		alert(width+"/"+height);
		
		if(width > pix_width || height> pix_height){
			if(width-height<0){
				num = (height/pix_height);
				max_height = height/num;
				max_width = width/num;
			}else if(width-height>=0){
				num = (width/pix_width);
				max_width = width/num;
				max_height = height/num;
			}
		}
		eval("document.getElementById('"+logo+"').width="+max_width);
		eval("document.getElementById('"+logo+"').height="+max_height);
	}
}

function checkAll(obj){
	
	var state = 0;
	
	for(i=0; i <obj.length; i++){
		if(obj[i].checked){
			state++;
		}
	}
	if(state >0){
		for(i=0; i <obj.length; i++){
			obj[i].checked=false;
		}
	}else{
		for(i=0; i <obj.length; i++){
			obj[i].checked=true;
		}
	}
}
function ismaxlength(obj, msg1, msg2){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	
	if (obj.getAttribute && obj.value.length>mlength){
		Ext.Msg.alert(msg1, msg2, function(btn){
			if(btn=='ok')
				obj.value=obj.value.substring(0,mlength);
		});
		
	}
}