function valid(x,nwcat)
{
	if(x == "")
	{
		alert("Enter Category") ;
		nwcat.focus();
		return false ;
	}
	return true ;
}
function validsubcat(x,n,y,nwcat1)
{
	if(x == "")
	{
		alert("Please Select Category") ;
		n.focus();
		return false ;
	}
	if(y == "")
	{
		alert("Enter subCategory") ;
		nwcat1.focus();
		return false ;
	}
	return true ;
}
function validpetasubcat(x,n,y,nwcat1,z,nwcat2)
{
	if(x == "")
	{
		alert("Please Select Category") ;
		n.focus();
		return false ;
	}
	if(y == "")
	{
		alert("Please Select subCategory") ;
		nwcat1.focus();
		return false ;
	}
	if(z == "")
	{
		alert("Enter petasubCategory") ;
		nwcat2.focus();
		return false ;
	}
	return true ;
}


function validsub(th)
{
	if(th.nwcat.value == "")
	{
		alert("Enter Sub category") ;
		th.nwcat.focus();
		return false ;
	}
	if(th.cat_id.value == "")
	{
		alert("Select Category") ;
		th.cat_id.focus();
		return false ;
	}
	return true ;
}
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

///////////////////////////////////////////////////////////////////////////////////////// general ajx function

function ajaxCtntMe(phppage,qrylst,divid)
{
	//return false;
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url=phppage;
	url=url+"?"+qrylst;
	
	//url=url+"&sid="+Math.random();

	xmlHttp.open('GET',url,true);

	xmlHttp.onreadystatechange=function(){ onstateChanged(divid); }

	xmlHttp.send(null);
}

function refresh_headerchk(FormName, FieldName,headerchk)
{
	
	var flg=true;
	
	if(!document.forms[FormName])
		return;
	var headerchkObj=document.forms[FormName].elements[headerchk];
	var objCheckBoxes = new Array();
	objCheckBoxes=document.forms[FormName].elements[FieldName];
	
	
	
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	
	if(countCheckBoxes===undefined)
	{
		headerchkObj.checked=objCheckBoxes.checked;
		return;
	}
	
	
	for(i=0;i<countCheckBoxes;i++)
	{
		if(objCheckBoxes[i].checked==false)
		{
			flg=false;
			break;
		}
		
	} 
	headerchkObj.checked=flg;
}

function onstateChanged(ctrlname) 
{ 
	if(xmlHttp.readyState==4)
	{ 
		 var rslt = xmlHttp.responseText;
		var row = rslt.split(',');
		for(var i=0;i<row.length;i++){
			var d = row[i].split(':');
			if(d.length>1){
				var optn = document.createElement("OPTION");
				optn.text = d[1];
				optn.value = d[0];
				document.getElementById('state').options.add(optn);
			}
		}

		//document.getElementById(ctrlname).innerHTML = rslt;
		
		
	}

}

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


		function GetSelectedItem()
		{
		
		var len = document.form1.bloglist.length
		var i = 0
		var chosen = ""
		
			for (i = 0; i < len; i++)
			{
				if (document.form1.bloglist[i].selected)
				{
				chosen = chosen + ", " + document.form1.bloglist[i].value;
				}
			}
		chosen = chosen.substring(1);
		
		ajaxContMe(chosen,document.getElementById('userlist').value)
		
		}
		
		////////////////////////////////////FOR SELECT ALL VALUE OF MULTIPLE SELECT //////////////////////////////////
		
		function selectAllOptions(th,obj)
		{
			if(th.checked==true)
			{
				for (var i=0; i<obj.options.length; i++) 
				{
					obj.options[i].selected = true;
				}
			}
		}
		
		function testalert(phppage)
		{
			alert("This js is working" + phppage);
			return false;
		}
		function multiple_checkbox(theForm)
		{
			var z = 0,ischk = 0, DeleteItms = '0';
			for(z=0; z<theForm.length;z++)
			{
	
				  if(theForm[z].type == 'checkbox' && theForm[z].name == 'allids[]' && (!theForm[z].disabled) && (theForm[z].checked))
					{
					ischk = 1;
					DeleteItms = DeleteItms + ',' + theForm[z].value;
					}
			}
			 if(ischk == 0)
			 {
				 alert("Select atleast 1 item to delete");
				 return false;
			 }
			return DeleteItms.substr(2);
		}
		function DelMulti(theForm,thpage)
		{	
			var delitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=6&ids='+delitem,'righttd');
		}
		
		function ActiveMulti(theForm,thpage)
		{
			var activeitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=7&ids='+activeitem,'righttd');
		}
		
		function inActiveMulti(theForm,thpage)
		{
			var inactiveitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=8&ids='+inactiveitem,'righttd');
		}
		
		function DelMulti1(theForm,thpage)
		{	
			var delitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=4&ids='+delitem,'righttd');
		}
		
		function ActiveMulti1(theForm,thpage)
		{
			var activeitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=5&ids='+activeitem,'righttd');
		}
		
		function inActiveMulti1(theForm,thpage)
		{
			var inactiveitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=6&ids='+inactiveitem,'righttd');
		}
		
		function DelMulti2(theForm,thpage)
		{	
			var delitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=4&ids='+delitem,'righttd');
		}
		
		function ActiveMulti2(theForm,thpage)
		{
			var activeitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=5&ids='+activeitem,'righttd');
		}
		
		function inActiveMulti2(theForm,thpage)
		{
			var inactiveitem = multiple_checkbox(theForm);
			ajaxCtntMe('http://ss3/directory/admin/common/statechange.php','pag='+thpage+'&act=6&ids='+inactiveitem,'righttd');
		}