//check size of image
function doImageSize(oFile, oImage) {
	var InItem    = document.all(oFile);
	var ImageItem = document.all(oImage);
	if (ImageItem.width > 575) {
		oFile.value = '';
		alert("Anh co chieu rong phai nho hon 575 px");
	}
	else if (ValidImage(oFile)) {
		ImageItem.src = InItem.value; 
	}
}
//show image
function ViewImage(oFile, oImage) {
	var ImageItem = document.all(oImage);
	InItem = document.all(oFile);
	if (ValidImage(oFile)) {
		ImageItem.src = InItem.value;              
	}
	
}
//check valid iame
function ValidImage(oFile) {
	var file = document.all(oFile).value;
	if (file == '') {
		showAlert("Hay chon file anh de upload.");
		return false;
	}

	var dir = file.substring(0,file.lastIndexOf('\\')+1);
	var url = file.substring(dir.length, file.length+1);

	if(!validFileName(url)){
		showAlert("Ten file anh khong hop le. Xin kiem tra lai!");
		return false;
	}

	var ext = url.substring(url.lastIndexOf(".") + 1, url.length);
		ext = ext.toLowerCase();

	if(!validFileFormat(ext)){
		showAlert("Dinh dang anh khong hop le. Xin kiem tra lai!");
		return false;
	}
	return true;
}
//check fike name
function validFileName(url) {
	if ( url.indexOf(' ') > -1) {
		return false;
	}

	if ( url.indexOf('%') > -1) {
		return false;
	}

	if ( url.indexOf(';') > -1){
		return false;
	}

	if ( url.indexOf('&') > -1){
		return false;
	}

	if ( url.indexOf('"') > -1){
		return false;
	}
	return true;
}
//check file format
function validFileFormat(ext) {
	var txt="bmp jpg gif jpeg";
	
	if ( txt.indexOf(ext) > -1) {
		return true;
	}
	
	return false;
}
// display a alert
function showAlert(strMessage){
	var strHeader = "Dinh Quoc Glass\n";
	var	msg = strMessage + "\n";
	alert(msg);
}
