//	when passed a file name it checks for PDF file types

function checkPDFFileExtensions(fileObj){
	var ext = getFileExtension(fileObj.value);

	if (ext.toUpperCase() != 'PDF' && ext != '')
	{
		alert("Please select only pdf file for upload.");
		fileObj.focus();
		return false;
	}

	return true;
}

//	when passed a file name it checks for compatible file types that are allowed

function checkImageFileExtensions(fileObj){
	var ext = getFileExtension(fileObj.value);

	if (ext.toUpperCase() == 'GIF')
	{
		if (confirm("JPEG/JPG image is recommended for uploading.\nDo you want to continue uploading a gif image?"))
		{
			return true;
		}
		else
		{
			fileObj.focus();
			return false;
		}
	}

	if (ext.toUpperCase() != 'JPG' && ext != '')
	{
		alert("Please select only jpeg or gif image for upload.");
		fileObj.focus();
		return false;
	}

	return true;
}

function getFileExtension(filePath) { //v1.0
  fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\')+1,filePath.length));
  return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
}
 
function OpenNewWindow(imageurl){
var Imagepage = imageurl;var windowheight = 480;var windowwidth = 640;
var windowleft = (screen.width - parseInt(windowwidth)) / 2;
var windowtop = (screen.height - parseInt(windowheight)) / 2;
var windowname = "PopupWindow";
windowproperties = 'resizable=no,status=no,toolbar=no,height='+windowheight+',width='+windowwidth+',top='+windowtop+',left='+windowleft+',scrollbars=yes'
setwindow = window.open(Imagepage, windowname, windowproperties)
	if (CheckNavigatorVersion()==true){
			setwindow.window.focus();}
}  

function popup(url , windowname, width , height){

var top = 100;
var left = 100;
var windowleft = (screen.width - parseInt(width)) / 2;
var windowtop = (screen.height - parseInt(height)) / 2;
var windowname = "PopupWindow";
windowproperties = 'resizable=no,status=no,toolbar=no,height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes'

setwindow = window.open(url, windowname, windowproperties)
	if (CheckNavigatorVersion()==true){
			setwindow.window.focus();}
}  

function CheckNavigatorVersion()
{
	if (parseInt(navigator.appVersion) >= 4)
		{
			return true;
		}
    	return false;

}

function MustEnter(obj, field)
{
	//if (  isObject(obj)  )
	{
		if (obj.value == "") 
		{
			alert("Please enter " + field);
			obj.focus();
			obj.select();
			return false;
		}
	}
	return true;
}

function MustEnterInt(obj, field)
{
//	if (  isObject(obj)  )
	{
		if ( MustEnter(obj, field) )
		{
			if (isNaN(obj.value) )
			{
				alert("Please enter a valid integer for " + field);
				obj.focus();
				obj.select();
				return false;
			}
		}	
		return true;
	}
	
	return false;
}

function validateEmail(field, fieldName){
	var str
	str = field.value;
		
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(^\s)/;
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	  
	if (!reg1.test(str) && reg2.test(str)) { 
     return true;
	}

	return false;
}

