//	JavaScript Document

//	preload images
var pic = new Array();
var preLoadPic = new Array();
function preLoad() {
	pic[0]  = '../guest/img/xxxxx.jpg';

	for(var i = 0; i < pic.length; i ++) {
		preLoadPic[i] = new Image();
		preLoadPic[i].src = pic[i];
	}
}

function makePopup(pageURL, pageName, w, h, pageScroll, pageCenter) {
	if(pageCenter == 'no')	{
		LeftPosition = 10;
		TopPosition = 10;
	} else {
		LeftPosition = (screen.width) ? (screen.width-w) / 2 : 0;
		TopPosition = (screen.height) ? (screen.height-h) / 2 : 0;
	}

	var pageConfig = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + pageScroll + ', resizable=yes, width=' + (w + 18) + ', height=' + (h + 18) + ', left=' + LeftPosition + ', top=' + TopPosition;
	var popup = window.open(pageURL, pageName, pageConfig);
	popup.focus();
	return popup;
}

function menuOver(id) {
	document.getElementById('menu-' + id).style.backgroundColor = '#fff';
	document.getElementById('menu-' + id).style.cursor = 'pointer';
}

function menuOut(id) {
	document.getElementById('menu-' + id).style.backgroundColor = '#FFD500';
}

function descOver(obj) {
	document.getElementById(obj).style.display = '';	
}

function descOut(obj) {
	document.getElementById(obj).style.display = 'none';	
}

function init(lang) {
	if(document.getElementById('_group').value == '') {
		if(idBack) {
			document.getElementById('product-' +  idBack).style.display = 'none';
			document.getElementById('addButton').onclick = '';
		}
		document.getElementById('_product').style.display = '';
	} else {
		if(document.getElementById('_product').style.display == '') {
			document.getElementById('_product').style.display = 'none';
		}
		if(idBack) {
			document.getElementById('product-' +  idBack).style.display = 'none';
		}
		var id = document.getElementById('_group').options[document.getElementById('_group').selectedIndex].id;
		document.getElementById('product-' + id).style.display = '';
		idBack = id;
		
		document.getElementById('addButton').onclick = function() 	{
																	addOrder(lang, id);
																	};
	}
}

function addOrder(lang, id) {
	if(document.getElementById('StateText').style.display == '' && document.getElementById('CityText').style.display == '') {
		var state = document.getElementById('_stateText').value;
		var city = document.getElementById('_cityText').value;

	} else if(document.getElementById('StateSelect').style.display == '' && document.getElementById('CitySelect').style.display == '') {
		var state = document.getElementById('_stateSelect').value;
		var city = document.getElementById('_citySelect').value;
	}
	var fillFlag = 1;
	if(!document.getElementById('_count').value) {
		document.getElementById('_count').style.background = '#ffd';
		document.getElementById('_count').focus();
		fillFlag = 0;
	} else {
		document.getElementById('_count').style.background = '#fff';
	}
	
	if(!document.getElementById('_color').value) {
		document.getElementById('_color').style.background = '#ffd';
		document.getElementById('_color').focus();
		fillFlag = 0;
	} else {
		document.getElementById('_color').style.background = '#fff';
	}
	if(fillFlag) {
		if(lang == 'en') {
			document.getElementById('OrderList').value += 
			"Product Group:\r\t" + document.getElementById('_group').value + "\r" +
			"Product Name:\r\t" + document.getElementById('_product-' + id).value + "\r" +
			"Product Color:\r\t" + document.getElementById('_color').value + "\r" +
			"Product Count:\r\t" + document.getElementById('_count').value + "\r" +
			"Product Comment:\r\t" + document.getElementById('_comment').value + "\r" +
			"-----------------------------------------------\r";
		} else if(lang == 'fa') {
			document.getElementById('OrderList').value += 
			"گروه محصول:\r" + document.getElementById('_group').value + "\r" +
			"نام محصول:\r" + document.getElementById('_product-' + id).value + "\r" +
			"رنگ:\r\t" + document.getElementById('_color').value + "\r" +
			"تعداد:\r" + document.getElementById('_count').value + "\r" +
			"توضيحات:\r" + document.getElementById('_comment').value + "\r" +
			"-----------------------------------------------\r";
		}
		
		//	reset order form
		document.getElementById('_group').value = '';
		if(document.getElementById('product-' + idBack).style.display == '') {
			document.getElementById('product-' + idBack).style.display = 'none';
		}
		document.getElementById('_product').style.display = '';
		document.getElementById('_color').value = '';
		document.getElementById('_count').value = '';
		document.getElementById('_country').value = '';
		document.getElementById('_stateText').value = '';
		document.getElementById('_cityText').value = '';
		document.getElementById('_stateSelect').value = '';
		document.getElementById('_citySelect').value = '';
		document.getElementById('_comment').value = '';
	}
}

function showState() {
	if(document.getElementById('_country').value!='Iran, Islamic Republic of') {
		document.getElementById('StateText').style.display = '';
		document.getElementById('CityText').style.display = '';
		document.getElementById('StateSelect').style.display = 'none';
		document.getElementById('CitySelect').style.display = 'none';
	} else {
		document.getElementById('StateText').style.display = 'none';
		document.getElementById('CityText').style.display = 'none';
		document.getElementById('StateSelect').style.display = '';
		document.getElementById('CitySelect').style.display = '';
	}
}