
//Function for image popup
function showImage(imgname) {
	window.open('enlarge.html?imgname='+imgname,'','scrollbars=no,resizable=yes,width=500,height=500,centre=0,middle=00');
}


//This function stops non decimal values to be entered in Text box
function AllowDecimal(e, sText) { 
	var key;
	var keychar;
	var Char;
	var i;
	var ValidChars;
	var ValidChars1;
	ValidChars  = ".";
	ValidChars1  = "-";
	l=sText;
	
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
		if ((key==null) || (key==0) || (key==8) ||(key==9) || (key==13)  || (key==48) || (key==49) || (key==50) ||(key==51) || (key==52) || (key==53) || (key==54) || (key==55) ||(key==56) || (key==57)  || (key==2) || (key==46) || (key==45)) {
		if(keychar == ".") {
			for (i = 0; i < l.length; i++) { 
				Char = l.charAt(i);
				if (ValidChars.indexOf(Char) != -1) 
					return false;
			}
		}
		if(keychar == "-") {
			return false;
		}
		return true;
	}
	else if (key==22)
		return false;
	else
		return false;
}           

//This function stops wildcards to be entered in Text box
function disallowWildCard(e, sText)	{ 
	var key, keychar, Char, i;
	l = sText;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	if(keychar == "%")
		return false;
	else
		return true;
}

//This function stops non numeric values to be entered in Text box
function AllowNumeric(e, sText)	{ 
	var key, keychar, Char, i, ValidChars;
	ValidChars = "-";
	l = sText;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) ||(key==9) || (key==13) || (key==27) || (key==48) || (key==49) || (key==50) ||(key==51) || (key==52) || (key==53) || (key==54) || (key==55) ||(key==56) || (key==57) || (key==45)  ) {
		if(keychar == "-") {
			return false;
		}
		return true;
	}
	else
		return false;
}


//This function email format to be entered in Text box
function isemail(obj) {
	var str = obj.value;
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   obj.focus();
	   return false;
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   obj.focus();
	   return false;
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID");
		obj.focus();
		return false;
	 }	
	 return true;					
}


//Trim Function
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


function checkNumeric(fld, minlen, chkAllSame) { 
	if(isNaN(fld.value)) {
		alert("Please fill numeric value to continue.");
		fld.focus();
		return false;
	}
	if(fld.value.trim().length < minlen)
	{
		alert('Field Value has to be atleast ' + minlen + ' digits');
		fld.focus();
		return false;
	}
	
	if(chkAllSame == 1) {
		Arr = fld.value.trim().split("");
		fine = 0;
		for(i=0; i<Arr.length; i++) {
			if(Arr[0] != Arr[i]) {
				fine = 1;
			}
		}
		if(fine == 0) {
			alert('Invalid ' + fld.name + '!');
			fld.focus();
			return false;
		}
	}
	return true;
}


//Validate Form for blank values
function verifyForm(ptr, fldList) {
	fldListArr = fldList.split(",");
	for(i=0; i<fldListArr.length; i++)
	{
		fldArr = fldListArr[i].split("|");
		pointer = eval("ptr." + fldArr[0]);
		
		if(pointer.type == "checkbox") {
			if(!pointer.checked) {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else if(pointer.type == "radio") {
			if(!pointer.checked) {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else if(pointer.type == "text") {
			if(pointer.value.trim() == "") {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
			if(pointer.value.trim().length < 2) {
				alert("Please fill correct '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
		else if(pointer.type == "textarea") {
			if(pointer.value.trim() == "") {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
			if(pointer.value.trim().length < 2) {
				alert("Please fill correct '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
			if(pointer.value.trim().length > fldArr[2]) {
				alert("Please fill correct '" + fldArr[1] + "' to continue. Maximum Length for this field is " + fldArr[2] + ".");
				pointer.value.trim().substr(0, fldArr[2]);
				pointer.focus();
				return false;
			}
		}
		else {
			if(pointer.value.trim() == "") {
				alert("Please fill '" + fldArr[1] + "' to continue.");
				pointer.focus();
				return false;
			}
		}
	}
	return true;
}
