isMSIE = (navigator.appName=="Microsoft Internet Explorer");
var apptimer = new Array();
var appobj = new Array();

function fixIE(e) {
	if (isMSIE) {
		e = event;
		e.target = e.srcElement;
		e.pageX = e.clientX + document.body.scrollLeft;
		e.pageY = e.clientY + document.body.scrollTop;
	}
	return e;
}

function c(o) {
	var t = o.parentNode.parentNode;
	var n = gid('s'+o.value).innerHTML;
	var i = gid('s'+o.value).parentNode.firstChild;
	var inq = gid("pesan");
	if (o.checked) {
		t.style.backgroundColor='FFFF99';
		inq.value = "- "+n+"\n"+inq.value;
		with (i.style) {
			borderColor = 'yellow';
			width = 54;
			height = 39;
			borderWidth = '3';
		}
	}
	else {
		t.style.backgroundColor='';
		var r = new RegExp("- "+n+"\r?\n?", "g");
		inq.value = inq.value.replace(r, RegExp.$1);
		with (i.style) {
			borderColor = '';
			width = 58;
			height = 43;
			borderWidth = '';
		}
	}
	return false;
}

function mclick(e, t) {
	e = fixIE(e);
	if (t.tagName=='DIV') {
		t = t.lastChild;
		t.click();
	}
	else
		e.cancelBubble = true;
	c(t);
}

function validate(f) {
	if (f.nama.value=='') {
		alert("Mohon tuliskan nama Anda");
		return false;
	}
	if (f.email.value=='') {
		alert("Mohon tuliskan alamat e-mail Anda");
		return false;
	}
	if (f.pesan.value=='') {
		alert("Mohon tuliskan pesanan/pertanyaan/komentar/testimonial Anda");
		return false;
	}
	sendform();
	return false;
}

var currc = 0;
function grab(o) {
	var i = o.parentNode.lastChild.id.substring(1);
	if (typeof(msgt)!='undefined') {
		clearTimeout(msgt);
		appear('msg', false, true);
	}
	if (pos[i] < 2) {
		appear('t'+i, true, true, 20);
		currc = (pos[i]==0 ? 1 : 0);
	}
	else {
		var tab = gid('t'+Math.floor(pos[i]/2));
		if (tab==null) {
			gid('msg').innerHTML = 'Halaman masih sedang di-load, mohon tunggu beberapa detik lagi...';
			appear('msg', true, true, 20);
			msgt = setTimeout("appear('msg', false, true)", 3000);
			return;
		}
		var far = tab.rows[0].cells[pos[i]%2];
		var cfar = gid('pick'+far.id.substring(1)).checked;
		var pfar = far.parentNode;
		far = pfar.removeChild(far);
		var here = gid('t0').rows[0].cells[0];
		var near = gid('t0').rows[0].cells[1];
		var cnear = gid('pick'+near.id.substring(1)).checked;
		var pnear = near.parentNode;
		near = pnear.removeChild(near);
		far = pnear.insertBefore(far, pnear.lastChild);
		if (cfar) gid('pick'+far.id.substring(1)).checked = true;
		appear(far, true, true, 20);
		var temp = pos[i];

		if (pos[i]%2==0)
			near = pfar.insertBefore(near, pfar.lastChild);
		else
			near = pfar.appendChild(near);
		if (cnear) gid('pick'+near.id.substring(1)).checked = true;
		
		pos[i] = 0;
		pos[here.id.substring(1)] = 1;
		pos[near.id.substring(1)] = temp;
		
		currc = (currc==0 ? 1 : 0);
	}
	return false;
}

function sendform() {
	var n = gid('nama');
	var e = gid('email');
	var h = gid('telepon');
	var p = gid('pesan');
	var k = '';
	var pick = document.getElementsByName('pick[]');
	var b = gid('btsend');
	var t = gid('txsend');
	if ((n.value!=='') && (e.value!=='') && (p.value!=='')) {
		var i;
		for (i=0; i<pick.length; i++) {
			if (pick[i].checked) {
				k += '&pick[]='+pick[i].value;
			}
		}
		var param = '?nama='+escape(n.value)+'&email='+escape(e.value)+'&telepon='+escape(h.value)+'&pesan='+escape(p.value)+k+'&submit=1';
		n.disabled = e.disabled = h.disabled = p.disabled = b.disabled = true;
		opc('form', 0.5);
		if (typeof(sft)!='undefined') clearTimeout(sft);
		t.innerHTML = "sedang mengirim...";
		appear(t, true, true, 20);
	
		if (isMSIE)
			var httpreq = new ActiveXObject("Microsoft.XMLHTTP");
		else
			var httpreq = new XMLHttpRequest();
		httpreq.open('get', param+'&r='+Math.random());
		httpreq.onreadystatechange = function () {
					if ((httpreq.readyState == 4) && (httpreq.status == 200)) {
						var response = httpreq.responseText;
						if (response!="") {
							t.innerHTML = '<b>Terima kasih</b> telah menghubungi kami.';
							appear(t, true, true, 20);
							n.value = e.value = h.value = p.value = '';
							n.disabled = e.disabled = h.disabled = p.disabled = b.disabled = false;
							appear('form', true, true, 20);
							sft = setTimeout("gid('txsend').style.visibility = 'hidden'", 10000);
						}
					}
				};
		httpreq.send(null);
	}
}
function togglechat() {
	if ((typeof(chatopen)=='undefined') || !chatopen) {
		chatopen=true;
		gid('chat').style.display = 'block';
		appear('chat',true,true);
	}
	else {
		chatopen=false;
		appear('chat', false, true);
		gid('chat').style.display = 'none';
	}
}

function show(o,s) {
	if (s==undefined) s=true;
	with (o.style) {
		borderColor = (s ? '55ff55': (gid('pick'+o.parentNode.lastChild.id.substring(1)).checked ? 'yellow' : ''));
	}
	var d = o.parentNode.lastChild;
	opc(d, 0);
	d.style.visibility = (s ? 'visible' : 'hidden');
	appear(d, s);
}
function hide(o) {
	show(o, false);
}
function appear(o, a, ex, dl) {
	var id = (ex ? Math.random() : 2);
	if (dl==undefined) dl = 1;
	if (typeof(apptimer[id])!='undefined') clearTimeout(apptimer[id]);
	if (typeof(appobj[id])!='undefined') opc(appobj[id], 0);
	if (typeof(o)=='string') o = gid(o);
	if (a) {
		o.style.visibility = 'visible';
		opc(o, 0.01);
		appobj[id] = o;
		apptimer[id] = setTimeout("appstep(0.3, '"+id+"', "+dl+")", 100);
	}
	else {
		opc(o, 0);
		o.style.visibility = 'hidden';
	}
}
function appstep(n, id, dl) {
	if (appobj[id].style.opacity > 0) {
		opc(appobj[id], n);
		if (n < 0.95) apptimer[id] = setTimeout("appstep("+(n+0.1)+", '"+id+"', "+dl+")", dl);
	}
}
function opc(o,n) {
	if (typeof(o)=='string') o = gid(o);
	o.style.opacity = n;
	o.style.filter = 'alpha(opacity='+(n*100)+')';
}
function gid(s) {
	return document.getElementById(s);
}

