// Declarations
var acturl = "/act.php";
var tb_search;
var btn_search;
var tb_quick_username;
var tb_quick_password;
var btn_quick_login;
var lnk_quick_login;
var frm_quick_login;

function baseinit()
{
	var body_width = 1000 / 1024 * screen.width;
	var font_size = screen.height / 768 * 14;
	document.body.style.fontSize = font_size + 'px';
	//document.body.style.width = body_width + 'px';
	//document.body.style.marginLeft = "-" + (body_width / 2) + "px";

	tb_search = get_elem("tb_search");
	btn_search = get_elem("btn_search");
	tb_quick_username = get_elem("tb_quick_username");
	tb_quick_password = get_elem("tb_quick_password");
	btn_quick_login = get_elem("btn_quick_login");
	lnk_quick_login = get_elem("lnk_quick_login");
	frm_quick_login = get_elem("frm_quick_login");
	
	if(tb_search != null)
	{
		add_handler(tb_search, "keyup", validate_search_submission);
		add_handler(tb_search, "change", validate_search_submission);
		
		add_handler(tb_search, "focus", search_textbox_focus);
		add_handler(tb_search, "blur", search_textbox_blur);
		add_handler(tb_search, "blur", validate_search_submission);
	}
	
	if(tb_quick_username != null)
	{
		add_handler(tb_quick_username, "focus", search_textbox_focus);
		add_handler(tb_quick_username, "blur", search_textbox_blur);
		add_handler(tb_quick_username, "blur", validate_quick_login);

		add_handler(tb_quick_username, "keyup", validate_quick_login);
		add_handler(tb_quick_username, "change", validate_quick_login);

		add_handler(tb_quick_password, "keyup", validate_quick_login);
		add_handler(tb_quick_password, "change", validate_quick_login);
	}
	
	init_textboxes();
	if(typeof init_shoutbox != "undefined")
		init_shoutbox();
		
	correctPNG();
}

function init_textboxes()
{
	var tbs = get_elems(document, "input");
	for(var i = 0; i < tbs.length; i++)
	{
		if(tbs[i].type == "text" && tbs[i].alt != "")
		{
			tbs[i].value = tbs[i].alt;
			tbs[i].style.color = "#aaa";
		}
		
		if(tbs[i].className == "textbox")
		{
			add_handler(tbs[i], "focus", textbox_focus);
			add_handler(tbs[i], "blur", textbox_blur);
		}
	}
	
	var tas = get_elems(document, "textarea");
	for(var i = 0; i < tas.length; i++)
	{
		if(tas[i].className == "textbox")
		{
			add_handler(tas[i], "focus", textbox_focus);
			add_handler(tas[i], "blur", textbox_blur);
		}
		
		if(tas[i].getAttribute("maxlength"))
		{
			add_handler(tas[i], "change", textarea_length_check);
			add_handler(tas[i], "keyup", textarea_length_check);
		}
	}
}

function textarea_length_check(e)
{
	var ta = get_sender(e);
	var maxlength = ta.getAttribute("maxlength");
	if(ta.value.length > maxlength)
	{
		ta.value = ta.value.substr(0, maxlength);
	}
}

function textbox_focus(e)
{
	var tb = get_sender(e);
	tb.className = "textbox_selected";
}

function textbox_blur(e)
{
	var tb = get_sender(e);
	tb.className = "textbox";
}

function toggle_quick_login_form()
{
	if(lnk_quick_login.innerHTML == "Log In")
	{
		frm_quick_login.style.display = "block";
		lnk_quick_login.innerHTML = "Close Login";
	}
	else
	{
		frm_quick_login.style.display = "";
		lnk_quick_login.innerHTML = "Log In";
	}
}


function validate_search_submission(e)
{
	if(is_textbox_empty(tb_search))
		disable_button(btn_search);
	else
		enable_button(btn_search);
}

function validate_quick_login(e)
{
	if(is_textbox_empty(tb_quick_username) || is_textbox_empty(tb_quick_password) || tb_quick_username.value.length < 3 || tb_quick_password.value.length < 6)
		disable_button(btn_quick_login);
	else
		enable_button(btn_quick_login);
}

function search_textbox_focus(e)
{
	var tb = get_sender(e);
	if(tb.value == tb.alt)
	{
		tb.value = "";
		tb.style.color = "#000";
	}
}

function search_textbox_blur(e)
{
	var tb = get_sender(e);
	if(tb.value == "" || tb.value == tb.alt)
	{
		tb.value = tb.alt;
		tb.style.color = "#aaa";
	}
}

// Common Functions
function get_elem(id)
{
	return document.getElementById(id);
}

function get_elems(obj, tagname)
{
	return obj.getElementsByTagName(tagname);
}


function add_handler(obj, e, func)
{
    if(obj.addEventListener)
    {
        obj.addEventListener(e, func, false);
    }
    else
    {
        obj.attachEvent("on" + e, func);
    }
}

function get_sender(e)
{
    var event = e || window.event;
    var target = event.target || event.srcElement;
    return target;
}

function enable_button(but)
{
	but.disabled = false;
	if(but.className.substr(but.className.length - 9) == "_disabled")
		but.className = but.className.substr(0, but.className.length - 9);
}

function disable_button(but)
{
	but.disabled = true;
	if(but.className.substr(but.className.length - 9) != "_disabled")
		but.className += "_disabled";
}

function disable_field(field)
{
	field.disabled = true;	
}

function enable_field(field)
{
	field.disabled = false;
}

function is_textbox_empty(tb)
{
	return (tb.value == "" || tb.value == tb.alt);
}

function is_email_valid(email)
{
	return email.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
}

function overlay()
{
	el = document.getElementById("div_overlay");
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function getKey(e)
{
	var keyNum;
	
	if(window.event) // IE
		keyNum = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		keyNum = e.which;

	return keyNum;
}

function load_xml(text)
{
    if(typeof DOMParser != "undefined")
	{
        // Mozilla, Firefox, and related browsers
        return(new DOMParser()).parseFromString(text, "application/xml");
    }
    else if(typeof ActiveXObject != "undefined")
	{
        // Internet Explorer.
        var doc = new ActiveXObject("MSXML2.DOMDocument");  // Create an empty document
        doc.loadXML(text);              //  Parse text into it
        return doc;                     // Return it
    }
    else
	{
        // As a last resort, try loading the document from a data: URL
        // This is supposed to work in Safari. Thanks to Manos Batsis and
        // his Sarissa library (sarissa.sourceforge.net) for this technique.
        var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
        var request = new XMLHttpRequest();
        request.open("GET", url, false);
        request.send(null);
        return request.responseXML;
    }
}

function getReference(property)
{  
	return function()
	{  
		return window[property];  
	}  
}  


function get_safe_name(name)
{
	return name.toLowerCase().replace(/\s/g, "_");
}

function serialize(obj)
{
	//alert("Serializing for Object " + obj);
	var output = "";
	if(typeof(obj) == 'object')
	{
		if (obj instanceof Array)
		{
			output = 'a:';
			
            var tmp = '';
            var count = 0;
            for(var i = 0; i < obj.length; i++)
			{
				tmp += 'i:' + i + ';';
                tmp += serialize(obj[i]);
                count++;
            }
            output += count + ':{';
            output += tmp;
            output += '}';
		}
		else
		{
			output = 'O:8:"stdClass":';
			
			var tmp = '';
			var count = 0;
			for(var key in obj)
			{
				tmp += serialize(key);
				tmp += serialize(obj[key]);
				count++;
			}
			
			output += count + ':{';
			output += tmp;
			output += '}';
		}
	}
	else
	{
		// Not an Object
		switch(typeof(obj))
		{
			case 'number':
                if (obj - Math.floor(obj) != 0)
				{
                    output += 'd:' + obj + ';';
                }
				else
				{
                    output += 'i:' + obj + ';';
                }
			
				break;
				
			case 'string':
				output += 's:' + obj.length + ':"' + obj + '";';
				break;
				
			case 'boolean':
				if (obj)
				{
                    output += 'b:1;';
                } else {
                    output += 'b:0;';
                }
				break;
		}
	}
	//alert(output);
	return output;
}

function unserialize(text)
{
	var debug = false;

	if(debug) alert("Unserialize \n" + text);
	var fchar = text.substr(0, 1);
	switch(fchar)
	{
		case 'i':
			var temp = text.substr(2);
			temp = temp.split(";")[0];
			return parseInt(temp);
			
		case 'd':
			var temp = text.substr(2);
			temp = temp.split(";")[0];
			return parseFloat(temp);
			
		case 's':
			var len = text.split(":")[1];
			if(debug) alert("String Size = " + len);
			var start = text.indexOf(':"');
			var temp = text.substr(start + 2, len);
			return temp;
		
		case 'b':
			var state = parseInt(text.substr(2, 1));
			if(state == 1)
				return true;
			else
				return false;
				
		case 'a':
			
			var len = text.split(":")[1];
			if(debug) alert("This is an array of size " + len);
			var temp = text.substr(5);
			temp = temp.substr(0, temp.length - 1);
			var a = new Array();
			var index = 0;
			for(var i = 0; i < temp.length; i++)
			{
				var curchar = temp.substr(i, 1);
				if(curchar == 'i')
				{
					index = temp.substr(i + 2);
					index = index.split(";")[0];
//					if(index == 9)	debug = true;
					if(index == 11)	debug = false;
					//alert("Searching for index " + index);
					var bcnt = 0;		// { count
					var skiploop = false;
					for(var j = i + String(index).length + 3; j < temp.length; j++)
					{
						var curchar2 = temp.substr(j, 1);
						switch (curchar2)
						{
							case '{':
								bcnt++;
								break;
								
							case '}':
								bcnt--;
								if(bcnt == 0)
								{
									var st = 3 + String(index).length;
									var temp2 = temp.substr(i + st , j - (i + st) + 1);
									
									//alert("Element seems to be " + temp2);
									a[index] = unserialize(temp2);
									//alert("Actual Element " + a[index]);
									i = j;
									skiploop = true;
									break;
								}
								break;
								
							case ';':
								if(bcnt == 0)
								{
									var st = 3 + String(index).length;
									var temp2 = temp.substr(i + st , j - (i + st) + 1);
									
//									alert(temp2 + "\n" + (j - (i + st) + 1) + "\n" + j);
									
									//alert("Element seems to be " + temp2);
									a[index] = unserialize(temp2);
									//alert("Actual Element " + a[index]);
									i = j;

									skiploop = true;
									break;
								}
								break;
						}
						if(skiploop == true)
							break;
					}
				}
			}
			return a;
	}
}

function reset_field(field)
{
	switch(field.tagName.toLowerCase())
	{
		case "textarea":
		case "input":
			field.value = "";
			break;
			
		case "select":
			if(field.multiple)
			{
				for(var i = 0; i < field.options.length; i++)
					field.options[i].selected = false;
			}
			else
				field.value = "";
			break;
	}
}

function get_combo_box_text(cbb, value)
{
	for(var i = 0; i < cbb.options.length; i++)
	{
		if(cbb.options[i].value == value)
			return cbb.options[i].innerHTML;
			
	}
	
	return null;
}

function get_combo_box_value(cbb, text)
{
	for(var i = 0; i < cbb.options.length; i++)
	{
		if(cbb.options[i].innerHTML == text)
			return cbb.options[i].value;
			
	}
	
	return null;
}

function is_float(number)
{
	return number.match(/^([0-9]|\.)+$/) != null;
}

function is_integer(number)
{
	return number.match(/^([0-9])+$/) != null;
}




// Date Validation
// ---------------------------------

function is_date_valid(str_date, date_style)
{
	//var date_style = "US"; //United States date style
	//var date_style = "EU";  //European date style
	date_style = date_style.toLowerCase();
	
	var str_date;
	var str_dateArray;
	var str_day;
	var str_month;
	var str_year;
	var day;
	var month;
	var year;
	var booFound = false;
	var str_separator_array = new Array("-"," ", "/", ".");
	var int_element_nr;
	var err = 0;
	var str_month_array = new Array(12);
	str_month_array[0] = "Jan";
	str_month_array[1] = "Feb";
	str_month_array[2] = "Mar";
	str_month_array[3] = "Apr";
	str_month_array[4] = "May";
	str_month_array[5] = "Jun";
	str_month_array[6] = "Jul";
	str_month_array[7] = "Aug";
	str_month_array[8] = "Sep";
	str_month_array[9] = "Oct";
	str_month_array[10] = "Nov";
	str_month_array[11] = "Dec";

	if(str_date.length < 1)
	{
		return false;
	}
	for(int_element_nr = 0; int_element_nr < str_separator_array.length; int_element_nr++)
	{
		if(str_date.indexOf(str_separator_array[int_element_nr]) != -1)
		{
			str_dateArray = str_date.split(str_separator_array[int_element_nr]);
			if(str_dateArray.length != 3)
			{
				err = 1;
				return false;
			}
			else
			{
				str_day = str_dateArray[0];
				str_month = str_dateArray[1];
				str_year = str_dateArray[2];
			}
			booFound = true;
 		}
	}
	if(booFound == false)
	{
		return false;
	}
	
	// US style
	switch(date_style)
	{
		case "us":
			str_temp = str_day;
			str_day = str_month;
			str_month = str_temp;
			break;
		
		case "mysql":
			str_temp = str_day;
			str_day = str_year;
			str_year = str_temp;
			break;
	}
	
	if(str_year.length == 2)
	{
		str_year = '20' + str_year;
	}
	
	day = parseInt(str_day, 10);
	if(isNaN(day))
	{
		err = 2;
		return false;
	}
	
	month = parseInt(str_month, 10);
	if(isNaN(month))
	{
		for(i = 0; i < 12; i++)
		{
			if(str_month.toUpperCase() == str_month_array[i].toUpperCase())
			{
				month = i+1;
				str_month = str_month_array[i];
				i = 12;
			}
		}
		if(isNaN(month))
		{
			err = 3;
			return false;
		}
	}
	
	year = parseInt(str_year, 10);
	if(isNaN(year))
	{
		err = 4;
		return false;
	}
	if(month > 12 || month < 1)
	{
		err = 5;
		return false;
	}
	if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 31 || day < 1))
	{
		err = 6;
		return false;
	}
	if((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30 || day < 1))
	{
		err = 7;
		return false;
	}
	if(month == 2)
	{
		if(day < 1)
		{
			err = 8;
			return false;
		}
		if(is_leap_year(year) == true)
		{
			if(day > 29)
			{
				err = 9;
				return false;
			}
		}
		else
		{
			if(day > 28)
			{
				err = 10;
				return false;
			}
		}
	}
	
	return true;
}

function is_leap_year(year)
{
	if(year % 100 == 0)
	{
		if(year % 400 == 0)
		{
			return true;
		}
	}
	else
	{
		if((year % 4) == 0)
		{
			return true;
		}
	}
	return false;
}

function convert_breaks_to_newlines(text)
{
	return text.replace(/<\/?\s*br>/ig, "\r\n");
}

function convert_newlines_to_breaks(text)
{
	return text.replace("\r\n", "</br>").replace("\n", "</br>");
}

function set_cookie(name, value, expires, path, domain, secure)
{
	document.cookie= name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

function get_cookie(name)
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
	{
		begin = dc.indexOf(prefix);
		if(begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if(end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function delete_cookie(name, path, domain)
{
	if(get_cookie(name))
	{
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function sort_object(arr, keys, reverse_sort)
{
	for(var i = 0; i < arr.length - 1; i++)
	{
		for(var j = i + 1; j < arr.length; j++)
		{
			for(var k = 0; k < keys.length; k++)
			{
				var key = keys[k];
				if(reverse_sort)
				{
					if(arr[i][key] < arr[j][key])
					{
						var temp = arr[i];
						arr[i] = arr[j];
						arr[j] = temp;
						break;
					}
					else if(arr[i][key] > arr[j][key])
					{
						break;
					}
				}
				else
				{
					if(arr[i][key] > arr[j][key])
					{
						temp = arr[i];
						arr[i] = arr[j];
						arr[j] = temp;
						break;
					}
					else if(arr[i][key] < arr[j][key])
					{
						break;
					}						
				}
			}
		}
	}
}

function get_host_from_url(url)
{
	var start = url.indexOf("http://");
	if(start != -1)
	{
		var endPoint = url.indexOf( "/", start + 7);
		if(endPoint != -1)
		{
			return url.substr(start + 7, endPoint - start - 7);
		}
		else
		{
			return url.substr(start + 7)
		}
	}
	else
	{
		return '';
	}
}

function format_time(seconds)
{
	var hrs;
	var mins;
	var secs;
	
	hrs = Math.floor(seconds / 3600);
	seconds = seconds - hrs * 3600;
	mins = Math.floor(seconds / 60);
	seconds = seconds - mins * 60;
	secs = seconds;
	
	if(hrs > 0)
	{
		if(mins < 10)
			mins = "0" + mins;
		if(secs < 10)
			secs = "0" + secs;
	}
	else if(mins > 0 && secs < 10)
			secs = "0" + secs;
	
	if(hrs > 0)
		return hrs + ":" + mins + ":" + secs;
	else
		if(mins > 0)
			return mins + ":" + secs;
		else
			if(secs > 1)
				return secs + " seconds";
			else if(secs == 1)
				return secs + " second";
			else
				return "---";
}

function format_file_size(bytes)
{
	var size = "0 bytes";
	if(bytes < 1024)
		size = bytes + " bytes";
	else if (bytes < 1024 * 1024)
	{
		var num = bytes / 1024;
		size =  num.toFixed(0) + " KB";
	}
	else if (bytes < 1024 * 1024 * 1024)
	{
		var num = bytes / 1024 / 1024;
		size = num.toFixed(2) + " MB";
	}
	return size;
}

function str_rep_count(text, what)
{
	var count = 0;
	var pos = 0;
	do
	{
		var val = text.indexOf(what, pos);
		if(val != -1)
		{
			count++;
			pos = val + what.length;
		}
	}while(val != -1);
	return count;
}

function get_xml(doc)
{
	if(doc.xml)
		return doc.xml;
	else
	{
		var serializer = new XMLSerializer();
		var xml = serializer.serializeToString(doc);
		return xml;
	}
}

function create_new_xml_doc(rootTagName, namespaceURL)
{
    if (!rootTagName) rootTagName = "";
    if (!namespaceURL) namespaceURL = "";

    if (document.implementation && document.implementation.createDocument) {
        // This is the W3C standard way to do it
        return document.implementation.createDocument(namespaceURL, 
                       rootTagName, null);
    }
    else { // This is the IE way to do it
        // Create an empty document as an ActiveX object
        // If there is no root element, this is all we have to do
        var doc = new ActiveXObject("MSXML2.DOMDocument"); 

        // If there is a root tag, initialize the document
        if (rootTagName) {
            // Look for a namespace prefix 
            var prefix = "";
            var tagname = rootTagName;
            var p = rootTagName.indexOf(':');
            if (p != -1) {
                prefix = rootTagName.substring(0, p);
                tagname = rootTagName.substring(p+1);
            } 

            // If we have a namespace, we must have a namespace prefix
            // If we don't have a namespace, we discard any prefix
            if (namespaceURL) { 
                if (!prefix) prefix = "a0"; // What Firefox uses
            }
            else prefix = ""; 
						
						prefix = "";

            // Create the root element (with optional namespace) as a
            // string of text
            var text = "<" + (prefix?(prefix+":"):"") + tagname +
                (namespaceURL
                 ?(" xmlns:" + prefix + '="' + namespaceURL +'"')
                 :"") +
                "/>";
            // And parse that text into the empty document
            doc.loadXML(text);
        }
        return doc;
    }
}; 

function process_ajax_response(t)
{
	var doc = load_xml(t.responseText);
	var root = doc.getElementsByTagName("ajax_response")[0];
	if(root == null)
	{
		var ret = new Object();
		ret.success = false;
		ret.root = t.responseText;
		return ret;
	}
		
	var success = root.getAttribute("success") == "true" ? true : false;
	
	var ret = new Object();
	ret.root = root;
	ret.success = success;
	
	return ret;
}

function show_ajax_success(root)
{
	alert(get_ajax_success(root));
}

function show_ajax_error(root)
{
	if(typeof root == "string")
	{
		alert(root);
	}
	else
		alert(get_ajax_error(root));
}

function get_ajax_error(root)
{
	var error = root.getElementsByTagName("error")[0];
	var msg = error.getAttribute("msg");
	
	return msg;
}

function get_ajax_success(root)
{
	var msg = root.getAttribute('msg');
	return msg;
}

// Form
// ------
function get_form_field_parent(input)
{
	return input.parentNode.parentNode;
}

function get_form_field_hint_div(input)
{
	var parent = input.parentNode.parentNode;
	var divs = get_elems(parent, 'div');
	if(divs.length < 3)
	{
		var div = document.createElement('div');
		div.className = 'msg';
		parent.appendChild(div);
		return div;
	}
	else
		return divs[2];
}

function set_form_field_hint(input, hint)
{
	get_form_field_parent(input).className = 'hint';
	get_form_field_hint_div(input).innerHTML = hint;
}

function set_form_field_error(input, msg)
{
	get_form_field_parent(input).className = 'error';
	get_form_field_hint_div(input).innerHTML = msg;
}

function set_form_field_correct(input)
{
	get_form_field_parent(input).className = 'correct';
	get_form_field_hint_div(input).innerHTML = '';
}

function set_form_field_working(input)
{
	get_form_field_parent(input).className = 'working';
	get_form_field_hint_div(input).innerHTML = '';
}

function clear_form_field_hint(input)
{
	get_form_field_parent(input).className = 'field';
	get_form_field_hint_div(input).innerHTML ='';
}

function is_field_valid(input)
{
	var parent = get_form_field_parent(input);
	return parent.className == 'correct';
}

function is_field_virgin(input)
{
	var parent = get_form_field_parent(input);
	return parent.className == 'field';
}
// ------






var expand_info;

function start_expand(target, callback, speed)
{
		if(expand_info == null)
			expand_info = new Array();
			
		if(speed == null)
			speed = 2;
			
		var obj = new Object();
		obj.id = expand_info.length;
		expand_info[obj.id] = obj;
		obj.done = false;
		
		obj.target = target;
		obj.callback = callback;
		obj.speed = speed;
		
		target.style.display = "";
		target.style.overflow = "hidden";

		obj.max_height = target.offsetHeight;

		target.style.height = "0px";

		setTimeout("expand_div(" + obj.id + ");", 1);
}

function expand_div(id)
{
	var obj = expand_info[id];
	if(obj.target.offsetHeight < obj.max_height)
	{
		obj.target.style.height = Math.min(obj.target.offsetHeight + obj.speed, obj.max_height) + "px";
		setTimeout("expand_div(" + obj.id + ");", 1);
	}
	else
	{
		obj.done = true;
		obj.target.style.height = "";
		
		for(var i = 0; i < expand_info.length; i++)
		{
			if(!expand_info[i].done)
			{
				break;
			}
		}
		
		if(i == expand_info.length)
			expand_info.length = 0;
			
		if(obj.callback != null)
			obj.callback(obj.target);
	}
}

var collapse_info;

function start_collapse(target, callback, speed)
{
		if(collapse_info == null)
			collapse_info = new Array();
			
		if(speed == null)
			speed = 2;
			
		var obj = new Object();
		obj.id = collapse_info.length;
		collapse_info[obj.id] = obj;
		obj.done = false;
		
		obj.target = target;
		obj.callback = callback;
		obj.speed = speed;
		
		obj.target.style.overflow = "hidden";
		
		setTimeout("collapse_div(" + obj.id + ");", 1);
}

function collapse_div(id)
{
	var obj = collapse_info[id];
	if(obj.target.offsetHeight > 0)
	{
		obj.target.style.height = Math.max(obj.target.offsetHeight - obj.speed, 0) + "px";
		setTimeout("collapse_div(" + obj.id + ");", 1);
	}
	else
	{
		obj.done = true;
		obj.target.style.display = "none";
		obj.target.style.height = "";
		
		for(var i = 0; i < collapse_info.length; i++)
		{
			if(!collapse_info[i].done)
			{
				break;
			}
		}
		
		if(i == collapse_info.length)
			collapse_info.length = 0;
			
		if(obj.callback != null)
			obj.callback(obj.target);
	}
}


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function get_elems_by_class(div, className)
{
	var ret = Array();
	for(var i = 0; i < div.childNodes.length; i++)
	{
		if(div.childNodes[i].className == className)
		{
			ret[ret.length] = div.childNodes[i];
		}
	}
	return ret;
}

function get_elem_by_class(div, className)
{
	for(var i = 0; i < div.childNodes.length; i++)
	{
		if(div.childNodes[i].className == className)
		{
			return div.childNodes[i];
		}
	}
	return null;
}

function create_link(text, href, onclick, title)
{
    var a = document.createElement("a");
    a.href = href;
    add_handler(a, "click", onclick);
    a.innerHTML = text;

    if (title != undefined)
        a.title = undefined;

    return a;
}
