var basket = 0;
var param = 'resizable=yes,scrollbars=yes,width=640,height=400,toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+((screen.width-640)/2)+',top='+((screen.height-400)/2);

function show_basket() {
	var total = document.getElementById('total');
	if(total.innerHTML == '0.00') {
		alert('Shopping Cart is empty');
		return false;
	} else {
		win = window.open('basket.php', 'ShoppingCart', param);
		win.focus();
	}
}

function toogleVisibility() {
	var a=document.getElementById('auth');
	//alert(a.className)
	if (a.className=='hide') {
		a.className='show';
	} else {
		a.className='hide';
	}
}

function showPrint(w, h, params) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('print.php?id='+params, 'Print', param);
	win.focus();
}

function showEmail(w, h, params) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('email.php?id='+params, 'Email', param);
	win.focus();
}

function showChPasswdForm(w, h) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('user.php?act=showChPasswdFrm', 'PasswordChanging', param);
	win.focus();
}

function showRememberForm(w, h) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('user.php?act=showRememberFrm', 'RememberPassword', param);
	win.focus();
}

function showRegisterForm(w, h) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('user.php?act=showRegFrm', 'Registration', param);
	win.focus();
}

function showAddToBasket(w, h, params) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('add_to_basket.php?id='+params, 'addToOrder', param);
	win.focus();
}


function showBasket(w, h) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('view_order.php', 'ViewOrder', param);
	win.focus();
}

function showProfileForm(w, h) {
	var left = (screen.width-w)/2;
	var top  = (screen.height-h)/2;
	var param = 'resizable=yes,scrollbars=yes,width='+w+',height='+h+',toolbar=no,userbar=no,location=no,status=no,menubar=no,screenX=100,screenY=100,left='+left+',top='+top;
	win =  window.open('user.php?act=showProfileFrm', 'ProfileEditing', param);
	win.focus();
}

function delete_items() {
	var i = 0;  var c;
	var f = false;
	while(c = document.getElementById('checks['+i+']')) {
		if(c.checked) {
			f = true;
			break;
		}
		i++;
	}
	if(f) {
		var frm = document.getElementById('list');
		frm.action += '?act=del';
		frm.submit();
	} else {
		alert('There are no selected items');
		return false;
	}
}

function clear_cart() {
	var url = window.location.href.split('?');
	window.location.href = url[0]+'?act=clear';
}

function refresh_all() {
	var url = parent.window.location.href;
	parent.window.location.href = url;
}

function update() {
	var frm = document.getElementById('list');
	frm.action += '?act=eval';
	frm.submit();
}


function submit_form() {
	var frm = document.getElementById('user');
	frm.submit();
}

function resetTotal() {
	var shart_total = document.getElementById('total');
	var opener_total = opener.document.getElementById('total');
	opener_total.innerHTML = shart_total.innerHTML;
}

function breakPayment(state) {
	alert('breakPayment: '+state);
	window.location='basket.php?act='+state;
//	window.close();
}

function closeCart() {
//	alert('closeCart');
	var opener_total = opener.document.getElementById('total');
	opener_total.innerHTML = '0.00';
	window.close();
}

function check_form(form) {
	//alert('check_form');
}

function check_all(e) {
	var i = 0;  var c;
	while(c = document.getElementById('checks['+i+']')) {
		c.checked = e.checked;
		i++;
	}
}

function login(mode) {
//	opener.document.
	window.location = "user.php?act=showLoginFrm&mode="+mode;
}

function __check_form(form)
{
	for(i = 0; i <= required.length-1; i++) {
		var e = form.elements[required[i][0]].value;
//		alert('required['+i+'][1] = '+required[i][1]);
		switch(required[i][1]) {
			case 'required':
				if(e.length == 0) {
					alert('\''+required[i][2]+'\' field length should not be empty');
					return false;
				}
				break
			case 'cond:>$1':
				if(e < 1) {
					alert('\''+required[i][2]+'\' field should be more then or equal $1');
					return false;
				}
				break
			case 'confirm:PASSWD1':
				var ar = required[i][1].split(':');
				var e1 = form.elements[ar[1]];
				if(e != e1.value) {
					alert('Passwords do not match. Please try again!');
					form.elements[required[i][0]].value = '';
					e1.value = '';
					e1.focus();
					return false;
				}
				break
			case 'regex:email':
//				var r = new RegExp("^http:\\/\\/" + document.domain + "\\/(.+\\/)*(\\??.+)*$");
//				var t = "^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$";
//				var t = "^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$";
				var t = "^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
				var r = new RegExp(t);
				var m = e.match(r);
				if(m == null) {
					alert(required[i][2]+' is Invalid');
					return false;
				}
				break
			default:
		}
	}
	return true;
}