var shownum = 9, curleft, curtop, h, w, rvalue, sshow;

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	rvalue = randomstring;
}

function getXHTTP() {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}

function get_show(obj, cat) {
	http = getXHTTP();
	randomString();
	document.getElementById('progress').style.display = 'inline';
	obj.disabled = true;
	http.open("GET", "show.php?code="+rvalue+"&category="+cat+"&get_show=true", true);
	http.onreadystatechange = function() { getHttpRes(obj, http); }
	http.send(null);
}

function getHttpRes(obj, http) {
	if (http.readyState == 4) {
		var res = http.responseText;
		obj.disabled = false;
		document.getElementById('progress').style.display = 'none';
		$('slideshow').innerHTML = res;
		load_slideshow();
	}
}

function send(obj) {
	http = getXHTTP();
	var visitor = document.getElementById("visitor");
	var email = document.getElementById("email");
	var notes = document.getElementById("notes");
	randomString();
	document.getElementById('send_res').style.display = '';
	obj.disabled = true;
	name.disabled = true;
	email.disabled = true;
	notes.disabled = true;
	fixed_notes = notes.value;
	fixed_notes = fixed_notes.replace(/\n/g,'<br />');
	http.open("GET", "send.php?code="+rvalue+"&visitor="+visitor.value+"&visitormail="+email.value+"&notes="+fixed_notes, true);
	http.onreadystatechange = function() { get_send_res(visitor, email, notes, obj); }
	http.send(null);
}

function get_send_res(visitor, email, notes, obj) {
	if (http.readyState == 4) {
		var res = http.responseText;
		obj.disabled = false;
		visitor.disabled = false;
		email.disabled = false;
		notes.disabled = false;
		$('send_res').innerHTML = res;
	}
}

function reset_form() {
	var visitor = document.getElementById("visitor");
	var email = document.getElementById("email");
	var notes = document.getElementById("notes");
	document.getElementById('send_res').style.display = 'none';
	document.getElementById('send_res').innerHTML = '<img src="admin/main_load.gif" width="16" height="16" />';
	visitor.value = '';
	email.value = '';
	notes.value = '';
}

function replacer(a) {
a.value = a.value.replace(/&/gi, "and");
a.value = a.value.replace(/#/gi, "");
}

function show(num) {
	i = 0;
	while (i < shownum) {
		if (num != i) {
			document.getElementById("layer"+i).style.display = 'none';
			if (i > 0)
				document.getElementById("a"+i).className = "a"+i;
		}
		if (num == i) {
			document.getElementById("layer"+i).style.display = '';
			if (i == 8)
				$('visitor').focus();
			
			if (i > 0) {
				$('tab_select_fill').style.display = 'none';
				find_pos(document.getElementById("a"+i));
				document.getElementById("a"+i).className = "tab_select";
			}
			// Effect.SlideDown('layer'+i, { duration: 2.0, transition: Effect.Transitions.sinoidal });
		}
		i++;
	}
}

function load_content() {
	show(0);
	Effect.SlideDown('content', { duration: 1.0, transition: Effect.Transitions.sinoidal });
}

function load_slideshow() {
	document.getElementById('slideshow').style.display = '';
	sshow = new Horinaja(rvalue, 0.5, 5, true);
}

function check_caption(id) {
	id -= 1;
	if ( document.getElementById("caption_"+id) )
		$('caption').innerHTML = $("caption_"+id).innerHTML;
	else
		$('caption').innerHTML = '';
}

function find_pos(a) {
	id = a.id;
	curleft = curtop = 0;
	h = a.offsetHeight - 1;
	w = a.offsetWidth;
	if (a.offsetParent) {
		do {
			if (a.id != 'container') {
				curleft += a.offsetLeft;
				curtop += a.offsetTop;
			}

		} while (a = a.offsetParent);
	}
	
	if (id.indexOf("a") != -1) {
		$('tab_select_fill').style.top = (curtop - 8) + "px";
		$('tab_select_fill').style.left = (curleft + 3) + "px";
		$('tab_select_fill').style.width = (w - 8) + "px";
		$('tab_select_fill').style.display = '';
	}
}

function show_div(id, num) {			
	for (i = 0; i < 4; i++)
		if (i != num)
			$('b'+i).style.display = 'none';	
	
	$('b'+num+'_detail1').style.display = '';
	$('b'+num+'_price1').style.display = '';
	$('b'+num).style.width = '';
	$('show_b'+num).style.display = 'none';
	if (document.getElementById('b'+num+'_detail2'))
		$('b'+num+'_detail2').style.display = '';
	if (document.getElementById('b'+num+'_price2'))
		$('b'+num+'_price2').style.display = '';
	find_pos(document.getElementById("b"+num));
	// $(id).style.left = (curleft + w - 30) + "px";
	// $(id).style.top = (- h) + "px";
	Effect.Appear(id, { duration: .5, transition: Effect.Transitions.sinoidal });
}

function hide_div(id, num) {
	$(id).style.display = 'none';
	$('b'+num+'_detail1').style.display = 'none';
	$('b'+num+'_price1').style.display = 'none';
	if (num == 0)
		wid = '240px';
	if (num == 1)
		wid = '140px';
	if (num == 2)
		wid = '240px';
	if (num == 3)
		wid = '140px';
	$('b'+num).style.width = wid;
	if (document.getElementById('b'+num+'_detail2'))
		$('b'+num+'_detail2').style.display = 'none';
	if (document.getElementById('b'+num+'_price2'))
		$('b'+num+'_price2').style.display = 'none';
	$('show_b'+num).style.display = '';
	
	for (i = 0; i < 4; i++)
		$('b'+i).show();
}
