var userAgent = navigator.userAgent;

var opera = (userAgent.indexOf('Opera') != -1);

var ie = (userAgent.indexOf('MSIE') != -1);

var gecko = (userAgent.indexOf('Gecko') != -1);

var oldnetscape = (userAgent.indexOf('Mozilla') != -1);
/*-------------------------------------------------------------------------------------
Date: 17/08/2006
Author: ThangVQ
File: checkImage.js
Purpose: check all images in the form
Change: first create
-------------------------------------------------------------------------------------*/
function checkdimension(image,min_value){
	if (gecko||opera){
		return true;	
	}else if (ie){
		if (image.height < min_value && image.width < min_value){
			return false;
		}else{
			return true;
		}	
	}
}
/*-------------------------------------------------------------------------------------
Date: 17/08/2006
Author: ThangVQ
Function: checksize()
Input: Image image, int max_size.
Output: string: normal, big or too_big.
Note: this function is only supported in IE4+.
	An image is "big" if its size is larger 2/3 of max_size.
-------------------------------------------------------------------------------------*/
function checksize(image,max_size){
	if (gecko||opera){
		return true;
	}else if (ie){
		if (image.fileSize < 2*max_size/3){
			return true;
		}else if (image.fileSize < max_size){
			return "big";
		}else {
			return "large";
		}
	}
}
function checkloaded(image){
	if (opera||gecko){
		return true;
	}else if (ie){
		if (image.complete == false || image.fileSize <= 0){
			return false;
		}else{
			return true;
		}
	}
}
function isNull(value){
	if (value == ""){
		return true;
	}else{
		return false;
	}
}
/*--------------------------------------------------------------------------------------------
Date: 17/08/2066
Author: ThangVQ
Function: checkImage()
Input:  arr_image contains image_name in the form
		arr_dimension contains image_dimension constraint. They're: min allowed 
	height and width
		arr_size contains max image_size. An image is big (and should have an alert
		for user) if its size > 2*image_max_size/3.
Output: arr_result contains string values: notload (if cannot be loaded), small (if loaded but 
its dimension < min_dimension), big (if loaded but its size >2/3 max_size), large (if loaded
but its size > max_size), normal (if pass all check).
Purpose: check all images in the form.
---------------------------------------------------------------------------------------------*/
function checkImage(arr_image,arr_dimension,arr_size){

	var result = new Array();
	var i = 0;
	for (i=0;i<arr_image.length;i++){
		if (isNull(arr_image[i].src)){
			result[i]="null";
		}else if (!checkloaded(arr_image[i])){
			result[i]="notload";
		}else{
			if (!checkdimension(arr_image[i],arr_dimension[i])){
				result[i]="small";
			}else {
				result[i]=checksize(arr_image[i],arr_size[i]);
			}
		}
	}
	return result;
}