// JavaScript Document

/*
Creation Date=18-08-2005
Creation Time=9:30PM
Version 1.0
Since 1.0

Created By :
			Shahid Malook
*/
function setFocus(){
	if(this.document.forms.length != 0 ){
		var lenField = this.document.forms[0].elements.length;
		for(i=0;i<lenField;i++)
		{
			if(this.document.forms[0].elements[i].type != "hidden" && this.document.forms[0].elements[i].type != "checkbox" && this.document.forms[0].elements[i].type != "radio" && this.document.forms[0].elements[i].disabled != true)
			{
				this.document.forms[0].elements[i].focus();
				return;
			}
		}
		
	}
}
//===================================================
//		Validate Email
//===================================================
function validEmail(emailfield) {
  var field = document.getElementById(emailfield); // email field
  var str = field.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    return true;
  }
  alert("\"" + str + "\" is an invalid e-mail!"); // this is also optional
  field.focus();
  field.select();
  return false;
}

//===============================================
// Date comparison function
//=========================================================
function getDateObject(dateString,dateSeperator)
{
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cDate=dateString.substring(0,curPos);

	//extract month portion
	endPos=dateString.indexOf(sepChar,curPos+1);
	cMonth=dateString.substring(curPos+1,endPos);

	//extract year portion
	curPos=endPos;
	endPos=curPos+5;	
	cYear=curValue.substring(curPos+1,endPos);

	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate);
	return dtObject;
}
//=========================================================
//=========================================================
function modelesswin(url,WinName,mwidth,mheight){

ScreenHeight=(screen.height)/2;
ScreenWidth=(screen.width)/2;
ScreenTop=ScreenHeight-(mheight/2);
ScreenLeft=ScreenWidth-(mwidth/2);
window.open(url,WinName,"width="+mwidth+"px,left="+ScreenLeft+"px,top="+ScreenTop+"px,height="+mheight+"px,help=0,resizable=0;");
}
///////////////////////////////////////////////////////////////////////////////////////////////


function setFocus()
{
	if(this.document.forms.length != 0 )
	{
		var lenField = this.document.forms[0].elements.length;
		for(i=0;i<lenField;i++)
		{
			if(this.document.forms[0].elements[i].type != "hidden" && this.document.forms[0].elements[i].type != "checkbox" && this.document.forms[0].elements[i].type != "radio" && this.document.forms[0].elements[i].disabled != true)
			{
				this.document.forms[0].elements[i].focus();
				return;
			}
		}
		
	}
}
/*
//
/*
	This is A Generic Function To Open New Window.
	Created By 
	Shahid Malook
*/
	function openDep(url) 
	{
  		win = window.open(url, "dep", "top=300,left=220,height=170,width=175");
	}	




function checkrequired(which) {
	var cancatenate="";
	var pass=true;
	//alert(document.images.length);
	if (document.images) 
	{
		for (i=0;i<which.length;i++)
		 {
			var tempobj=which.elements[i];
			//alert(tempobj.name.length);
			if (tempobj.name.substring(0,8)=="required")
			 {
				if (((tempobj.type=="password" || tempobj.type=="text" ||tempobj.type=="textarea" || tempobj.type=="select-one")&&tempobj.value.trim()=='' && tempobj.disabled==false))
				 {
					pass=false;
					break;
			 	  }				  
		  	  }
			  if(tempobj.disabled)
				tempobj.disabled=false;
	   		}
		}
	if (!pass) {
		shortFieldName=tempobj.name.substring(11,tempobj.name.length);
		val = tempobj.value.trim();
		for(a=0;a<shortFieldName.length;a++)
		{
			if(shortFieldName.substring(a,a+1)==shortFieldName.substring(a,a+1).toUpperCase())
				cancatenate+=" ";
			cancatenate+=shortFieldName.substring(a,a+1);
		}
//		if(cancatenate.strlength)
		cancatenate=cancatenate.split('[ ]');
		//alert(cancatenate);

		alert(cancatenate[0]+" field can not be left blank.");
		tempobj.focus();
		return false;
		}
	else
	{
		for (i=0;i<which.length;i++)
		 {
			var temObj=which.elements[i];
			var lengthObj=temObj.name.length;
				
			if(temObj.name.substring(lengthObj-4)=='Date')
				temObj.disabled=false;			

		 }
	} 
	return true;

}
/////////////////////////////////////
String.prototype.trim = function() {
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
  }
/////////////////this variable use for cheking the max value of check box
var countChildCheckBox=1;
///////////////////////////////////////////////////////////////////////////////////

//=========================================================
function redir(frmaction,module,queryString)
{
	document.frmred.fname.value=frmaction;
	document.frmred.module.value=module;
	document.frmred.qString.value=queryString;	
	document.frmred.submit();	
}

//=========================================================
function comboSelect(val,comboName)
{
	document.getElementById(comboName).value=val;
}
//==============================================
 function fillData(data,frm)
 {
	for(key in data)
	{
		if(document.forms[frm].elements[key].type=="select-one")
		{
			comboSelect(data[key],key);
		}
		else
		{
			document.forms[frm].elements[key].value=data[key];
		}		
	}
	document.forms[frm].action.value="update";
 }
//====================================checking the check boxs===============
//====================================checking the check boxs===============


//==================Check Field Length===================
function checkLength(frm,field,maxLength){
	var val=document.getElementById(field).value.length;
	if (val >= maxLength){
		   return false;
		}
		return true;
	
}
//=======================================================================
function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}

//=========================================================================================<!--
function charsCheck(e, goods)
{
	if(goods=='a...z' || goods=='A...Z')
		goods='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	if(goods=='a...z,0...9')
		goods='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
	
	if(goods=='0...9')
		goods='0123456789';
	if(goods=='0...9.')
		goods='0123456789.';	
	
	var key, keychar;
		key = getkey(e);
	if (key == null) return true;
	
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;
	
	// else return false
	return false;
}
//-->
//======================================================================================



