var config_cat_id = '' ; 

// Loading Similer Scripts By: Prosenjit Sarkar 5/4/2011
function get_similer_scripts(cat_id)
{
   var randomnumber=Math.floor(Math.random()*1231) ;
 
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		window['xmlhttp' + randomnumber ] =new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		window['xmlhttp' + randomnumber ] =new ActiveXObject("Microsoft.XMLHTTP");
	}
	window['xmlhttp' + randomnumber ].onreadystatechange=function()
	{
		if (window['xmlhttp' + randomnumber ].readyState==4 && window['xmlhttp' + randomnumber ].status==200)
		{

			   
			var cn = document.getElementById('ads_right_home_ads' );
			if(cn){
				cn.innerHTML= "" ;
				cn.innerHTML= window['xmlhttp' + randomnumber ].responseText + " <div id='ads_right_home_ads_n'> </div>";
				loadSideAds(cat_id);
	            	}
                 
		}
	}
	window['xmlhttp' + randomnumber ].open("GET", config_site_url + "get_similer_scripts.php?id=" + cat_id ,true);
	window['xmlhttp' + randomnumber ].send();
}// end of function 



function getdirectory_content(path)
{

   var randomnumber=Math.floor(Math.random()*1231) ;
 
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		window['xmlhttp' + randomnumber ] =new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		window['xmlhttp' + randomnumber ] =new ActiveXObject("Microsoft.XMLHTTP");
	}
	window['xmlhttp' + randomnumber ].onreadystatechange=function()
	{
		if (window['xmlhttp' + randomnumber ].readyState==4 && window['xmlhttp' + randomnumber ].status==200)
		{

			var cn = document.getElementById('directory-product-content' );
			if(cn){
				var dircont = window['xmlhttp' + randomnumber ].responseText;
				var dirpath =  dircont.split("|",2);
				var  dir_path = dirpath[0];
				dircont = dircont.replace(dir_path+ "|" , "");
				dir_path = config_site_url + dir_path ;
				var dirname = dirpath[1] ;
				dircont = dircont.replace(dirname+ "|" , "")
				var likebuttons = '<iframe src="'+ config_site_url +'likebutton.php?pageurl=' + dir_path + '&dirname=' + dirname +'" width="100%" height="75" scrolling=no frameborder= 0> <p>Your browser does not support iframes.</p></iframe>' ;
				cn.innerHTML= likebuttons + dircont + "<div id='ads_right_home_ads_n'> </div>";
				get_similer_scripts(path);
			}
                 
		}
	}
	window['xmlhttp' + randomnumber ].open("GET", config_site_url + "loadproduct.php?id=" + path ,true);
	window['xmlhttp' + randomnumber ].send();
}


 function utf8_decode ( str_data ) {  
     // Converts a UTF-8 encoded string to ISO-8859-1    
     //   
     // version: 810.1317  
     // discuss at: http://phpjs.org/functions/utf8_decode  
     // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)  
     // +      input by: Aman Gupta  
     // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
     // +   improved by: Norman "zEh" Fuchs  
     // +   bugfixed by: hitwork  
     // +   bugfixed by: Onno Marsman  
     // *     example 1: utf8_decode('Kevin van Zonneveld');  
     // *     returns 1: 'Kevin van Zonneveld'  
     var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;  
   
     str_data += '';  
   
     while ( i < str_data.length ) {  
         c1 = str_data.charCodeAt(i);  
         if (c1 < 128) {  
             tmp_arr[ac++] = String.fromCharCode(c1);  
             i++;  
         } else if ((c1 > 191) && (c1 < 224)) {  
             c2 = str_data.charCodeAt(i+1);  
             tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));  
             i += 2;  
         } else {  
             c2 = str_data.charCodeAt(i+1);  
             c3 = str_data.charCodeAt(i+2);  
             tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
             i += 3;  
         }  
     }  
   
     return tmp_arr.join('');  
 }  
   


function swapsearch(id){
	if(id==1){ //Mystic Search ON
		document.getElementById("google_search").style.display='none';
		document.getElementById("mysticscript_search").style.display='block';
	}else if(id==2){  //Google Search ON
		document.getElementById("google_search").style.display='block';
		document.getElementById("mysticscript_search").style.display='none';
	}
}



function loadSideAds(config_cat_id) {
	ifrm = document.createElement("IFRAME");
	ifrm.setAttribute("src", config_site_url + "googleads.php?config_cat_id=" + config_cat_id );
	ifrm.setAttribute("frameborder", "0") ;
	ifrm.setAttribute("id", "mysticsideads");
	ifrm.setAttribute("name", "mysticsideads");
	ifrm.style.width = 310+"px";
	ifrm.style.height = 830+"px";
	ifrm.scrolling= "no";
	ifrm.frameBorder = "no";
	document.body.appendChild(ifrm);
	document.getElementById('ads_right_home_ads_n').appendChild(ifrm);
}



function Get_menu_search()
{

	var randomnumber=Math.floor(Math.random()*1231) ;
 
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		window['xmlhttp' + randomnumber ] =new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		window['xmlhttp' + randomnumber ] =new ActiveXObject("Microsoft.XMLHTTP");
	}
	window['xmlhttp' + randomnumber ].onreadystatechange=function()
	{
		if (window['xmlhttp' + randomnumber ].readyState==4 && window['xmlhttp' + randomnumber ].status==200)
		{
			var menu_data = window['xmlhttp' + randomnumber ].responseText;
			return menu_data ;
		}
	}
   	var url = location.href ;
	window['xmlhttp' + randomnumber ].open("GET", config_site_url + "menu-search.php" ,true);
	window['xmlhttp' + randomnumber ].send();
}

function GotoTabmenu(id)
{

   	var nid = eval(id) + 1 ;
	id = eval(id) ;

	var content = document.getElementById("tab-menu-content-id-" + id ) ;

	if(content){
		content.style.display = 'block' ;
		// Highlighting open tab 
		document.getElementById("tab-menu-id-" + id ).className = "tab_area_active" ;
		document.getElementById("tab_area_corner_img-" + id ).className = "tab_area_corner_active_img" ;
		document.getElementById("tab_area_txt-" + id ).className = "tab_area_txt_active" ;
		document.getElementById("tab_area_corner1_img-" + id ).className = "tab_area_corner1_active_img" ;
	}


	// Remove new menus 
	var d = document.getElementById('tab_main_area');
	var olddiv = document.getElementById("tab-menu-id-" + nid );

	if(olddiv) {
		d.removeChild(olddiv);
		d = document.getElementById('nav_panel_area_with_tab');
		olddiv = document.getElementById("tab-menu-content-id-" + nid );
		d.removeChild(olddiv);
		GotoTabmenu(nid);
	}
}
	
	

function RemoveMenuElement(divid)
{
	var d = document.getElementById('tab_main_area');
	var olddiv = document.getElementById("tab-menu-id-" + divid );
	d.removeChild(olddiv);

	var c = document.getElementById('nav_panel_area_with_tab');
	var cold = document.getElementById('tab-menu-content-id-' + divid );
	c.removeChild(cold);

	var cid = eval(divid);
	cid = cid -1 ;

	document.getElementById('tab-menu-content-id-' + cid ).style.display = 'block';
	// Highlighting open tab 
	document.getElementById("tab-menu-id-" + cid ).className = "tab_area_active" ;
	document.getElementById("tab_area_corner_img-" + cid ).className = "tab_area_corner_active_img" ;
	document.getElementById("tab_area_txt-" + cid ).className = "tab_area_txt_active" ;
	document.getElementById("tab_area_corner1_img-" + cid ).className = "tab_area_corner1_active_img" ;
}

function creat_menu_item(array_menu_id,array_menu_deep,array_menu_name,array_menu_identifire,array_menu_old_or_new,array_menu_url,   menu_id,cid,loadcontent,menu_url)
{	

	//alert(array_menu_old_or_new);
	var randomnumber=Math.floor(Math.random()*1231) ;
	var id=menu_id;
	var depth=cid;
	var loadcontent=loadcontent;
	var pageurl=menu_url;

	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		window['xmlhttp' + randomnumber ]=new XMLHttpRequest();
	}else{
		// code for IE6, IE5
		window['xmlhttp' + randomnumber ]=new ActiveXObject("Microsoft.XMLHTTP");
	}
	window['xmlhttp' + randomnumber ].onreadystatechange=function()
	{
		if (window['xmlhttp' + randomnumber ].readyState==4 && window['xmlhttp' + randomnumber ].status==200)
		{

			var ndepth = eval(depth) + 1 ;
			var cn = document.getElementById('tab-menu-content-id-' + ndepth );
			
			if(cn){
				cn.innerHTML= window['xmlhttp' + randomnumber ].responseText;
			}		
		
			//document.getElementById("tab-menu-content-id-1").innerHTML=window['xmlhttp' + randomnumber ].responseText;
			//blockmoreapps(divid);
			
			
			if(loadcontent == 1 )
			{
				var cn = document.getElementById('directory-product-content' );
				if(cn)
				{
					cn.innerHTML= '<div align="center"><a href="' + pageurl + '"><span style="font-size:16px; font-weight:bold; color:#FF00FF;" >If the page does not load automatically in 5 seconds, please click here</a></span> <br /><div class="loading-busy"></div> </div>' ;
					getdirectory_content(id);
				}
			}

		}
	}

	params="array_menu_id=" + array_menu_id + "&array_menu_deep=" + array_menu_deep + "&array_menu_name=" + array_menu_name + "&array_menu_identifire=" + array_menu_identifire + "&array_menu_old_or_new=" + array_menu_old_or_new + "&array_menu_url=" + array_menu_url + "&menu_id=" + menu_id;

	window['xmlhttp' + randomnumber ].open("POST", config_site_url +  "ajax-creat-menu.php", true);
	window['xmlhttp' + randomnumber ].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	window['xmlhttp' + randomnumber ].setRequestHeader("Content-length", params.length);
	window['xmlhttp' + randomnumber ].setRequestHeader("Connection", "close");
	window['xmlhttp' + randomnumber ].send(params);
}



function display_menu_box(menu_deep,menu_name,menu_id,loadcontent,menu_url)
{

	var randomnumber=Math.floor(Math.random()*1231) ;

	//alert(menu_name);

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		window['xmlhttp' + randomnumber ]=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		window['xmlhttp' + randomnumber ]=new ActiveXObject("Microsoft.XMLHTTP");
	}


	window['xmlhttp' + randomnumber ].open("GET", config_site_url + "get-menu.xml",false);
	window['xmlhttp' + randomnumber ].send();
	xmlDoc=window['xmlhttp' + randomnumber ].responseXML;


	var array_menu_id=new Array();
	var array_menu_deep=new Array();
	var array_menu_name=new Array();
	var array_menu_identifire=new Array();
	var array_menu_old_or_new=new Array();
	var array_menu_url=new Array();
	var count=0;

	main_x=xmlDoc.getElementsByTagName("maincat");
	main_y=xmlDoc.getElementsByTagName("maincat");
	//alert(main_x.length);

	if(menu_deep==0)
	{
		//alert("enter");
		for (h=0;h<main_x.length;h++)
		{
			if(main_x[h].getAttribute('deep')==1)
			{
				count++;
				array_menu_id[count]=main_x[h].getAttribute('id');
				array_menu_deep[count]=main_x[h].getAttribute('deep');
				array_menu_name[count]=main_x[h].getAttribute('name');
				array_menu_identifire[count]=main_x[h].getAttribute('cat_aap_identifire');
				array_menu_old_or_new[count]=main_x[h].getAttribute('old_or_new');
				array_menu_url[count]=main_x[h].getAttribute('url');
			}
		}
	}
	else
	{
		for (h=0;h<main_x.length;h++)
		{
			if(main_x[h].getAttribute('name')==menu_name)
			{
				x=xmlDoc.getElementsByTagName("maincat")[h].childNodes;
				y=xmlDoc.getElementsByTagName("maincat")[h].firstChild;

				for (i=0;i<x.length;i++)
				{
					if (y.nodeType==1)
					{
						count++;
						array_menu_id[count]=y.getAttribute('id');
						array_menu_deep[count]=y.getAttribute('deep');
						array_menu_name[count]=y.getAttribute('name');
						array_menu_identifire[count]=y.getAttribute('cat_aap_identifire');
						array_menu_old_or_new[count]=y.getAttribute('old_or_new');
						array_menu_url[count]=y.getAttribute('url');
						//alert(y.getAttribute('id'));
					}
					y=y.nextSibling;
				}
				break;
			}
		}		
	}



	var id=eval(menu_deep);
	var txt=menu_name;
	var menuid=menu_id;
	var loadcontent=eval(loadcontent);
	var pageurl=menu_url;
	var cid = id;
	var nid = cid +1 ;

	var ni = document.getElementById('tab_main_area');

	if(menu_deep!=0)
	{

		// De - Highlighting previous tab 
		document.getElementById("tab-menu-id-" + cid ).className = "tab_area_normal" ;
		document.getElementById("tab_area_corner_img-" + cid ).className = "tab_area_corner_img" ;
		document.getElementById("tab_area_txt-" + cid ).className = "tab_area_txt" ;
		document.getElementById("tab_area_corner1_img-" + id ).className = "tab_area_corner1_img" ;

		// Add new tab menu
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id','tab-menu-id-'+ nid);

		newdiv.innerHTML = '<div class="tab_area_corner_active_img" id="tab_area_corner_img-' + nid + '"  ></div> ' ;
		newdiv.innerHTML = newdiv.innerHTML + '<div class="tab_area_txt_active" id="tab_area_txt-'+ nid + '" ><a href="JavaScript:void(0);" onclick="GotoTabmenu(\''+ nid + '\')">'+ txt + '</a> </div> ' ;
		newdiv.innerHTML = newdiv.innerHTML + '<div class="tab_area_corner1_active_img"  id="tab_area_corner1_img-'+ nid + '"" ><a href="JavaScript:void(0);" onclick=\'RemoveMenuElement("'+ nid + '");\' ><div class="cross_img"></div></a></div>' ;
		ni.appendChild(newdiv);
		document.getElementById('tab-menu-id-'+ nid ).className = "tab_area_active" ;

		// Add new content area 
		var ni = document.getElementById('nav_panel_area_with_tab');
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id','tab-menu-content-id-'+ nid);
		ni.appendChild(newdiv);
		newdiv.innerHTML = '<div align="center"><a href="' + pageurl + '"><span style="font-size:16px; font-weight:bold; color:#ffffff;" >If the menu does not load automatically in 5 seconds, please click here</a></span> <br /><div class="loading-busy"></div> </div>' ;
		var xid = nid+1 ;
	}

	creat_menu_item(array_menu_id,array_menu_deep,array_menu_name,array_menu_identifire,array_menu_old_or_new,array_menu_url,   menu_id,cid,loadcontent,menu_url);

	if(menu_deep!=0)
	{

	   if(loadcontent ==1 ) 
	   document.getElementById("config_appname_h1").innerHTML = '<a href="'+pageurl+'">' + txt + '</a>' ;
	   
	   document.getElementById('tab-menu-content-id-' + cid ).style.display = 'none' ;		

	}

	return false;
}
