/**********************************************************************************************
	              function.js Created by Subhasish Nag 6th February 2005
**********************************************************************************************/
function setCheckBox(theForm,theStatus) {
	var sus=eval("window.document."+theForm+".elements.length");
	for(j=0;j<sus;j++) {
		if(eval("window.document."+theForm+".elements["+j+"].type")=="checkbox") {
			eval("window.document."+theForm+".elements["+j+"].checked="+theStatus);
		}
	}
}
function getDeleteConfirm(theURL,theValue,theMsg) {
	var str="Are you sure you want to delete this "+theMsg+" : "+theValue+" ?    ";
	choice=confirm(str);
	if(choice) {
		window.location.href=theURL;
	} else {
		return false;
	}
}
function isEmpty(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
}
function IsNumeric(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	if(isNaN(str)==true || parseInt(str) <= 0) {
		alert(""+theMess+" should not be alpha numeric and always greater than Zero    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function isEmail(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".value");
	if(str=="") {
		alert(""+theMess+" should not be empty !!! Please provide a valid email address    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	if(re.test(str)==false) {
		alert("That is not a valid Email address. Please enter again.    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function isSpecialChar(theForm,theElement,theMsg) {
	var iChars = "!@#$%^&*~`()+=-[]\\\';,/{}|\":<>?";
	for(var i=0;i<eval("window.document."+theForm+"."+theElement+".value.length");i++) {
		if(iChars.indexOf(eval("window.document."+theForm+"."+theElement+".value.charAt("+i+")"))!=-1) {
			alert(theMsg);
			eval("window.document."+theForm+"."+theElement+".focus()");
			eval("window.document."+theForm+"."+theElement+".select()");
			return false;
		}
	}
}
function setCombo(theForm,theElement,theMess) {
	var str=eval("window.document."+theForm+"."+theElement+".selectedIndex");
	if(str==0) {
		alert("Please select a value for "+theMess+"    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false
	}
}
function ChangePassword(theForm,theArrayElement) {
	for(i=0;i<theArrayElement.length;i++) {
		if(eval("window.document." + theForm + "." + theArrayElement[i] + ".value")=="") {
			alert("Please fill up all password fields    ");
			return false;
		}
	}
	nPwd = eval("window.document." + theForm + "." + theArrayElement[1] + ".value");
	cPwd = eval("window.document." + theForm + "." + theArrayElement[2] + ".value");
	if(nPwd!=cPwd) {
		alert("New Password and Confirm Password should be same    ");
		eval("window.document." + theForm + "." + theArrayElement[2] + ".focus()");
		eval("window.document." + theForm + "." + theArrayElement[2] + ".select()");
		return false;
	}
}
function CheckPassword(theForm,theElement,theMsg) {
	var CapsArray = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	var SmallArray = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
	var NumArray = new Array("0","1","2","3","4","5","6","7","8","9");
	var char;
	var cap_i = 0;
	var sma_i = 0;
	var num_i = 0;
	
	var str = eval("window.document."+theForm+"."+theElement+".value");
	
	if(str == "") {
		alert(theMsg + " should not be empty    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	
	strlen = str.length;
	
	for(var i=0;i<strlen;i++) {
		char = str.charAt(i);
		// Checking for Capital Letter
		for(j=0;j<CapsArray.length;j++) {
			if(char == CapsArray[j]) {
				cap_i++;
			}
		}
		// Checking for Small Letter
		for(j=0;j<SmallArray.length;j++) {
			if(char == SmallArray[j]) {
				sma_i++;
			}
		}
		// Checking for Number
		for(j=0;j<NumArray.length;j++) {
			if(char == NumArray[j]) {
				num_i++;
			}
		}
	}
	if(cap_i < 1 || sma_i < 6 || num_i < 2) {
		alert(theMsg + " must contain at least 1 upper case character, 6 lower case characters and 2 numeric values    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function CheckFileField(theForm,theElement,theValue) {
	var fileVal=eval("window.document."+theForm+"."+theElement+".value");
	if(fileVal=="")	{
		alert("Please provide a "+theValue+" Image    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		return false;
	}
	var ext=fileVal.substr(fileVal.lastIndexOf(".")).toLowerCase();
	if(ext!=".gif" && ext!=".jpeg" && ext!=".tif" && ext!=".jpg") {
		alert("Image file should be .gif or .tif or .jpeg format    ");
		eval("window.document."+theForm+"."+theElement+".focus()");
		eval("window.document."+theForm+"."+theElement+".select()");
		return false;
	}
}
function LoadPopup(getFileName,getWindowName,getHeight,getWidth) {
	var _file = getFileName;
	var _window = getWindowName;
	var _toolbar = 0;
	var _menubar = 0;
	var _status = 1;
	var _resizable = 0;
	var _width = getWidth;
	var _height = getHeight;
	var _top = (screen.height - _height) / 2;
	var _left = (screen.width - _width) / 2;
	var _scrollbars = 1;
	
	var _condition = "toolbar=" + _toolbar + ",menubar=" + _menubar + ",status=" + _status + ",resizable=" + _resizable;
	_condition+=",width=" + _width + ",height=" + _height + ",left=" + _left + ",top=" + _top + ",scrollbars=" + _scrollbars + "";
	
	window.open(_file,_window,_condition);
}
function modelessDialogShow(url,width,height) {
	window.showModelessDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;");
}
function modalDialogShow(url,width,height) {
	window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1");
}