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;
}
//manoj code
// function for filter table
function filter(term, _id, type)
{
	xmlhttp=getxmlhttpobject();
	var suche = term.value.toLowerCase();
	var table = document.getElementById(_id);
	var ele;
	var query='';
	if (table.rows)
	{
			ele = '';
			query=query+"txtval="+suche;
			query=query+"&type="+type;
			for (var r = 0; r < table.rows.length; r++)
			{
				table.rows[r].style.display = 'none';
			}
			document.getElementById("filter").innerHTML='Searching...';
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4)
				{
					document.getElementById("filter").innerHTML=xmlhttp.responseText;
					//document.getElementById("filt").value=suche;
					//parent.frames['content'].location.reload(true);
				}
			}
			xmlhttp.open("GET","passnext.php?action=searchtable&"+query,true);
			xmlhttp.send(null);
			//return false;

			/*
			for (var ctr=0; ctr < (table.rows[r].cells.length -1); ctr++)
			{
				
				ele += table.rows[r].cells[ctr].innerHTML.replace(/<[^>]+>/g,"")+ ' ';				
			}

			if (ele.toLowerCase().indexOf(suche) >=0)
			{
				table.rows[r].style.display = '';
			}
			else 
			{
				table.rows[r].style.display = 'none';
			}
			*/
		//}
	}	
}
// function for save n delete

function deleteAll(frm,type)
{
	
	var query='';
	var i=0;
	xmlhttp=getxmlhttpobject();
	for (var ctr=0; ctr < frm.length; ctr++)
	{
		field_name = frm.elements[ctr].name;
			if (field_name.indexOf("chk") != -1)
			{
				var data=frm.elements[ctr].value;
				query=query+"val_"+i+"="+data+"&";
				i=i+1;
			}
	}
	query=query+"type="+type+"&rec="+i;
	document.getElementById("deleting").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("deleting").innerHTML=xmlhttp.responseText;
		}
	}
	alert(query);
	xmlhttp.open("GET","passnext.php?action=delete&"+query,true);
	xmlhttp.send(null);
	return false;
}
//////////////////
function editValueNoTxtbx(frm,id,data,type)
{
	xmlhttp=getxmlhttpobject();
	var query="val="+data+"&id="+id+"&type="+type;
	document.getElementById("ajaxrep").innerHTML='Saving...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);
		}
	}
	xmlhttp.open("GET","passnext.php?action=edit&"+query,true);
	xmlhttp.send(null);
	return false;
}

////////////////////////////////////////////////////
function editValue(frm,id,rowno,type)
{
	xmlhttp=getxmlhttpobject();
	for (var ctr=0; ctr < frm.length; ctr++)
	{
		field_name = frm.elements[ctr].name;
		if (field_name.indexOf("txt") != -1)
		{
			var cnt=frm.elements[ctr].name.split("_");
			if(cnt[1]==rowno)
			{
				var data=frm.elements[ctr].value;
				var query="val="+data+"&id="+id+"&type="+type;
		
				document.getElementById("ajaxrep").innerHTML='Saving...';
				xmlhttp.onreadystatechange=function()
				{
					if (xmlhttp.readyState==4)
				 	{
				  		document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
				 	}
				}
				xmlhttp.open("GET","passnext.php?action=edit&"+query,true);
				xmlhttp.send(null);
				return false;
			}
		}
	}
}
///////////////////////////////////////////////


function deleteValueDynamic(frm,id,type,joinvalue)
{
	var con = confirm('Are you sure to delete this Image?');
	if(con){
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type+"&joinval="+joinvalue;
	
	document.getElementById('ajaxrep1').innerHTML = 'deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById('ajaxrep1').innerHTML=xmlhttp.responseText;
			window.location.href='alchemy_add.php?aid='+id;
			//parent.frames['content'].location.reload(true);
		}
	}
	xmlhttp.open("GET","pass.php?action=delete&"+query,true);
	xmlhttp.send(null);
	}else{
	return false;
	}
}

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

function deleteValue(frm,id,type)
{
	
	$con = confirm('Are you sure to delete?');
	if($con == true){
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type;
	document.getElementById("ajaxrep").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			window.location.href='group.php';
			parent.frames['content'].location.reload(true);
		}
	}
	
	xmlhttp.open("GET","pass.php?action=delete&"+query,true);
	xmlhttp.send(null);
	}else{
	return false;
	}
}
//check user name verification //
function chkuname_owner()
{
	
	xmlhttp7 = getxmlhttpobject()
	var email = document.getElementById("email").value;
	var usertype = document.getElementById("usertypesel").checked;
	var query = "email="+email+"&usertype="+usertype;
	//alert(query);
	document.getElementById("chkuname").innerHTML = "<span class='ajaxmsg'>Checking...</span><img src=images/icon_loading.gif />";
	xmlhttp7.onreadystatechange=function(){
	if (xmlhttp7.readyState==4)
	  { 
	    chck = xmlhttp7.responseText;
	    
		if(chck == "<span class='ajaxmsg'>Already taken.Choose another.</span>")
		{
		 alert('Already taken Choose another.');
		 document.getElementById("email").value ='';
		 document.getElementById("email").focus();
		}
		if(chck == "<span class='ajaxmsg'>Please Enter Username.</span>")
		{
		 alert('Please Enter Username.');
		 document.getElementById("email").value ='';		 
		 document.getElementById("email").focus();
		 return false;
		}
		document.getElementById("chkuname").innerHTML=xmlhttp7.responseText;
	  }
	}
	xmlhttp7.open("GET","pass.php?action=registerview_owner&"+query,true)
	xmlhttp7.send(null)
}

//check user name verification //
function chk_username()
{
	xmlhttp7 = getxmlhttpobject()
	var name = document.getElementById("name").value;
	var query = "name="+name;
	document.getElementById("chkun").innerHTML = "<span class='ajaxmsg'>Checking...</span><img src=images/icon_loading.gif />";
	xmlhttp7.onreadystatechange=function(){
	if (xmlhttp7.readyState==4)
	  { 
	    chck = xmlhttp7.responseText;
	   if(chck == "<span class='ajaxmsg'>Already taken.Choose another.</span>")
		{
		 alert('Already taken Choose another.');
		 document.getElementById("name").value ='';
		 document.getElementById("name").focus();
		}
		if(chck == "<span class='ajaxmsg'>Please Enter Username.</span>")
		{
		 alert('Please Enter Username.');
		 document.getElementById("name").value ='';		 
		 document.getElementById("name").focus();
		 return false;
		}
		document.getElementById("chkun").innerHTML=xmlhttp7.responseText;
	  }
	}
	xmlhttp7.open("GET","pass.php?action=user_name&"+query,true)
	xmlhttp7.send(null)
}
//rating//
function couponwork(frm,id,type,val)
{
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type+"&value="+val;
	//alert(query);
	document.getElementById("ajaxrep").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			window.location.href='group.php';
			parent.frames['content'].location.reload(true);
		}
	}
	xmlhttp.open("GET","passAjax.php?action=rating&"+query,true);
	xmlhttp.send(null);
}

function deleteMainTopic(frm,id,type)
{
	
	 $con = confirm('Are you sure to delete main topic?');
	
	if($con == true){
	
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type;
	//alert(query);
	document.getElementById("ajaxrep").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			window.location.href='group.php';
			//parent.frames['content'].location.reload(true);
		}
	}

	xmlhttp.open("GET","passAjax.php?action=delete&"+query,true);
	xmlhttp.send(null);
	}else{
	return false;
	}
}


function friendreject(frm,id,type){
	
	 $con = confirm('Are you sure to Reject this Friendship?');
	
	if($con == true){
	
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type;
	
	document.getElementById("ajaxrep").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);
		}
	}

	xmlhttp.open("GET","passAjax.php?action=rejectfrn&"+query,true);
	xmlhttp.send(null);
	}else{
	return false;
	}
	}
function friendconfirm(frm,id,type){
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type;
	
	document.getElementById("ajaxrep").innerHTML='Friend Confirm...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);
		}
	}
	xmlhttp.open("GET","passAjax.php?action=confirmfrn&"+query,true);
	xmlhttp.send(null);
}	
function removefriend(frm,id,type){
	 $con = confirm('Are you sure to Delete this Friend?');
	
	if($con == true){
	
	xmlhttp=getxmlhttpobject();
	var query="id="+id+"&type="+type;
	
	document.getElementById("ajaxrep").innerHTML='Deleting...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);
		}
	}
	xmlhttp.open("GET","passAjax.php?action=deletefrn&"+query,true);
	xmlhttp.send(null);
	}else{
	return false;
	}
	}
// for temporary 
function editValue1(frm,id,rowno)
{
	xmlhttp=getxmlhttpobject();
	for (var ctr=0; ctr < frm.length; ctr++)
	{
		field_name = frm.elements[ctr].name;
		if (field_name.indexOf("txt") != -1)
		{
			var cnt=frm.elements[ctr].name.split("_");
			if(cnt[1]==rowno)
			{
				var data=frm.elements[ctr].value;
				var query="val="+data+"&id="+id;
				//alert(query);
				document.getElementById("ajaxrep").innerHTML='Saving...';
				xmlhttp.onreadystatechange=function()
				{
					if (xmlhttp.readyState==4)
				 	{
				  		document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
				 	}
				}
				xmlhttp.open("GET","passnext.php?action=editmusic&"+query,true);
				xmlhttp.send(null);
			}
		}
	}
}
function deleteValue1(frm,id,rowno)
{
	
	xmlhttp=getxmlhttpobject();
	var query="id="+id;
	
	alert(query);
	
	document.getElementById("ajaxrep").innerHTML='Saving...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);		
		}
	}
	xmlhttp.open("GET","passnext.php?action=deletemusic&"+query,true);
	xmlhttp.send(null);
	return false;
}

// end function
// end
// pre made 
function chkuname()
{
	
	xmlhttp=getxmlhttpobject();
	var uname = document.getElementById("uname").value;
	var query = "uname="+uname;
	
	document.getElementById("chkuname").innerHTML = "<span class='ajaxmsg'>Checking...</span><img src=images/icon_loading.gif />";
	xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4)
	  { 
	    chck = xmlhttp.responseText;
	    if(chck == "<span class='ajaxmsg'>Already taken.Choose another.</span>")
		{
		 alert('Already taken Choose another.');
		 document.getElementById("uname").value ='';
		 document.getElementById("uname").focus();
		}
		if(chck == "<span class='ajaxmsg'>Please Enter Username.</span>")
		{
		 alert('Please Enter Username.');
		 document.getElementById("uname").value ='';
		 document.getElementById("uname").focus();
		}
		document.getElementById("chkuname").innerHTML=xmlhttp.responseText;
	  }
	}
	xmlhttp.open("GET","pass.php?action=registerview&"+query,true)
	xmlhttp.send(null)
}

function chkVcode()
{
	var str=document.getElementById("varification").value;
	var url="pass.php?block=main&go=check_Vcode&v_code="+str;
			alert (url);
			xmlHttp=getobject();
			//xmlHttp.onreadystatechange=VcChanged;
			document.getElementById("Vc_div").innerHTML='checking...';
			xmlHttp.onreadystatechange=function()
				{
					if (xmlHttp.readyState==4)
				 	{
				  		document.getElementById("Vc_div").innerHTML=xmlHttp.responseText;
				 	}
				}			
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			return false;
}

/*function chkcode(id)
{
	xmlhttp = getxmlhttpobject()
	var uname = id.value;
	alert(uname);
	var query = "uname="+uname;
	document.getElementById("chkuname1").innerHTML = "<span class='ajaxmsg'>Checking...</span><img src=images/icon_loading.gif />";
	xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4)
	  { 
	    chck = xmlhttp.responseText;
	    if(chck == "<span class='ajaxmsg'>Already taken.Choose another.</span>")
		{
		 alert('Already taken Choose another.');
		 id.value ='';
		 id.focus();
		}
		if(chck == "<span class='ajaxmsg'>Please Enter Username.</span>")
		{
		 alert('Please Enter Username.');
		 id.value ='';
		 id.focus();
		}
		document.getElementById("chkuname1").innerHTML=xmlhttp.responseText;
	  }
	}

	xmlhttp.open("GET","pass.php?action=check&"+query,true)
	xmlhttp.send(null)
}*/


function editValueStatus(frm,id,data)
{
	
	xmlhttp=getxmlhttpobject();
	var query="val="+data+"&id="+id;
	document.getElementById("ajaxrep").innerHTML='Saving...';
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("ajaxrep").innerHTML=xmlhttp.responseText;
			parent.frames['content'].location.reload(true);
		}
	}
	//alert("pass.php?action=edit&"+query);
	xmlhttp.open("GET","pass.php?action=editstatus&"+query,true);
	xmlhttp.send(null);
	//return false;
}
/*********CODE***********/
	function chkuname1(id)
{
	xmlhttp7 = getxmlhttpobject()
	var uname = id.value;
	var query = "uname="+uname;
	document.getElementById("chkuname1").innerHTML = "<span class='ajaxmsg'>Checking...</span><img src=images/icon_loading.gif />";
	xmlhttp7.onreadystatechange=function(){
	if (xmlhttp7.readyState==4)
	  { 
	    chck = xmlhttp7.responseText;
		
		if(chck == "<span class='ajaxmsg'>Please enter right code.</span>")
		{	
		 document.getElementById("varification").value ='';
		 document.getElementById("varification").focus();
		 //return false;
		}
		if(chck == "<span class='ajaxmsg'>Please Enter verification code.</span>")
		{
		 document.getElementById("varification").value ='';
		 document.getElementById("varification").focus();
		 //return false;
		}
		
		document.getElementById("chkuname1").innerHTML=xmlhttp7.responseText;
		return false;
	  }
	}
	
	xmlhttp7.open("GET","pass.php?action=check&"+query,true)
	xmlhttp7.send(null)
}

/***********MANAGE CATEGORY AND SUBCATEGORY*************/
function show_sub_cat(catid)
{
	xmlhttp3=getxmlhttpobject()
	document.getElementById("div2").innerHTML="<span class='ajaxmsg'>Loading...</span><img src=images/working1.gif />";
	document.getElementById("div3").innerHTML="";
	xmlhttp3.onreadystatechange=function(){
		if (xmlhttp3.readyState==4)
		{
			document.getElementById("div2").innerHTML=xmlhttp3.responseText;
		}
	}
	xmlhttp3.open("GET","passnext.php?action=show_sub_cat&catid="+catid,true)
	xmlhttp3.send(null)
}

function show_option(sub_catid)
{
	xmlhttp4=getxmlhttpobject()
	document.getElementById("div3").innerHTML="<span class='ajaxmsg'>Loading...</span><img src=images/working1.gif />";
	xmlhttp4.onreadystatechange=function(){
		if (xmlhttp4.readyState==4)
		{
			document.getElementById("div3").innerHTML=xmlhttp4.responseText;
		}
	}
	xmlhttp4.open("GET","passnext.php?action=show_option&sub_catid="+sub_catid,true)
xmlhttp4.send(null)
}


///////////////top ten list/////////////////////
function toptenlist(id){
	xmlhttp4=getxmlhttpobject()
	xmlhttp4.onreadystatechange=function(){
		if (xmlhttp4.readyState==4)
		{
			document.getElementById("divtoplist").innerHTML=xmlhttp4.responseText;
		}
	}
	xmlhttp4.open("GET","toptenlist.php?ttl="+id,true)
	xmlhttp4.send(null)
}
///////////////contact us question answer////////////////
function questionanswer(qid){
	xmlhttp4=getxmlhttpobject()
	xmlhttp4.onreadystatechange=function(){
		if (xmlhttp4.readyState==4)
		{
			document.getElementById("answerdiv").innerHTML=xmlhttp4.responseText;
		}
	}
	xmlhttp4.open("GET","quesanswer.php?qid="+qid,true)
	xmlhttp4.send(null)
}
//////
function submit_comment(frm,commentid,commentval,commentname){

 if((commentname.length == 0)){
  alert("Please insert your name");
 } else if((commentval.length == 0)){
  alert("Please insert some comment");
 }else{
 xmlhttp4=getxmlhttpobject()
 document.getElementById("load_img").innerHTML = "<img src='http://www.mysale.ee/images/icon_loading.gif' >";
 var query="val="+commentval+"&id="+commentid+"&name="+commentname;
 xmlhttp4.onreadystatechange=function(){
  if (xmlhttp4.readyState==4)
  {
   //document.getElementById("load_data").innerHTML=xmlhttp4.responseText;
   document.getElementById("load_img").innerHTML = "";
  }
 }
  xmlhttp4.open("GET","http://www.mysale.ee/pass.php?action=addcomment&"+query,true)
 xmlhttp4.send(null)
 }
}

//shiblee 23/sep/2008
function packagedescription(pid){
	xmlhttp4=getxmlhttpobject()
	xmlhttp4.onreadystatechange=function(){
		if (xmlhttp4.readyState==4)
		{
			document.getElementById("prolisterpkg").innerHTML=xmlhttp4.responseText;
		}
	}
	xmlhttp4.open("GET","pass.php?action=prolister&pid="+pid,true)
	xmlhttp4.send(null)
}
