window.onload = function() {
	ie.hover();
}

/* common
--------------------------------------*/

Array.prototype.inArray = function(value) {
	for(var i = 0; i < this.length; i++) {
		if(this[i] === value) {
			return true;
		}
	}
	
	return false;
};

/* is (browser indentification)
--------------------------------------*/

var is = {
    ie: navigator.appName == 'Microsoft Internet Explorer',
    java: navigator.javaEnabled(),
    ns: navigator.appName == 'Netscape',
    ua: navigator.userAgent.toLowerCase(),
    version: parseFloat(navigator.appVersion.substr(21)) || parseFloat(navigator.appVersion),
    win: navigator.platform == 'Win32'
}

is.mac = is.ua.indexOf('mac') >= 0;

if (is.ua.indexOf('opera') >= 0) {
    is.ie = is.ns = false;
    is.opera = true;
}

if (is.ua.indexOf('gecko') >= 0) {
    is.ie = is.ns = false;
    is.gecko = true;
}

/* ie hover
--------------------------------------*/

var ie = {
	hover: function() {
		if(document.all) {
			this.row();
			this.button();
			this.input();
		}
	},
	
	row: function() {
		var e = document.getElementsByClassName('row');
		for(var i = 0; i < e.length; i++) {
			e[i].onmouseover = new Function("this.className = 'row-hover'");
			e[i].onmouseout = new Function("this.className = 'row'");
		}
	},
	
	button: function() {
		var e = document.getElementsByClassName('button');
		for(var i = 0; i < e.length; i++) {
			e[i].onmouseover = new Function("this.className = 'button-hover'");
			e[i].onmouseout = new Function("this.className = 'button'");
		}
	},
	
	input: function() {
		var e = document.getElementsByTagName('input');
		var inputTypes = new Array('text', 'file', 'password');
		for(var i = 0; i < e.length; i++) {
			if(inputTypes.inArray(e[i].getAttribute('type'))) {
				e[i].onfocus = new Function("this.className = 'input-focus'");
				e[i].onblur = new Function("this.className = ''");
			}
		}
		
		e = document.getElementsByTagName('textarea');
		for(var i = 0; i < e.length; i++) {
			e[i].onfocus = new Function("this.className = 'textarea-focus'");
			e[i].onblur = new Function("this.className = ''");
		}
	}
}

/*
--------------------------------------*/
function toggle_description_NEW(id,img1,img2) {
	//alert(id);
	if(is.ie) {
		var d = $('description_' + id);
		d.style.display = d.style.display == 'none' ? 'block' : 'none';
	}
	else {
		eval('moo_height_' + id).toggle();
	}
	
	var a = $('a_description_' + id);
	a.innerHTML = a.innerHTML.indexOf(img1) != -1 ? a.innerHTML.replace(img1, img2) : a.innerHTML.replace(img2, img1);
	return false;
}

function toggle_description(id) {
	//alert(id);
	if(is.ie) {
		var d = $('description_' + id);
		d.style.display = d.style.display == 'none' ? 'block' : 'none';
	}
	else {
		eval('moo_height_' + id).toggle();
	}
	
	var a = $('a_description_' + id);
	//a.innerHTML = a.innerHTML.indexOf('show') != -1 ? a.innerHTML.replace(/show/, 'hide') : a.innerHTML.replace(/hide/, 'show');
	a.innerHTML = a.innerHTML.indexOf('configure_open') != -1 ? a.innerHTML.replace(/configure_open/, 'configure_closed') : a.innerHTML.replace(/configure_closed/, 'configure_open');
	return false;
}

/* ajax
   note: we should move to moo.ajax
--------------------------------------*/

var ajax2 = null;

function ajax_init() {
	var a = false;
    
	//branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			a = new XMLHttpRequest();
        }
		catch(e) {
			a = false;
        }
    }
	//branch for IE/Windows ActiveX version
	else if(window.ActiveXObject) {
       	try {
        	a = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		a = new ActiveXObject("Microsoft.XMLHTTP");
        	}
			catch(e) {
          		a = false;
        	}
		}
    }
	
	return a;
}

/*ajax submit*/
/* ajax submit */
function myFunction(request){
	//alert (request.responseText);
}
function ajaxsubmit(page,postval,element){
	//alert(page+', '+postval+', '+element);
	new ajax(page, {postBody: postval, update: $(element), onComplete: myFunction});
}