
function element(id)
{
	return document.getElementById ? document.getElementById(id) : document.all[id];
}

var xmlreq;

function request(id)
{
	xmlreq = false;
	
	try
	{
		xmlreq = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
			xmlreq = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e)
		{
			if (window.XMLHttpRequest)
			{
				xmlreq = new XMLHttpRequest();
			}
		}
	}
	if (xmlreq)
	{
	    
	    xmlreq.onreadystatechange = eval('result');
	    
		xmlreq.open("GET", "../libs/setcookie.php?id=" + id, true);
		xmlreq.send(null);
	}
}

function result()
{
	if (xmlreq.readyState == 4)
	{
		if (xmlreq.status == 200)
		{
			var response = xmlreq.responseXML.documentElement;

			//element('linkfollowerid').innerHTML = '';
			
			for(var n = 0; n < response.getElementsByTagName('items')[0].childNodes.length; n ++)
			{
				var item = response.getElementsByTagName('items')[0].childNodes[n];

				if(item.tagName != undefined)
				{
					var id = item.getElementsByTagName('id')[0].firstChild.data;
					//var title = item.getElementsByTagName('title')[0].firstChild.data;
					var link = item.getElementsByTagName('link')[0].firstChild.data;
					
					//element('linkfollowerid').innerHTML += '<a href="'+ link + '">' + title + '</a> &gt; ';

				}
			}
		
			//setCookie("buttonId", id, "Mon, 01-Jan-2010 00:00:00 GMT", "/");
			
			//createCookie('buttonId',id,false);
			//alert(link);
			document.location=link;

		}
	}
}

function is_array(input)
{
    return typeof(input)=='object'&&(input instanceof Array);
}

function getHeight(){
   if(element('conent_id') == null)
   {
       
   }
   else
   {
       var h = element('conent_id').offsetHeight;
       element('conent_div').style.height = h;
   }
}


function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function open_blank_window(link) //opens new window
{
  newWin = window.open(link,'_blank');
  newWin.focus();
}

function open_window(link,w,h) //opens new window
{
  var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
  newWin = window.open(link,'newWin',win);
  newWin.focus();
}

function setCookie (name, value, expires, path, domain, secure) 
{
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function setCookiez(c_name,value,expiredays,path)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
((path) ? "; path=" + path : "");
}

function getCookie(name) 
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function getCookiez(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function eraseCookie(name)
{
	setCookie(name,"");
}



function close_mods(ids_arr)
{
    var b_type = check_browse_type('gecko');
    
    if(is_array(ids_arr))
    {
        var cout_id = ids_arr.length;
        
        for(i=0;i<cout_id;i++){
            //alert(ids_arr[i]);
            if(typeof element('close_' + ids_arr[i] + '_l') == "object" && element('close_' + ids_arr[i] + '_l')!=null)
            { 
                
                if(b_type == true){
                    var status = getCookie('module_'+ids_arr[i]+ '_l');
                }
                else{
                    var status = getCookiez('module_'+ids_arr[i]+ '_l');
                }
               
                if(status == "")
                {
                    element('close_' + ids_arr[i] + '_l').style.display = "none";
                    element('open_' + ids_arr[i]+ '_l').style.display = "";
                    
                    if(b_type == true){
                        setCookie ('module_'+ids_arr[i]+ '_l', 'close', 365, '/');
                    }
                    else{
                        setCookiez('module_'+ids_arr[i]+ '_l','close',365, '/');
                    }
                }
            }
            
            if(typeof element('close_' + ids_arr[i] + '_r') == "object" && element('close_' + ids_arr[i] + '_r')!=null)
            { 
                //alert(ids_arr[i]);
                if(b_type == true){
                    var status = getCookie ('module_'+ids_arr[i]+ '_r');
                }
                else{
                    var status = getCookiez('module_'+ids_arr[i]+ '_r');
                }
                //alert(status);
                if(status == "" || status ==null)
                {
                    element('close_' + ids_arr[i] + '_r').style.display = "none";
                    element('open_' + ids_arr[i]+ '_r').style.display = "";
                    
                    if(b_type == true){
                        setCookie ('module_'+ids_arr[i]+ '_r', 'close', 365, '/');
                    }
                    else{
                        setCookiez('module_'+ids_arr[i]+ '_r','close',365, '/');
                    }
                }
            } 
        }
        
        getHeight();
    }
    else
    {
        if(typeof element('close_' + ids_arr + '_l') == "object" && element('close_' + ids_arr + '_l')!=null)
        { 
            
            if(b_type == true){
                var status = getCookie('module_'+ids_arr+ '_l');
            }
            else{
                var status = getCookiez('module_'+ids_arr+ '_l');
            }
           
            if(status == "")
            {
                element('close_' + ids_arr + '_l').style.display = "none";
                element('open_' + ids_arr+ '_l').style.display = "";
                
                if(b_type == true){
                    setCookie ('module_'+ids_arr+ '_l', 'close', 365, '/');
                }
                else{
                    setCookiez('module_'+ids_arr+ '_l','close',365, '/');
                }
            }
        }
        
        if(typeof element('close_' + ids_arr + '_r') == "object" && element('close_' + ids_arr + '_r')!=null)
        { 
            //alert(ids_arr[i]);
            if(b_type == true){
                var status = getCookie ('module_'+ids_arr+ '_r');
            }
            else{
                var status = getCookiez('module_'+ids_arr+ '_r');
            }
            //alert(status);
            if(status == "" || status ==null)
            {
                element('close_' + ids_arr + '_r').style.display = "none";
                element('open_' + ids_arr+ '_r').style.display = "";
                
                if(b_type == true){
                    setCookie ('module_'+ids_arr+ '_r', 'close', 365, '/');
                }
                else{
                    setCookiez('module_'+ids_arr+ '_r','close',365, '/');
                }
            }
        }
        
        getHeight(); 
    }
}

function close_mod(id)
{
    element('close_' + id).style.display = "none";
    element('open_' + id).style.display = "";
    
    var b_type = check_browse_type('gecko');
    
    if(b_type == true){
        setCookie ('module_'+id, 'close', 365, '/');
    }
    else{
        setCookiez('module_'+id,'close',365, '/');
    }
    
    getHeight();
    
    return false;
}

function open_mod(id)
{
    element('close_' + id).style.display = "";
    element('open_' + id).style.display = "none";
    
    var b_type = check_browse_type('gecko');
    
    if(b_type == true){
        setCookie ('module_'+id, 'open', 365, '/');
    }
    else{
        setCookiez('module_'+id,'open',365, '/');
    }
    
    getHeight();
    
    return false;
}

function check_browse_type(browse){
    var ua = navigator.userAgent.toLowerCase();
    if(browse == 'ie'){
        isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1);
        return isIE;
    }
    else 
    if (browse == 'safari'){
        isSafari = (ua.indexOf("safari") != -1);
        return isSafari;
    }
    else 
    if (browse == 'gecko'){
        isGecko = (ua.indexOf("gecko") != -1);
        return isGecko;
    }
    else 
    if (browse == 'opera'){
        isOpera = (ua.indexOf("opera") != -1);
        return isOpera;
    }
    else {
        return false;
    }
}

function changelang(lang){
    document.langfrm.change_lang.value = lang;
    document.langfrm.submit();
    return false;
}

function open_menu(id){
    element('close_' + id).style.display = "none";
    element('open_' + id).style.display = "";
    
    var b_type = check_browse_type('gecko');
    
    if(b_type == true){
        setCookie ('admin_menu_'+id, 'open', 365, '/');
    }
    else{
        setCookiez('admin_menu_'+id,'open',365, '/');
    }
    
}

function close_menu(id){
    element('close_' + id).style.display = "";
    element('open_' + id).style.display = "none";
    
    var b_type = check_browse_type('gecko');
    
    if(b_type == true){
        setCookie ('admin_menu_'+id, 'close', 365, '/');
    }
    else{
        setCookiez('admin_menu_'+id,'close',365, '/');
    }
}

function getMenuStatus(id){
    var b_type = check_browse_type('gecko');
    
    if(b_type == true){
        var status = getCookie ('admin_menu_'+id);
    }
    else{
        var status = getCookiez('admin_menu_'+id);
    }
}
