function isint(value)
{
	if (value.length==0) return true; //is null is a diffrent check

	alphabets="01234567890-"
	value = value.toUpperCase()
	
	for (j=0;j < value.length;j++)
	{
		if (alphabets.indexOf(value.charAt(j))==-1)
			return false
	}
	return true;
}
function IsRadioChecked(radiobutton)
{
var i,n = radiobutton.length,f=false
if (n==null) return radiobutton.checked;

for(i=0;i<n;i++)
{
	if (radiobutton[i].checked) {f=true;break}
}

return f; 
}
function _Obj(name,id)
{
	var obj 
	obj = eval("document.all.Field_"+id)
	if (obj==null) return null;
	return obj
}
function LoadXmlTable2Hidden(LoadFromDS)
{
	var tables=document.all.tags("TABLE")
	var ds,XmlDs,XmlHidden,tagname,addbuton
	var i,n=tables.length
	for(i=0;i<n;i++)
	{
		if (tables(i).dataSrc!="")
		{
		ds=tables(i).dataSrc
		ds=ds.substring(1,255)
		XmlDs = eval("document.all."+ds)
		XmlHidden = eval("document.all.Field_SubTable_"+ds)
			try
			{			
				if (LoadFromDS==1)
				{
					if (XmlHidden.tagName=="SPAN") // Readonly Field
					{
						addbuton=eval("document.all.DS_AddBut_"+ds.substr(3,255))
						if (addbuton!=null) 
						{
							addbuton.disabled =1
							tables(i).dataSrc =""
							tables(i).disabled =1
							FixReadOnlyTables(tables(i))
							tables(i).dataSrc = "#"+ds
						}
						if ((XmlHidden.innerText.length>0)&&(XmlHidden.innerText!="Empty."))
						{
							var str=new String(XmlHidden.innerText)
							XmlDs.XMLDocument.loadXML(str)				
						}
					}
					else
					{
						if (XmlHidden.value.length>0) 
						{
						
							var str=new String(XmlHidden.value)
						
							XmlDs.XMLDocument.loadXML(str)
						}
					}
				}
				else
				{
					var str=new String(XmlDs.XMLDocument.xml)
					XmlHidden.value=str
				}
			}
			catch(e)
			{
				alert("Warning:Unable to Loading XML")
				return
			}
		}
	}
	gDisableInsDelBtn();
}
function gDisableInsDelBtn()
{
		var k=0;
		var coll = document.all.tags("TABLE");
		var l = coll.length
		if ( l > 0)
        {
          for(var i=0;i<l;i++)
			{ 
				if ( coll(i).getAttribute("TP") == null  ||  coll(i).TP == "" )	
				 {
						continue; 
				 }	
				else	
					{
						var tpno = coll(i).getAttribute("TP") ;
						var coll1 = document.all.tags("INPUT");
						for(var p=0;p< coll1.length;p++)
						{
							var DTSR = coll(i).getAttribute("DATASRC")
							var BTNID = coll1(p).id ;
							var tt1 =  "_DelBut" + DTSR.substr(DTSR.lastIndexOf("_")) ;
							var tt2 =  "_InsBut" + DTSR.substr(DTSR.lastIndexOf("_")) ;
							if (tpno == "2")			//	if (tpno == "1") = modified on 8/1/02
							{							
								if ( BTNID.indexOf(tt2) >= 0 ) 	coll1(p).disabled = true;
								if ( (coll1(p).name).indexOf("_AddBut_") >= 0 )		// coll1(p).disabled = true;
								  {	   
										if ( coll1(p).name == "DS_AddBut"+ DTSR.substr(DTSR.lastIndexOf("_")) )
												coll1(p).disabled = true;
								  }		
							}
							else if (tpno == "1")		//	else if (tpno == "2") = modified on 8/1/02
							{
								if ( BTNID.indexOf(tt1) >= 0 ) 	coll1(p).disabled = true;
							}	
						}
					}
			}
		}
}
function isemptyAlert(obj)
{
	if (isempty(obj.value))
	{
		alert(obj.id+" should not be empty")
		obj.focus();
		return true;
	}
	return false;
}

function isempty(value)
{
	if (value.length==0) return true; //is null is a diffrent check
	f=0
	for(i=0;i<value.length;i++)
	{
		if (value.charAt(i)>' ')
		{
			f=1;break;
		}
	}
	if (f==0) return true;else return false;
	
}
function ValidateXmlTable()
{
   		var Inputs,i,custommessage
   		Inputs = eval(document.gCmsFormMain.elements)
   		   		
		for (i=0; i<Inputs.length; i++) 
		{
			if ((Inputs[i].Validate!=null)&&(Inputs[i].customTTTT!=null))
			{
				if (IsInputInDisabledTable(Inputs[i])==true) continue;
			
				st=Inputs[i].Validate

					pos1=st.indexOf('[')
					pos2=st.indexOf(']')
					custommessage=""
					if ((pos1>-1)&&(pos2>-1))
					{
						custommessage=st.substr(pos1+1,pos2-pos1-1)
					}
				if (st.indexOf('notnull')!=-1)
				{
					if (Inputs[i].type=="checkbox")
					{
						if (!Inputs[i].checked)
						{
							if (custommessage.length>0)
								alert(custommessage);
							else 
								alert("Empty Data not Allowed ")
							Inputs[i].focus();
							return false;
							
						}
					}
					if ((Inputs[i].type=="radio") )
					{
						var rad,atleastonechecked
						rad = eval("document.all."+Inputs[i].id)
						atleastonechecked=0
						for(j=0;j<rad.length;j++)
						{
							if (rad[j].checked) {atleastonechecked=1;break;}
						}
						if (atleastonechecked==0)
						{
							alert("Empty Data not Allowed For "+rad[0].Label)
							rad[0].focus();
							return false;
							
						}
					}
					
					if (Inputs[i].type=="select-one")
					{
						var dropdown
						dropdown = eval("document.all."+Inputs[i].id)
						if (dropdown.value != null) {
							if (dropdown.value.length == 0 )
							{
								if (custommessage.length>0)
									alert(custommessage);
								else 
									alert("Atleast one Item should be selected ");
								Inputs[i].focus();
								return false;
							}
						}
						else{
							for (m= 0 ; m <dropdown.length; m++){
								if (dropdown[m].value.length == 0 )
								{
									if (custommessage.length>0)
										alert(custommessage);
									else 
										alert("Atleast one Item should be selected ");
									dropdown[m].focus();
									return false;
								}
							}
						}
					}
					if (isempty(Inputs[i].value))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("Empty Data not Allowed.")
						Inputs[i].focus();
						return false;
					}				
				}
				if (Inputs[i].value.length==0) continue;		
				if (st.indexOf('isnumeric')!=-1)
				{
					if (!isnumeric(Inputs[i].value))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("Non Numeric Data not Allowed.")
						Inputs[i].focus();
						return false;
					}				
				}				
				if (st.indexOf('isint')!=-1)
				{
					if (!isint(Inputs[i].value))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("Non Integer Data not Allowed.")
						Inputs[i].focus();
						return false;
					}				
				}
				if (st.indexOf('isalpha')!=-1)
				{
					if (isnumeric(Inputs[i].value))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("Should have atleast one alphabet.")							
						Inputs[i].focus();
						return false;
					}				
				}				
				if (st.indexOf('isemail')!=-1)
				{
					if (!isemail(Inputs[i].value))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("should be a valid email address.")
						Inputs[i].focus();
						return false;
					}				
				}
				if (st.indexOf('isdate')!=-1)
				{
					if (!isdate(Inputs[i]))	
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("should be a valid Date(DD/MM/YYYY) with YYYY > 1969.")
						Inputs[i].focus();
						return false;
					}				
				}				
				if (st.indexOf('istime')!=-1)
				{
					if (!istime(Inputs[i].value))
					{
						if (custommessage.length>0)
							alert(custommessage)
						else 
							alert("should be a valid time(hh:mm).")
						Inputs[i].focus();
						return false;
					}				
				}				
				if (st.indexOf('(')!=-1)
				{								
					pos1=st.indexOf('(')
					pos2=st.indexOf(')')
					if ((pos1>-1)&&(pos2>-1))
					{
						str=st.substr(pos1+1,pos2-pos1-1)
						var strA
						strA=str.split("~")
						if (!isinrange(Inputs[i].value,strA[0],strA[1]))	
						{
							if (custommessage.length>0)
								alert(custommessage)
							else 
								alert("Should be between "+strA[0]+" & "+strA[1])
							Inputs[i].focus();
							return false;
						}				
					}
				}				
			}
		}		
	return true
}
function IsDropDownSelected(selectbox)
{
var i,n=selectbox.length,f=false
if (n==null) return selectbox.selected;
for(i=0;i<n;i++)
{
	if (selectbox[i].selected)
	{
		f=true;
		var ss
		ss = trim(selectbox[i].value)
		ss1 = trim(selectbox[i].text)
		if ((ss.length==0)||(ss=="")){
			if((ss1.length==0)||(ss1=="")){
			f=false;
			selectbox.focus()
			}
			break
		}
	}
}
return f;
}
function trim(stringV){
	var str;
	str=stringV;	
	str=str.replace(/^\s+/g, "");
	str=str.replace(/\s+$/g, "");
	return str;
}
function _Val(name,id)
{
	var obj 
	obj = eval("document.all.Field_"+id)
	if (obj==null) return null;
	if (obj.type == 'hidden') return obj.value
	if (obj.length >=2)                             //changed by priya for 
	{				
	var str1 = "";								// enabling _val for radio buttons
		for ( i = 0; i < obj.length; i++)
		{
			if (obj[i].checked == true) 
			return obj[i].value
		}
		str1 ="";
		return str1;
	}                                               // till here
	validate = obj.Validate
	if (validate.indexOf("isint")!=-1) return parseInt(obj.value)
	if (validate.indexOf("isnumeric")!=-1) return parseFloat(obj.value)
	
	return obj.value
}
function readystateinfo(Obj){ // added by priya.
 if (Obj.readyState == "complete"){
	try{
		getoptions() //This function is used to get the stored dropdown values of a table and to set them to thier relevent field.
	}catch(e){}
	Obj.title = "Done"
	return;
 }
 if (Obj.title == "Done") gDisableInsDelBtn();
}
function isnumeric(value)
{
	if (value.length==0) return true; //is null is a diffrent check
	alphabets="01234567890-."
	value = value.toUpperCase()
	for (j=0;j < value.length;j++)
	{
		if (alphabets.indexOf(value.charAt(j))==-1)
			return false
	}
	return true;
}
function appendXmlRow(xmlDoc,defstr)
{
	var rootNode = xmlDoc.XMLDocument.selectSingleNode('root')
	var newNode = xmlDoc.XMLDocument.createNode("element", "row", "")
	SetAttributes2Node(newNode,defstr)
	rootNode.appendChild( newNode )
	gDisableInsDelBtn();
	try
	{
		OnAfterAppendXmlRow()
	}
	catch(e)
	{
	}
}
function SetAttributes2Node(Node,AttrStr)
{
	var name,value,ch,st,f=0,i
	st=""
	for(i=0;i<AttrStr.length;i++)
	{
		ch=AttrStr.charAt(i)
		if ((f==0)&&(ch=='='))
		{
			name=st
			i++
			st=""
			f=1
		}
		else if ((f==1)&&(ch=='\"'))
		{
			value=st
			i++
			st=""
			f=0
			Node.setAttribute(name,value)
		}
		else st=st+ch
	}
}
function deleteXMLRow(xmlDoc,node)
{
	var rootNode = xmlDoc.XMLDocument.selectSingleNode('root')
	var i=node.parentElement.parentElement.rowIndex
	if (i==0)
	{	
		alert("Header has been removed from the XML table.")
		return
	}
	if (i>0) i--;
	rootNode.removeChild(rootNode.childNodes(i))
	gDisableInsDelBtn();
	try
	{
		OnAfterDeleteXmlRow()
	}
	catch(e)
	{
	}
}
function IsInputInDisabledTable(elem)
{
	while (elem!=null)
	{
		if ((elem.tagName=="TABLE")&&(elem.disabled==true)) return true;
		elem = elem.parentElement
	}
return false
}
function IsCheckBoxChecked(button)
{
	return button.checked;
}
function isint(value)
{
	if (value.length==0) return true; //is null is a diffrent check

	alphabets="01234567890-"
	value = value.toUpperCase()
	
	for (j=0;j < value.length;j++)
	{
		if (alphabets.indexOf(value.charAt(j))==-1)
			return false
	}
	return true;
}
