var agent = navigator.userAgent.toLowerCase();
var is_ns  = ((agent.indexOf('mozilla') != -1)
				&& (agent.indexOf('spoofer') == -1)
				&& (agent.indexOf('compatible') == -1)
                && (agent.indexOf('opera') == -1)
                && (agent.indexOf('webtv') == -1)
                && (agent.indexOf('hotjava') == -1));
var is_ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
var is_opera = (agent.indexOf("opera") != -1);
var win;

window.onload=function(){
	init_dropdown();
	init_choose_size();
	init_gallery2();
}


function init_choose_size(){
	if(!document.getElementById("choose_size")) return;
	objs=document.getElementById("choose_size").getElementsByTagName("img");
	for(i=0;i<objs.length;i++){
		if(!objs[i].parentNode.href) continue;
		objs[i].parentNode.style.background="url(imgs/"+objs[i].id+"_a.jpg)"
		objs[i].onmouseover=function(){this.src="imgs/"+this.id+"_a.jpg"}
		objs[i].onmouseout=function(){this.src="imgs/dot.gif"}
	}
}

function init_dropdown(){
	if(!(_menu=document.getElementById("menu"))) return;
	mi=_menu.getElementsByTagName("a");
	for(i=0;i<mi.length;i++){
		if(!mi[i].name || mi[i].className=="act") continue;
		dropdown=document.getElementById("drop_"+mi[i].name);
		if(!dropdown) continue;
		mi[i].onmouseover=function(){dropdown_on(this)}
		mi[i].onmouseout=function(){dropdown_over()}
		dropdown.onmouseover=function(){act=1;}
		dropdown.onmouseout=function(){dropdown_over();}
		objs=dropdown.getElementsByTagName("a");
		for(j=0;j<objs.length;j++){
			objs[j].onmouseover=function(){act=1;}
			objs[j].onmouseout=function(){dropdown_over();}
		}
	}
}

var act=0;
var tm;
var cur;

function dropdown_on(obj){
	if(cur) document.getElementById(cur).style.display="none"; 
	cur="drop_"+obj.name;
	document.getElementById(cur).style.display="block"; 
	act=1;
}

function dropdown_off(){
	if(!act) document.getElementById(cur).style.display="none";
}

function dropdown_over(){
	act=0;
	clearTimeout(tm);
	tm = setTimeout("dropdown_off()",200); 
}


function init_gallery2(){
	if(!(_gallery2=document.getElementById("gallery2"))) return;
	objs=_gallery2.getElementsByTagName("img");
	for(i=0;i<objs.length;i++){
		objs[i].style.backgroundImage="url("+objs[i].id+")";
		objs[i].onmouseover=function(){gallery2_over(this)}
		objs[i].onmouseout=function(){gallery2_out(this)}
		objs[i].onclick=function(){gallery2_click(this)}
	}
}

var cur_img;

function gallery2_over(obj){
	if(obj==cur_img) return; 
	obj.name=obj.src; 
	obj.src="imgs/dot.gif";
}

function gallery2_out(obj){
	if(obj==cur_img) return; 
	obj.src=obj.name;
}

function gallery2_click(obj){
	if(cur_img) cur_img.src=cur_img.name;
	else gallery2_over(obj);
	cur_img=obj;
	dp=document.getElementById("design_prev")
	dp.getElementsByTagName("img")[0].src=obj.lang;
	dp.getElementsByTagName("span")[0].innerHTML=obj.alt;
}

function areYouSure(text) {
	if (text==undefined) text="Are you sure?";
	if (confirm(text))
		return true;
	return false;
}

function optionAdd(_objSelect,_text,_value, _id) {
    if (is_ie) {
        var _objOption = document.createElement("OPTION");
        _objOption.text = _text;
        _objOption.value = _value;
        _objOption.lang = _id;
        _objSelect.add(_objOption);
    }else if (is_ns || is_opera) {
        var _nextOption = _objSelect.options.length;
        _objOption = new Option(_text,_value,"");
        _objOption.lang = _id;
        _objSelect.options[_nextOption] = _objOption;
    }
}

function optionDelete(_objSelect,_start,_length) {
    if (_start == null || _start < 0)
        _start = 0;
    if (_length == null || _length < 0 || _length == 0)
        _elements = objSelect.length;
    else
        _elements = (_length > (objSelect.length - _start))	?objSelect.length - _start	:_start + _length;
    for (i=_start;i<_elements;i++)
        objSelect.options[_start] = null;
}

function optionSelect(_objSelect,_index) {
    _index = (_index == null || _index >= _objSelect.length)?0:_index;
    if (is_ie || is_opera)
        _objSelect.selectedIndex = _index
    if (is_ns)
        _objSelect.options[_index].selected = true
}

function email_is_valid(_email) {
    email_re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/
    email_re2 = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
    if (_email == "" || email_re1.exec(_email) || !email_re2.exec(_email))
        return false
    return true
}
