function $(v){return document.getElementById(v);};

function init(){
	var list = document.getElementsByTagName("input");
	for(var i =0;i<list.length;i++){
		if(list[i].type == "text"){
			if(list[i].alt == "pass"){
				list[i].onfocus = function(){style_changer(this,'password');}
			}else{
				list[i].onfocus = function(){style_changer(this,'text');}
			}
			list[i].onblur = function(){style_reseter(this);};
		}
	}
	for(var i =0;i<onloadList.length;i++){
		eval(onloadList[i]);
	}
}

var onloadList = [];

function add_onload(func){
	if(func){
		onloadList.push(func);
	}
}

function whichElement(e){
    var targ;
    if (!e){
        var e = window.event;
    }
    if (e.target){
        targ=e.target;
    }else if (e.srcElement){
        targ=e.srcElement;
    }
    if (targ.nodeType==3){
        targ = targ.parentNode;
    }
    if(targ.altType == 1){
        targ.blur();
        return false;
    }
    return targ;
}
function style_changer(obj,type){
	if(obj.className.indexOf('input_text') !== -1){
		obj.className = obj.className.replace('input_text','');
		obj._value = obj.value;
		obj._type = obj.type;
		obj.value = "";
		obj.alt = "";
		obj.type = type;
	}
}
function style_reseter(obj){
	if(!obj.value.length){
		if(obj._value){
			obj.className += ' input_text';
			obj.type = obj._type;
			obj.value = obj._value;
		}
	}	
}
function reload_captcha(id){
	var capt = $(id);
	if(capt){
		capt.src = capt.src.replace(/rand\=\d+/,'rand='+(parseInt(Math.random()*10000000)));
	}
}

function form_submit(form_name,action){
	var form = document.forms[form_name];
	for(var i=0;i<form.elements.length;i++){
		var elem = form.elements[i];
		if(elem.className.indexOf('input_text') !== -1){
			elem.value = "";
		}
	}
	if(!action)
		action = location;
	form.action = action;
	setTimeout(function(){form.submit();},1);
}


_ERROR_DIV = null;

function show_error(text){
	if(!_ERROR_DIV){
		_ERROR_DIV = $('_ERROR_DIV');
		var iH = '<table align="center" cellspacing="0" cellpadding="0" style="background-color :#6292bb;" width="">';
		iH += '<tr><td style="">';
		iH += '<div style="width:9px; font-size:0; height:9px; float: left; background: url(img/corner2.png) top left no-repeat"></div>';
		iH += '<div style="width:9px; font-size:0; height:9px; float: right; background: url(img/corner2.png) top right no-repeat"></div>';
		iH += '</td></tr><tr><td style="padding:6px;">';
		iH += '<table cellspacing="6"><tr><td class="big_text" style="padding-left:5px;color:#680000;font-size:12px;" id="_ERROR_BODY"></td>';
		iH += '</tr></table></td></tr><tr><td>';
		iH += '<div style="width:9px; font-size:0; height:9px; float: left; background: url(img/corner2.png) bottom left no-repeat"></div>';
		iH += '<div style="width:9px; font-size:0; height:9px; float: right; background: url(img/corner2.png) bottom right no-repeat"></div>';
		iH += '</td></tr></table>';
		iH += '<div style="font-size:0;position:absolute;top:6px;right:6px;width:10px;height:10px;background: url(img/x.png)"><a href="javascript:hide_error();" style="display:block;width:10px;height:10px;"></a></div>';
		_ERROR_DIV.innerHTML = iH;
		_ERROR_DIV.BODY = $('_ERROR_BODY');
	}
	_ERROR_DIV.BODY.innerHTML = text;
}
function hide_error(){
	if(_ERROR_DIV)
		_ERROR_DIV.style.display= "none";
}

function add_option(sel,opt){
	try{
		sel.add(opt,null);
	}catch(ex){
		sel.add(opt);
	}
}
function create_option(value,text){
	var opt = document.createElement("option");
	if(value){
		opt.value = value;
	}
	opt.text = text;
	return opt;
}

function td_over(td){
	td.style.backgroundColor = "#DCFFE2";
}
function td_out(td){
	td.style.backgroundColor = "#BAC7E2";
}
function td_click(td,id){
	if(!$(id))
		return;
	if(!td.clicked){
		td.style.backgroundColor = "#0066A0";
		td._onmouseover = td.onmouseover;
		td.onmouseover = null;
		td._onmouseout = td.onmouseout;
		td.onmouseout = null;
		$(id).checked = true;
		td.clicked = true;
	}else{
		td.style.backgroundColor = "#DCFFE2";
		td.onmouseover = td._onmouseover;
		td.onmouseout = td._onmouseout;
		$(id).checked = false;
		td.clicked = false;
	}
}

