var fs; //fullscreen

function _(_id){
    if(document.getElementById && document.getElementById(_id)) return document.getElementById(_id);
    else return null;
}


function addEvent(parent, ev, func){
    if (parent.attachEvent) parent.attachEvent('on'+ev, func);
    else parent.addEventListener(ev, func, true);
}


function init_mail(id) {
	var obj=document.getElementById(id);
	var mail=obj.lang+"@"+obj.href.replace(/http:\/\/([^\/]*)\/?/, "$1");
	obj.href="mailto:"+mail;
	if(obj.innerHTML == '') obj.innerHTML=mail;
	//if(!obj.getElementsByTagName("*")[0]) obj.innerHTML=mail;
};

var email_pattern=/^([A-Za-z0-9\-._]+)@([A-Za-z0-9\-._]+)\.([A-Za-z0-9]{2,3})$/;

function check_form(form){
    req=form.getElementsByTagName("*");
    for(i=0;i<req.length;i++){
        if(req[i].lang!="require") continue;
        req[i].focus();
        if(req[i].value=="" || req[i].value==req[i].def_value){
            alert("Mandatory fields are empty!");
            return false;
        }
        if(req[i].name=="email" && !email_pattern.test(req[i].value)){
            alert("Email is not valid!");
            return false;
        }
    }
    form.submit();
    return false;
}

function inpclear(obj){
    if(!obj.def_value){
        obj.def_value=obj.value;
        obj.onblur=function(){this.value=this.value || this.def_value}
    }
    if(obj.def_value==obj.value) obj.value="";
}

function viewForm(a,fId){
    form = _(fId);
    form.className = (form.className == "hidden")?"visible":"hidden";
    tmp = a.innerHTML;
    a.innerHTML = a.getAttribute("textInner");
    a.setAttribute("textInner",tmp);
    return false;
}

function init_prev(root_id){
    var a=_(root_id).getElementsByTagName("a");
    for(var i=0, l=a.length; i<l; i++)
        if(a[i].href){ 
            //hover(a[i]); //preload img
            //a[i].onmouseover=function(){hover(this, 1)}
            //a[i].onmouseout=function(){hover(this, 0)}
            a[i].onfocus=function(){this.blur()}
            a[i].onclick=function(){return fs.show(this);}
        }
}
