
window.onresize = function(){WindowOnResize();}

function obj(id){return document.getElementById(id);}
function display(id){obj(id).style.display = 'block';}

//triggered by body onload in PermobilMain.master
/**********************************************************/
function BodyOnload()
{
	try{
		RightAlignSearchResultDiv();		
		document.getElementById('top-bar-logo-ie').style.visibility = 'visible';
	}
	catch(e){}
}

//triggered by body onclick in PermobilMain.master
/**********************************************************/
function BodyOnFocus()
{
	try{
		ClearSearch(1);
	}
	catch(e){}
}

/**********************************************************/
function WindowOnResize()
{
	try{
		RightAlignSearchResultDiv();	
	}
	catch(e){}	
}

// these methods handles event triggering in FF, IE, Safari ...
/**********************************************************/
var prev_func = '';

function FireHtmlEvent(objId, eventname){

	try{
		var obj = document.getElementById(objId);
		
		if(obj == null)
			return;
			
		if(document.createEvent){
			try{
				var evt = document.createEvent("HTMLEvents");
				evt.initEvent(eventname, true, true);
				obj.dispatchEvent(evt);			
			}
			catch(e){}
		}
		else
			obj.fireEvent("on" + eventname);
		
		prev_func = '';
	}
	catch(e){}	
}

/**********************************************************/
function setTimeoutEx(func, sleep)
{
	if(func == prev_func)
		return;
		
	prev_func = func;
		
	setTimeout(func, sleep);
}
//----

//right aligning one object to another (at least in theory :), 
//only used to position search result div for now...)
/**********************************************************/
function RightAlign(id, id_relative)
{					
	try{
		var obj = document.getElementById(id);
		var obj_rel = document.getElementById(id_relative);
		
		var offsetW = obj_rel.offsetWidth;
		var offsetL = 0;
		
		while(obj_rel.offsetParent != null){
			offsetL += obj_rel.offsetLeft;
			obj_rel = obj_rel.offsetParent;
		}

		obj.style.left = ((offsetL + offsetW) - obj.offsetWidth) + "px";
	}
	catch(e){}
}

/**********************************************************/
function toggleMenuDiv(id)
{
	try{
		var obj = document.getElementById(id);
		
		if(!obj)
			return false;
			
		obj.className = obj.className == 'menu-div' ? 'menu-div-expanded' : 'menu-div';
		
		return obj.className == 'menu-div-expanded';
	}
	catch(e){}
}

/**********************************************************/
function setItemSelected(id, selected)
{
	try{
		var obj = document.getElementById(id);
		
		if(!obj)
			return false;
			
		obj.className = selected ? 'has-children-expanded' : 'has-children';	
	}
	catch(e){}
}

/**********************************************************/
function hide(obj)
{	
	try{
		if(!obj)
			return;	
			
		if(arguments.length > 1)	
			setTimeout("hide('" + obj.id + "')", arguments[1]);
			
		obj.style.display = 'none';
	}
	catch(e){}
}

//product accessories
/**********************************************************/
function toggleItem(item_id)
{
	var list = document.getElementById('item-area');
	var item = document.getElementById(item_id);
	
	for(var i = 0; i < list.childNodes.length; i++){
		if(list.childNodes[i].id != item_id && list.childNodes[i].className == 'item-selected')
			list.childNodes[i].className = 'item';
	}
	
	item.className = item.className == 'item' ? 'item-selected' : 'item';
}

//ie dropdown menu fix
/********************************************************/
sfHover = function() {
	var menu = document.getElementById("top-menu");
	
	if(menu){		
		var sfEls = menu.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() { this.className+=" sfhover"; }
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); }
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//temp
/********************************************************/
function initMenu() {
	var menu = document.getElementById("top-menu");
	
	if(menu){		
		var sfEls = menu.getElementsByTagName("LI");
		
		for (var i=0; i<sfEls.length; i++) {
			//sfEls[i].onmouseover=function() { var li = this; setTimeout(function() { li.className += " sfhover"; }, 0); }
			//sfEls[i].onmouseout=function() { var li = this; setTimeout(function() { li.className = li.className.replace(new RegExp(" sfhover\\b"), ""); }, 10); }
			sfEls[i].onmouseover=function() { this.className += " sfhover"; }
			sfEls[i].onmouseout=function() { this.className = this.className.replace(new RegExp(" sfhover\\b"), ""); }
		}
	}
}

//flash functionallity
function getFlashObj(movie){
   if (window.document[movie]) {
      return window.document[movie];
   }
   if (navigator.appName.indexOf("Microsoft Internet")==-1) {
	alert("inte ms...");
      if (document.embeds && document.embeds[movie]) {
         return document.embeds[movie]; 
      }
   } else {
      return document.getElementById(movie);
   }
}

function getDimensions(movie) {	
   var movieObj = getFlashObj(movie);  
   var width = movieObj.TGetProperty("/", 8);
   var height= movieObj.TGetProperty("/", 9);
   alert("The current dimensions for the Flash Object ("+movie+") are "+width+" in width and "+height+" in height.");
}

/********************************************************/
function popup(url, target, features) {	
	try {
		var popup = window.open(url, target, features);
		
		if(popup == null)
			return false;

	
		if(window.opera)
			if(!popup.opera)
				return false;
	}
	catch(err) {
		return false;
	}
	
	return true;
}

/********************************************************/
function toggleElement(id) {

        if(document.getElementById(id).className == "elementHidden")
            document.getElementById(id).className = "elementVisible";
        else
            document.getElementById(id).className = "elementHidden";
/**/
    //if(document.getElementById(id).className == 'elementHidden')
    //    document.getElementById(id).style.display = "none";
    //else
       
       //     document.getElementById(id).style.display = "block";
       
}