// 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 SelectCheckBox(FormName,CheckBoxParent,CheckBoxChild){
	
if(document.getElementById(CheckBoxChild)!=null)
{
		
	var Child=document.getElementById(CheckBoxChild);
	var Parent=document.getElementById(CheckBoxParent);
		//alert(Parent);
	if(Parent.checked)
	{
		
			for (counter = 0; counter < FormName.all.length; counter++)
			{
				
				var a=FormName.elements[counter];
				if(a=='[object]')
				{
				//alert(a.id)
				
					if(a.type=='checkbox' && a.id==Child.id && !a.disabled)
					{
					
						a.checked=true;
					}
				}
			}
	}
	else
		{
			for (counter = 0; counter < FormName.all.length; counter++)
			{
				var a=FormName.elements[counter];
				if(a=='[object]')
				{
					if(a.type=='checkbox' && a.id==Child.id && !a.disabled)
						a.checked=false;
				}
			}
	
	
	
	}
}
}


/*
Creation Date=24-08-2005
Creation Time=2:41PM
Purpose of this function:
			This function is use to Select all Checkboxs.
Parameter:
			This function gets one parameter in array type.
Return:
			This function dose not returns any value. It's only select or descelect checkbox

Version 1.0
Since 1.0

Created By :
			Abdul Mannan

example
SelectChildCheckBox(this.form,'CheckBoxParent','CheckBoxChild');

*/
function SelectChildCheckBox(FormName,CheckBoxParent,CheckBoxChild)
{

	//alert(FormName.elements[1].type)
	var Child=document.getElementById(CheckBoxChild);
	var Parent=document.getElementById(CheckBoxParent);
	//alert(FormName.all.length);
	var checkbox_choices = 0;
	var toltalbox=0;
	for (counter = 0; counter < FormName.all.length; counter++)
	{
	var a=FormName.elements[counter];
	if(a=='[object]')
	{
		if(a.type=='checkbox' && a.id==Child.id){
		toltalbox=toltalbox+1;
		}
	}
}

for (counter = 0; counter < FormName.all.length; counter++)
	{
	var a=FormName.elements[counter];
	if(a=='[object]')
	{
		if(a.type=='checkbox' && a.id==Child.id && a.checked){
			checkbox_choices=checkbox_choices+1;
		}
	}
}

	//alert(checkbox_choices);
	//alert(toltalbox);
	if(checkbox_choices==toltalbox) Parent.checked=true; else  Parent.checked=false;

}

//
/*
	This is A Generic Function Which Set The Focus on The First Element on the Calling Form.
	Created By 
	Muhammad Shamshad Habib
*/
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");
	}	


/*
Creation Date=14-08-2005
Purpose of this function:
			This function is use to get all requered filed in form
Parameter:
			This function get form Name.
Return:
			This function return error if its is accour

Version 1.0
Since 1.0

Created By :
			Abdul Mannan

example
checkrequired("form name")

*/

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 removeRowFromTable(which)
{
	  for(count=1;count<document.getElementById(which).rows.length;)
	  {
	  	  //alert(count);
		  var limit=document.getElementById(which).rows.length;		 
		  if(document.getElementById(which).rows[count].cells[0].childNodes[0].checked)
		  {
			  var tr = document.getElementById(which).rows[count];
			  tr.parentNode.removeChild(tr);			  
			}
			else
			count++;
		}

}
//=========================================================
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===============

function checkChkBox(frm) 
{
 
 //alert(frm.elements);
 var el = frm.elements;
 var flage=false;
 //alert(el);
 for(var i = 0 ; i < el.length ; ++i)
 {
  	if(el[i].type == "checkbox") 
  	{
		if(el[i].name!='CheckBoxParent')
		{
			flage=true;
			var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			var delController = 0;
			var itemchecked = false;			
			if(radiogroup.length == undefined)
			{
				if(el[i].checked)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{			
				for(var j = 0 ; j < radiogroup.length ; ++j)
				{
					if(radiogroup[j].checked) 
					{
						itemchecked = true;
						delController++;
						break;
					}
				}
			   if( delController == 0)
			   {
				   alert('No Child Is Selected For Deletion !');
				   return ;
			   }
			   if(!itemchecked && !flage) 
			   { 
					return false;
			   }
			}
		}
	}
 }
 return true;
} 
//==================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;
}
//-->
//======================================================================================

function addRowToTable_New1(tableName,list)
{
	 
	 countChildCheckBox=countChildCheckBox+1;
	  var tbl = document.getElementById(tableName);
	  //alert(tbl);
	  var lastRow = tbl.rows.length;
	  
	  var iteration = lastRow;
	  var row = tbl.insertRow(lastRow);
	  if(lastRow%2==0)
		  row.className='tblTextBgAlternate';
	  else
		  row.className='tblTextBg';

      ////////////it is use for chekbox in first coloumn
	  var cellChk = row.insertCell(0);
	  
	
/////////////////////convert in to string
	var objList=list.toString();
///////////////////////////split string into array//////////////////////////////like////'tablename;Type'
	var restoredArray= objList.split(",");
		a=0;
		for(count=0;count<=restoredArray.length-1;count++ )
		{			
			var restoredSubArray= restoredArray[count].split(";");
			////////////if table have linke			
			//alert(a);
			if(restoredSubArray[1]=='input')
			{
				// alert(restoredSubArray[0]);
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('input');
				  el.setAttribute('type', 'text');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  el.setAttribute('id', restoredSubArray[0]);
				  el.setAttribute('className','InputList');
				  el.setAttribute('class','InputList');
				  cellChk.appendChild(el);
			}
			if(restoredSubArray[1]=='chk')
			{
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('input');
				  el.setAttribute('type', 'checkbox');
				  //el.setAttribute('className','input');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  el.setAttribute('id', restoredSubArray[0]);
				  el.setAttribute('value', 1);
				  if(restoredSubArray[0]=='Default')
				   el.onclick =function ()
				   {
				  		selectOneCheckBox(frmlisting,el);
				   };				  
				  cellChk.appendChild(el);
			}
			if(restoredSubArray[1]=='radio')
			{
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('input');
				  el.setAttribute('type', 'radio');
				  el.setAttribute('name', restoredSubArray[0]);
				  //el.setAttribute('className','input');
				  
				 //el.type='radio';
				  //el.setAttribute('value','radiobutton');
				  //el.name=restoredSubArray[0];
				  //el.onclick=alert('aa') ;
				 
				  alert(el.type)
				  
				  cellChk.appendChild(el);
				  
				  
			}
			
			if(restoredSubArray[1]=='tArea')
			{
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('textarea');
				  //el.setAttribute('type', 'textarea');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				 // alert(el.name)
				  el.setAttribute('id', restoredSubArray[0]);				  
				  el.setAttribute('className','InputList');
				  el.setAttribute('class','InputList');
				  cellChk.appendChild(el);
			}
		}
}

//===========valitidy of radio button=================
function validate_radio(frm) 
{
 
 //alert(frm.elements);
 var el = frm.elements;
 //alert(el);
 for(var i = 0 ; i < el.length ; ++i)
 {
  	if(el[i].type == "radio") 
  	{
		var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
		var itemchecked = false;
		if(typeof radiogroup.length!='undefined')
		{
			for(var j = 0 ; j < radiogroup.length ; ++j)
			{
				if(radiogroup[j].checked) 
				{
					itemchecked = true;
					break;
				}
			}
		}
		else
		{
			if(radiogroup.checked) 
				{
					itemchecked = true;				
				}
		}
	   if(!itemchecked) 
	   { 
			alert("Please select a option.");
			if(el[i].focus)
			el[i].focus();
			return false;
	   }
		
	}
 }
 return true;
}
//=======Checking the check box validaty===========================================================
function chkBoxValidaty(frm, IDOfCheckBox)
{
var el = frm.elements;
 //alert(el);
 for(var i = 0 ; i < el.length ; ++i)
 {
  	if(el[i].type == "checkbox") 
  	{
		if(el[i].name!='status')
		{
			//alert("it is a test");
			var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			//alert(el[i].name);
			var itemchecked = false;		
			if(typeof radiogroup.length!='undefined')
			{
				for(var j = 0 ; j < radiogroup.length ; ++j)
				{
					if(radiogroup[j].checked) 
					{
						itemchecked = true;
						break;
					}
				}
			}
			else
			{
				if(radiogroup.checked) 
					{
						itemchecked = true;				
					}
			}
		   if(!itemchecked) 
		   { 
				if(el[i].focus)
				el[i].focus();
				return false;
		   }
		}
	}
 }
 return true;
} 

//====================================================
function SelectCheckBoxMRights(FormName,CheckBoxParent,CheckBoxChild)
{
	var Child=document.getElementById(CheckBoxChild);
	var Parent=document.getElementById(CheckBoxParent);
	var el = FormName.elements[CheckBoxChild];	
	if(Parent.checked)
	{
		if(typeof el.length!='undefined')
		{
			for (counter = 0; counter < el.length; counter++)
			{
				el[counter].checked=true;			
			}
		}
		else
		{
			el.checked=true;
		}
	}
	else
	{
		if(typeof el.length!='undefined')
		{
			for (counter = 0; counter < el.length; counter++)
			{
				el[counter].checked=false;			
			}
		}
		else
		{
			el.checked=false;
		}
	}
}
//==================================================
function SelectChildCheckBoxMRights(FormName,CheckBoxParent,CheckBoxChild)
{
	var Child=document.getElementById(CheckBoxChild);
	var Parent=document.getElementById(CheckBoxParent);
	var el = FormName.elements[CheckBoxChild];	
	if(typeof el!='undefined')
	{
		if(typeof el.length!='undefined')
		{
			parentChecked=0;
			for (counter = 0; counter < el.length; counter++)
			{
				if(el[counter].checked)
						parentChecked++;		
			}
			
			if(parentChecked==el.length)
				Parent.checked=true;
			else
				Parent.checked=false;
		}
		else
		{
			if(el.checked)
				Parent.checked=true;
			else
				Parent.checked=false;
		}
	}
}

function selectOneCheckBox(frm,name)
{
var el = frm.elements;
//alert(name);
 for(var i = 0 ; i < el.length ; ++i)
 {
  	if(el[i].type == "checkbox") 
  	{
		if(el[i].name!='status')
		{
			if(el[i].name=='Default[]')
			{
			//alert("it is a test");
			
			//alert(el[i].name);
			//Default[]
		var itemchecked = false;
			el[i].checked=false;		
			}
			
		}
	}
 }
 //alert(name.checked=true)
 name.checked=true
 return true;
}
function modewin(url,WinName,mwidth,mheight)
{
ScreenHeight=(screen.height)/2;
ScreenWidth=(screen.width)/2;
ScreenTop=ScreenHeight-(mheight/2);
ScreenLeft=ScreenWidth-(mwidth/2);
var WinName=window.open(url,WinName,"width="+mwidth+"px,left="+ScreenLeft+"px,top="+ScreenTop+"px,height="+mheight+"px,help=0,scrollbars=1;");
return WinName;
}
function newWin(url,WinName,mwidth,mheight)
{
ScreenHeight=(screen.height)/2;
ScreenWidth=(screen.width)/2;
ScreenTop=ScreenHeight-(mheight/2);
ScreenLeft=ScreenWidth-(mwidth/2);
var WinName=window.open(url,WinName,"width="+mwidth+"px,left="+ScreenLeft+"px,top="+ScreenTop+"px,height="+mheight+"px,help=0,scrollbars=1;");
}
function delRecord(frm)
{
	delConfirm=confirm("Are you sure, you want to delete the current record.");
	if(delConfirm)
	{
		document.getElementById(frm).action.value='delete';
		document.getElementById(frm).submit();
	}
}
function checkSpaceInPassWord(e)
	{
		var key, keychar;
		key = getkey(e);
		
		if ( key=='32' )
		{
			alert("Space Key not allowed");
			window.event.returnValue =false;
		}
		
	}
	
function checkEmailAddress(email)
{

	for (var i = 0; i < email.length; i++)
	{
		var chr = email.charAt(i);

		if (!(((chr >= 'a') && (chr <= 'z')) || ((chr >= 'A') && (chr <= 'Z')) ||
			(chr == '.') || (chr == '@') || (chr == '_') || (chr == '-') ||
			((chr >= '0') && (chr <= '9'))))
		{
			alert("Invalid Email address '" + email + "'.");
			return false;
		}
	}
	if ((email == "") || (email.indexOf('@', 0) == -1) ||
		(email.indexOf('@', 0) == 0) || (email.indexOf('.', 0) == -1) ||
		(email.indexOf('.', 0) == (email.length - 1)) ||
		(email.indexOf('@', 0) == (email.length - 2)) ||
		(email.charAt(0) == '.') || (email.charAt(email.length - 1) == '.'))
	{
		alert("Invalid Email address '" + email + "'.");
		return false;
	}
	// Added by Riz... 241201 checking for invalid emails due to '.' placement
	var temp = email.substring(email.indexOf('@', 0) + 1, email.length);

	if (temp.length > 2)
	{
		if (temp.indexOf('.', 1) == -1)
		{
			alert("Invalid Email address '" + email + "'.");
			return false;
		}
		else
		{
			if (temp.indexOf('.', 1) == temp.length - 1)
			{
				alert("Invalid Email address '" + email + "'.");
				return false;
			}
		}
	}
	else
	{
		alert("Invalid Email address '" + email + "'.");
		return false;
	}

	var charIndex = email.indexOf('@', 0);
	if (email.indexOf('@', charIndex + 1) != -1)
	{
		alert("Invalid Email address '" + email + "'.");
		return false;
	}
	else
	{
		charIndex = email.indexOf('@', 0);
		if (email.charAt(charIndex - 1) == '.')
		{
			alert("Invalid Email address '" + email + "'.");
			return false;
		}
	}
	// This case checks that 2 dots can't be consective
	var previousChar;
	var currentChar;

	for (var i = 0; i < email.length; i++)
	{
		currentChar = email.charAt(i);
		if (currentChar == '.')
		{
			if (currentChar == previousChar)
			{
				alert("Invalid Email address '" + email + "'.");
				return false;
			}
		}
		previousChar = currentChar;
	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////

function addRowToTable_New(tableName,list)
{
	 
	 countChildCheckBox=countChildCheckBox+1;
	  var tbl = document.getElementById(tableName);
	  //alert(list);
	  var listReFromProd=list.toString();
	  var listReFromProd= listReFromProd.split(";");
	 
	  var lastRow = tbl.rows.length;
	   //alert(tbl)
	  var iteration = lastRow;
	  var row = tbl.insertRow(lastRow);
	  if(lastRow%2==0)
		  row.className='tblTextBg';
	  else
		  row.className='tblTextBgAlternate';
		
	
      ////////////it is use for chekbox in first coloumn
	  var cellChk = row.insertCell(0);
	  var el = document.createElement('input');
	  el.setAttribute('type', 'checkbox');
	  el.setAttribute('name', 'CheckBoxChild1[]');
	  el.setAttribute('id', 'CheckBoxChild');
	  el.setAttribute('value','' );
	  	  //el.setAttribute('onclick', "SelectChildCheckBox(this.form,'CheckBoxParent','CheckBoxChild');");	 
	   el.onclick =function (){
		   
				SelectChildCheckBox(this.form,'CheckBoxParent','CheckBoxChild');
	   } 
	  cellChk.appendChild(el);	   

	   
/////////////////////convert in to string
	var objList=list.toString();
///////////////////////////split string into array//////////////////////////////like////'tablename;Type'
	var restoredArray= objList.split(",");
		a=0;
		for(count=0;count<=restoredArray.length-1;count++ )
		{
				
			
			var restoredSubArray= restoredArray[count].split(";");
			////////////if table have linke			
			//alert(restoredSubArray[1]);
			if(restoredSubArray[1]=='input')
			{
				//alert(restoredSubArray[1]);
				 var cellChk = row.insertCell(count+1);
				 
				 var el = document.createElement('input');
				  var maxLenthVal=restoredSubArray[2];
				  //alert(maxLenthVal);
				  el.setAttribute('type', 'text');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  el.setAttribute('id', restoredSubArray[0]);
				  el.setAttribute('className',restoredSubArray[3]);
				  el.setAttribute('class',restoredSubArray[3]);
				  el.setAttribute('maxLength',restoredSubArray[2]);
				 
				//if(restoredSubArray[0]=='eDate')	
					//el.disabled=true;
					if(maxLenthVal!='AlphaNumric')
					{
			  		el.onkeypress=function()
					 {
					   window.event;
					   return charsCheck(event,'0...9');

			      	  }
					  el.onkeyup=function()
					  {
					  	if(this.id=='requiredtxtNoDays')	
						{
							var DateArry=this.parentNode.previousSibling.childNodes[0].value.split('/');
							day=parseInt(DateArry[0])+parseInt(this.value);
							DateVal=DateArry[2]+'/'+DateArry[1]+'/'+day;
							getDateVal=new Date(DateVal)
							if(getDateVal.getDate())
								this.parentNode.nextSibling.childNodes[0].value=getDateVal.getDate()+'/'+(parseInt(getDateVal.getMonth())+1)+'/'+getDateVal.getYear();
						}
					  }}
				  cellChk.appendChild(el);
			}
			
			if(restoredSubArray[1]=='inputDate')
			{
				// alert(restoredSubArray[0]);
		///==================Create Input Box
						 
				  var cellChk = row.insertCell(count+1);
				  var NumberT=cellChk.parentNode.sectionRowIndex;
				//alert(NumberT);
				  var el = document.createElement('input');
				  var maxLenthVal=restoredSubArray[2];
				  el.setAttribute('type', 'text');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  el.setAttribute('id', restoredSubArray[0]+NumberT);
				  el.setAttribute('className',restoredSubArray[3]);
				  el.setAttribute('class',restoredSubArray[3]);
				  el.setAttribute('value',restoredSubArray[4]);
				  el.disabled=true;
				  
				  cellChk.appendChild(el);
		//=================create Image=========================================================
		//alert(restoredSubArray[0]);
				if(restoredSubArray[0]=='txtSD')
					var objName1=restoredSubArray[0]+NumberT;
				else
					var objName=restoredSubArray[0]+NumberT;
				  var el = document.createElement('img');
				  el.setAttribute('title', "View Calendar");
				  el.setAttribute('align', "absmiddle");
				  el.setAttribute('src', 'webapp//images/icon_calendar.gif');
				  el.setAttribute('border',0);
				  el.style.cursor='hand';
				  if(restoredSubArray[0]=='txtSD')
				  {
					  el.onclick =function ()
					  {
						//alert(objName1+'----name 1');
						DateId=NewCal1(objName1,'ddmmyyyy');
					  }
				  }
				  else
				  {
					  el.onclick =function ()
					  {
						//alert(objName1+'----name');
						DateId=NewCal1(objName,'ddmmyyyy');
					  }
				  }
				 cellChk.appendChild(el);
			}
			
			
			if(restoredSubArray[1]=='combo')
			{
				// alert(restoredSubArray[3]);
				var optionVal=restoredSubArray[3];
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('select');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  el.setAttribute('id', restoredSubArray[0]);
				  el.setAttribute('className','InputSmall');
				  el.setAttribute('class','InputSmall');
				  //el.setAttribute('class','InputList');
				 
				  //el.setAttribute('onchange', "alert('xxx')");
				  MaxLength=((restoredSubArray.length)-2)/2;
				 // alert(MaxLength)
				  var optionvalue=3;
				  var optionTxt=2;
				  var optionMaxPoint=4;
				  for(countOption=1;countOption<=MaxLength;countOption++)
				  {
					  var elOptNew = document.createElement('option');
					  elOptNew.text = restoredSubArray[optionTxt];
					  elOptNew.value = restoredSubArray[optionvalue];
					  //alert(restoredSubArray[optionvalue]);
					  optionvalue=optionvalue+2;
					  optionTxt=optionTxt+2;
					  el.options.add(elOptNew);
  				  }
				
				/*  	el.onchange=function ()
					{
					 	var MaxPoint=this.value.split('/');
						el.parentNode.parentNode.cells[4].innerHTML=MaxPoint[1];
						el.parentNode.parentNode.cells[3].childNodes[1].value=MaxPoint[1];
					};
					*/
				   cellChk.appendChild(el);
			}

////////////
			
			if(restoredSubArray[1]=='tArea')
			{
				 var cellChk = row.insertCell(count+1);
				 var el = document.createElement('textarea');
				 var maxLenthValArea=restoredSubArray[2];
				 el.setAttribute('name', restoredSubArray[0]+'[]');
				 el.setAttribute('id', restoredSubArray[0]);				  
				 el.setAttribute('className',restoredSubArray[3]);
				 el.setAttribute('class',restoredSubArray[3]);
				 cellChk.appendChild(el);
				 el.onkeypress=function()
				 {
				   	if(this.value.length>=maxLenthValArea)
				 	window.event.returnValue =false;
				 }
				 el.onpaste=function()
				 {
				 	if(this.value.length>=maxLenthValArea)
				 	window.event.returnValue =false;
				 }

			}
			if(restoredSubArray[1]=='txt')
			{
				 var cellSerial = row.insertCell(count+1);
				  if(restoredSubArray[2]!=null)
				  	var textNode = document.createTextNode(restoredSubArray[2]);
				  else 
				  	var textNode = document.createTextNode(restoredSubArray[0]);
				  cellSerial.appendChild(textNode);
				 
				   var el = document.createElement('input');
				  el.setAttribute('type', 'hidden');
				  el.setAttribute('name', restoredSubArray[0]+'[]');
				  //alert(el.setAttribute('name', restoredSubArray[0]+'[]'));
				  el.setAttribute('id', restoredSubArray[0]);
				  el.value =(restoredSubArray[2]);
				  //alert(restoredSubArray[1]);
				 
				  cellChk.appendChild(el);

			}
		}
}

function cancelR(Rform,id)
{
	delConfirm=confirm("Are you sure, you want to cancel this resource request.");
	if(delConfirm)
	{
		alert(Rform+'?cID='+id);
		window.location.href=Rform+'?cID='+id;
	}
}
function submitDelForm(frm)
{
	var valString='';
	//alert(checkChkBox(frm))
	if(checkChkBox(frm))
	{
		delConfirm=confirm("Are you sure, you want to delete the selected records.");
		if(delConfirm)
		{
			var el = frm.elements;
			for(var i = 0 ; i < el.length ; ++i) 
			{
				 if(el[i].type == "checkbox") 
				 {
					if(el[i].name!='CheckBoxParent')
					{
						var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
						
						for(var j = 0 ; j < radiogroup.length ; ++j) 
						{
							if(radiogroup[j].checked)
							{

								valString=valString+radiogroup[j].value;
								valString=valString+',';
								
							}
							
						}
						break;
					}
				}
			}
			//alert(frm.CheckBoxChild.checked)
			//======================if not a array======================
			if(frm.CheckBoxChild.checked)
			valString=frm.CheckBoxChild.value+',';
			
			frm.chkValues.value=valString.substring(0,valString.length-1);
			
			frm.submit();
		}
	}
	
}
function submitSort(frm,sortBy,sOrder)
{
	document.forms[frm].elements['sortBy'].value=sortBy;
	document.forms[frm].elements['sortOrder'].value=sOrder;
	document.forms[frm].submit();
}
function ShowDisableEnableField(Fields){
/////////////////////convert in to string
	var ObjFields=Fields.toString();
///////////////////////////split string into array//////////////////////////////like////'tablename;hidden' or 'tablename;visible'
	var restoredArray= ObjFields.split(",");
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
		for(count=0;count<=restoredArray.length-1;count++ ){
//////////////////////////////split the string into seperate string/////////////with seperate table name and value//////////////////////
			var restoredSubArray= restoredArray[count].split(";");
			//alert(restoredSubArray[0]);
//////////////////////////////check the value if hidden then hidde the table//////////////////////////////////////////////////////			
			
			//alert(restoredSubArray[0].substr(0,3));
			
			
			if(restoredSubArray[1]=='disable'){
				document.getElementById(restoredSubArray[0]).disabled=true;
				//alert(restoredSubArray[1]);
			}
//////////////////////////////check the value if visible then visible the table//////////////////////////////////////////////////////			
			if(restoredSubArray[1]=='enable'){
				document.getElementById(restoredSubArray[0]).disabled=false;
				//alert(restoredSubArray[1]);
			}
		}

}

//=================================================================
//			Credit card validation
//=================================================================
function checkCC(ccNumb) 
{  // v2.0
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit
	
	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) 
	{
		temp = "" + sCCN.substring(j, j+1);
		if (valid.indexOf(temp) == "-1"){bNum = false;}
	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum)
	{
		/*alert("Not a Number");*/bResult = false;
	}
	
	// Determine if it is the proper length 
	if((len == 0)&&(bResult))
	{  // nothing, field is blank AND passed above # check
		bResult = false;
	} 
	else
	{  // ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15)
		{  // 15 or 16 for Amex or V/MC
			for(var i=len;i>0;i--)
			{  // LOOP throught the digits of the card
				calc = parseInt(iCCN) % 10;  // right most digit
				calc = parseInt(calc);  // assure it is an integer
				iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
				i--;  // decrement the count - move to the next digit in the card
				iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
				calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
				calc = calc *2;                                 // multiply the digit by two
				// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
				// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
				switch(calc)
				{
					case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
					case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
					case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
					case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
					case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
					default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
				}                                               
				iCCN = iCCN / 10;  // subtracts right most digit from ccNum
				iTotal += calc;  // running total of the card number as we loop
			}  // END OF LOOP
			if ((iTotal%10)==0)
			{  // check to see if the sum Mod 10 is zero
				bResult = true;  // This IS (or could be) a valid credit card number.
			} 
			else 
			{
				bResult = false;  // This could NOT be a valid credit card number
			}
		}
	}
	// change alert to on-page display or other indication as needed.
	/*if(bResult) 
	{
		alert("This IS a valid Credit Card Number!");
	}*/
	if(!bResult){
		alert("Please enter a valid Credit Card Number!");
	}
	return bResult; // Return the results
}

