function returnFalse() {
	return false;
}

function open_window(link,w,h) {
		var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'newWin',win);
		newWin.focus();
}

function openWindow(link,w,h) {
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=no,scrollbars=no";
	newWindow = window.open(link,'newWin',win);
	newWindow.focus();
}
	
function closeWindow() {
	var win = window;
	if (win && !win.closed) {
		win.close();
	}
}

function updateParent() {
	window.opener.location.href = opener.location;
}
	
function confirmDelete(msg,url) {
	if (window.confirm(msg)) {
		document.location.href = url;
		return false;
	}
	else {
		return false;
	}
}

function showHide(id) {
	if (document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";
		return;
	}
	else {
		document.getElementById(id).style.display = "none";
		return;
	}
}

function enableDisable(id, type) {
	var main = document.getElementById(type + '_cats[' + id + ']'),
		div = document.getElementById(type + '_c_' + id);
	if (div.style.display != 'block') {
		div.style.display = 'block';
	}
	list = div.getElementsByTagName('input');
	l = list.length;
	if (main.checked == true) {
		for (i = 0; i < l; i++) {
			list[i].checked = true;
			list[i].disabled = true;
		}
	}
	else {
		for (i = 0; i < l; i++) {
			list[i].checked = false;
			list[i].disabled = false;
		}
	}
}

function checkAllSelected(id, type) {
	var main = document.getElementById(type + '_cats[' + id + ']'),
		div = document.getElementById(type + '_c_' + id),
		ok = true;
	list = div.getElementsByTagName('input');
	l = list.length;
	for (i = 0; i < l; i++) {
		if (list[i].checked == false) {
			ok = false;
		}
	}
	if (ok == true) {
		main.checked = true;
		enableDisable(id, type);
	}
}

function showHideUserDetail(id) {
	var a = document.getElementById(id + '_info'),
		b = document.getElementById(id + '_info_edit'),
		c = document.getElementById('submit');
	a.style.display = 'none';
	b.style.display = 'block';
	if (c.style.display = 'none') {
		c.style.display = 'block';
	}
	else false;
}

function jump(value) {
		if (value != '') {
				document.location.href = 'index.php?orders=yes&showorders=yes&period='+value;
		}
		else {
				return false;
		}
}
	
// name - eiy cookie
// value - cia?aiea cookie
// [expires] - aaoa ieii?aiey aaenoaey cookie (ii oiie?aie? - eiiao oaeouae  //  nannee)
// [path] - ioou, aaa cookie aa?iu (ii oiie?aie? - ioou e oaeouaio aieoiaioo)
// [domain] - aiiai, aaa cookie aa?iu (ii oiie?aie? - aiiai aucuaaaiiai 
// aieoiaioa)
// [secure] - aeia?iay ia?aiaiiay, iieacuaa?uay, ?oi cookie aie?iu
// ia?aaaaaouny ?a?ac caueu?iiia niaaeiaiea
// * ii oiie?aie? a?aoiaioo i?enaiaii cia?aiea null
// * ioeaaia cia?aiea ia o?aaoaony i?enaaeaaou i?iiouaiiui ia?aiaiiui
function setCookie(name, value, expires, path, domain, secure) {
		var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
		document.cookie = curCookie;
}

// name - eiy cookie
// * no?iea aica?aoa niaa??eo cia?aiey iaiaoiaeiiai cookie eee null i?e
// aai ionoonoaee
function getCookie(name) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
				begin = dc.indexOf(prefix);
				if (begin != 0) return null;
		}
		else begin += 2;
		var end = document.cookie.indexOf(";", begin);
		if (end == -1) end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
}

function showHideMenu(menuId) {
		if (document.getElementById(menuId).style.display == 'block') {
				//Hide element, set Cookie
				document.getElementById(menuId).style.display = 'none';
				document.getElementById(menuId+'_image').innerHTML = '<img src="../../images/admin/down.gif" width="16" heigth="16" border="0" onClick="showHideMenu(\''+menuId+'\'); return false;" />';
				setCookie(menuId, 0);
		}
		else {
				//Show element, set Cookie
				document.getElementById(menuId).style.display = 'block';
				document.getElementById(menuId+'_image').innerHTML = '<img src="../../images/admin/up.gif" width="16" heigth="16" border="0" onClick="showHideMenu(\''+menuId+'\'); return false;" />';
				setCookie(menuId, 1);
		}
}
	
function showHideGrade(num) {		
	var check = document.getElementById('limit[' + num + ']'),
		el = document.getElementById('cost[' + num + ']'),
		block = '<table width="100%" align="center"><tr><table id="rates"><tr><td width="50%" align="center" style="font-weight:bold; font-size:smaller"><span>I?aaae noieiinoe<br />caeaca</span></td><td align="center" style="font-weight:bold; font-size:smaller"><span>Noieiinou<br />ainoaaee</span></td></tr><tr><td align="center"><input type="text" name="order_limit[' + num + '][0]" value="" /></td><td align="center"><input type="text" name="rate_value[' + num + '][0]" value="" /></td></tr><tr><td align="center"><input type="text" name="order_limit[' + num + '][1]" value="" /></td><td align="center"><input type="text" name="rate_value[' + num + '][1]" value="" /></td></tr></table></tr><tr><td colspan="2" align="center"><input type="button" class="blue" value="Aiaaaeou" style="font-weight:bold; font-size:smaller" onMouseUp="insertRow(\'rates_' + num + '\')" /></td></tr></table>',
		str = '<input id="cost" type="text" name="cost[' + num + ']" value="" />';
	if (check.checked) {
		el.innerHTML = block;
	}
	else {
		el.innerHTML = str;
	}
}

function insertRow(type) {
	var el = document.getElementById(type),
		num = el.rows.length;
	if (type == 'val_tab') {
		var c0 = '<input name="value[' + num + ']" id="' + num + '_value" type="text" value="" /><input type="hidden" name="valueID[' + num + ']" value="" />',
			c1 = '<input name="altvalue[' + num + ']" id="' + num + '_altvalue" type="text" value="" />',
			c2 = '<input name="val_sort_order[' + num + ']" id="' + num + '_sort" type="text" value="" />', 
			c3 = '<input name="val_enabled[' + num + ']" id="' + num + '_enabled" type="checkbox" value="" />',
			c4 = '<input name="val_editable[' + num + ']" id="' + num + '_editable" type="checkbox" value="" />';
		el.insertRow(num);
		el.rows[num].insertCell(0);
		el.rows[num].insertCell(1);
		el.rows[num].insertCell(2);
		el.rows[num].insertCell(3);
		el.rows[num].insertCell(4);
		el.rows[num].cells[3].align = 'center';
		el.rows[num].cells[4].align = 'center';
		el.rows[num].cells[0].innerHTML = c0;
		el.rows[num].cells[1].innerHTML = c1;
		el.rows[num].cells[2].innerHTML = c2;
		el.rows[num].cells[3].innerHTML = c3;
		el.rows[num].cells[4].innerHTML = c4;
	} else if (type == 'cat_tab') {
		c1 = el.rows[num - 1].cells[0].innerHTML;
		el.insertRow(num);
		el.rows[num].insertCell(0);		
		el.rows[num].cells[0].innerHTML = c1;
	} else {
		var c0 = '<input type="text" name="order_limit[' + type + '][' + num + ']" value="" />',
			c1 = '<input type="text" name="rate_value[' + type + '][' + num + ']" value="" />';
		el.insertRow(num);
		el.rows[num].insertCell(0);
		el.rows[num].insertCell(1);
		el.rows[num].cells[0].align = 'center';
		el.rows[num].cells[1].align = 'center';
		el.rows[num].cells[0].innerHTML = c0;
		el.rows[num].cells[1].innerHTML = c1;
	}
}