if (window != top) top.location.href = location.href;

// Dynamic Resolution
// based on http://particletree.com/features/dynamic-resolution-dependent-layouts

//addEvent() by John Resig
function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

//Run dynamicLayout function when page loads and when it resizes.
//addEvent(window,'load',dynamicLayout);
//addEvent(window,'resize',dynamicLayout);

function dynamicLayout(){
    var browserWidth = getBrowserWidth();

    if (browserWidth<1024){
        changeLayout("small");
    }
}

function changeLayout(description){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
	   if(a.getAttribute("title") == description){a.disabled = false;}
	   else if(a.getAttribute("title") != "default"){a.disabled = true;}
   }
}

function getBrowserWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	} else if (document.body) {
		return document.body.clientWidth;
	}
	return 0;
}

function javaconfirm(text,ok) {
	var x=window.confirm(text)
	if (x) window.location=ok
}

function fieldset_hide(box,id) {
	if (box.checked) {
		document.getElementById(id).style.visibility = "visible";
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(id).style.display = "none";
	}
}

function hide_elements() {
	for(id in elements) {
		document.getElementById(elements[id]).style.visibility = "hidden";
		document.getElementById(elements[id]).style.display = "none";
	}
}

function show_element(id) {
	document.getElementById(elements[id]).style.visibility = "visible";
	document.getElementById(elements[id]).style.display = "block";
}

function test_type(id) {
	hide_elements();
	if (document.getElementById(id).value == "") return;
	index = "edit[extra_" + document.getElementById(id).value + "]";
	if (document.getElementById(index)) {
		if (document.getElementById(index).value == "") return;
		var str = document.getElementById(index).value;
		ar = str.split("|");
		for (i=0;i<ar.length;i++) show_element(i);
		document.getElementById("extra_label").innerHTML = ar[0];
	}
}

