var mapWindowWidth = 680;
var mapWindowHeight = 530;

var detailsWindowWidth = 720;
var detailsWindowHeight = 580;

var referenceWindowWidth = 720;
var referenceWindowHeight = 560;

var voucherWindowWidth = 750;
var voucherWindowHeight = 550;

var printWindowWidth = 750;
var printWindowHeight = 550;

function openMap(scope, ref) {
	var url = "showMap.skbin?scope=" + scope + "&ref=" + ref;
	// alert("Opening: " + url);
	var mapWindow = window.open(url, '', 'scrollbars=no,menubar=no,height=' + mapWindowHeight + ',width=' + mapWindowWidth + ',resizable=yes,toolbar=no,location=no,status=no');
}

function openDetails(link) {
	var url = link;
	// alert("Opening: " + url);
	var detailsWindow = window.open(url, '', 'scrollbars=yes,menubar=no,height=' + detailsWindowHeight + ',width=' + detailsWindowWidth + ',resizable=yes,toolbar=no,location=no,status=no');
}

function popReference(event, scope) {
	window.name = "bookingWindow";
	var targetWin = window.name;
	//var url = "getList.skbin?event=" + event + "&scope=" + scope;
	var url = "?mod=reflist&eventid=" + event + "&scope=" + scope + "&target=" + targetWin;
	//alert("Opening: " + url);
	var referenceWindow = window.open(url, '', 'scrollbars=show,menubar=no,height=' + referenceWindowHeight + ',width=' + referenceWindowWidth + ',resizable=yes,toolbar=no,location=no,status=no');
}

function popReferenceUpdate(targetField, value) {
	opener.document.getElementById(targetField).value = value;
	//alert("Updating: " + targetField + " with value" + value);
	window.close();
}

function openAlert(scope) {
	var msg="";
	if (scope == "banktransfer") {
		msg = "Bank transfer will be available soon";
	} else if (scope == "reporterror") {
		msg = "If you wolud like to report\nan error or a change regarding\nyour order, please contact us\nat e-mail: mojca.sojar@kongres.si";
	}
	alert(msg);
}

function openVoucherWindow(ref) {
	var url="?sub=registrations&action=showvoucher&" + ref;
	//alert(url);
	var voucherWindow = window.open(url, '', 'scrollbars=auto,menubar=no,height=' + voucherWindowHeight + ',width=' + voucherWindowWidth + ',resizable=yes,toolbar=no,location=no,status=no');
}

function openPrintWindow(ref) {
	var url = ref;
	//alert(url);
	var printWindow = window.open(url, '', 'scrollbars=auto,menubar=no,height=' + printWindowHeight + ',width=' + printWindowWidth + ',resizable=yes,toolbar=no,location=no,status=no');
}

function trimString(sInString) {
	  sInString = sInString.replace( /^\s+/g, "" ); // strip leading
	  return sInString.replace( /\s+$/g, "" );      // strip trailing
}

function trimStringArray(data) {
	var ret = Array();
	for (i = 0; i < data.length; i++) {
		ret[i] = trimString(data[i]);
	}
	return ret;
}

function setProperty(el, property) {
	//var properties =
	var ret = false;
	if (property.indexOf(':') != -1) {
		var properties = property.split(':');
		properties = trimStringArray(properties)
		if (properties[0] == "display") {
			el.style.display = properties[1];
		} else if (properties[0] == "visibility") {
			el.style.visibility = properties[1];
		}
		ret = true;
	} else if (property.indexOf('=') != -1) {
		var properties = property.split("=");
		properties = trimStringArray(properties)
		if (properties[0] == "disabled") {
			el.style.disabled = properties[1];
		} else if (properties[0] == "readOnly") {
			el.style.readOnly = properties[1];
		}
		ret = true;
	}
	return ret;
}

function skFieldEvaluate(refEl) {
	var refValue = refEl.value;
	var el = false;
	var msg = "Setting: " + magicFields.length + "\n";
	var succ = false;
	for (idx = 0; idx < magicFields.length; idx++) {
		msg += "Field" + idx + " : " + magicFields[idx][2];
		if (magicFields[idx][0] == refEl.id) {
			msg += " = SET";
			el = document.getElementById(magicFields[idx][2]);
			if (refValue == magicFields[idx][1]) {
				//el.style = magicFields[idx][4];
				succ = setProperty(el, magicFields[idx][4]);
			} else {
				//el.style = magicFields[idx][3];
				succ = setProperty(el, magicFields[idx][3]);
			}
		}
		msg += "\n idx=" + idx + "\n";
	}
	msg += "Length: " + magicFields.length;
	if (!succ) alert(msg);
}
