// fieldset.js
function expandFieldset( id ) {
	document.getElementById( 'fbody_'+id ).style.display = "block";
	document.getElementById( 'expand_imglink_'+id ).style.display = "none";
	document.getElementById( 'collapse_imglink_'+id ).style.display = "inline";
	document.getElementById( 'expand_textlink_'+id ).style.display = "none";
	document.getElementById( 'collapse_textlink_'+id ).style.display = "inline";
	//document.getElementById( 'collapse_right_'+id ).style.display = "none";
}
function collapseFieldset( id ) {
	document.getElementById( 'fbody_'+id ).style.display = "none";
	document.getElementById( 'expand_imglink_'+id ).style.display = "inline";
	document.getElementById( 'collapse_imglink_'+id ).style.display = "none";
	document.getElementById( 'expand_textlink_'+id ).style.display = "inline";
	document.getElementById( 'collapse_textlink_'+id ).style.display = "none";
	//document.getElementById( 'collapse_right_'+id ).style.display = "inline";
}
function expandOnlyOneFieldset( id, count_fieldset ) {
	for (var i = 1; i <= count_fieldset; i++){
		if (document.getElementById('fbody_'+i)){		
			if (i == id){
				expandFieldset(i);
			} else {
				collapseFieldset(i);
			}
		}
	}
}
function goToSelectedUrl(){
	var select = document.forms['site_control'].elements['url'];
	var selectedValue = select.options[select.options.selectedIndex].value;
	if (selectedValue != 'null'){
		location.href = selectedValue;
	}
	
}

// basefunctions.js

//gives you float number with IE version or 0 if not IE
function getIEVersion(){
    var result = 0;
    if(navigator.appName == 'Microsoft Internet Explorer'){
        var nav = navigator.userAgent;
        var reg  = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
        if( reg.exec(nav)!=null ){
            result = parseFloat( RegExp.$1 );
        }
    }
    return result;
}

//this function is called when the page is loaded
function Page_Loaded()
{
    //CR1857:Firefox bug 
    SetStyleOverFlow("auto");
}

//fix dissapearing cursor by adding overflow to all edit_table_field divs
function SetStyleOverFlow( value )
{ 
	if(navigator.userAgent.indexOf("Firefox")!=-1){
		var divs=document.getElementsByTagName('div'); 
		/*
		for (var i=0;i<divs.length;i++)
		{
	   		var pos =  divs[i].id.indexOf("edit_table_field");
			if (pos>=0 ) 	
	        {
	           divs[i].style.overflow  = value;
	   		}
	   	}
	   	
	   	*/
	   	/* CR 2616 - Seems the above JS broke the tabbing functionality of fields, so
	   	I have hardcoded the problem fields in the listings page, so it only affects those.
	   	This limits the number of fields where tab doesn't work.*/ 
	   	if (document.getElementById('edit_table_field_7'))
	   	{
	   		document.getElementById('edit_table_field_6').style.overflow=value;
	    	document.getElementById('edit_table_field_7').style.overflow=value;
	   }
	}	
}

//gives you css class name based on browser
function getCssClassName( elem ){
	if( elem ){
        if( getIEVersion() >= 6.0 ){   
            //IE6 did not work with getAttribute so i added this if - i guess this way does not work in other 
            //browsers so i did not replace just made if for IE6 so i would not break other stuff
            return elem.className;
        }else{
            return elem.getAttribute( 'class' );
        }
	}else{
		return null;
	}
}