///// test test test

function winopen(url) {
	// Here resize the PopUp
	
	var popUpSizeX=screen.width;;
	var popUpSizeY=screen.height;
	var scroll = "no";
	
	//var popUpSizeX=1240;
	//var popUpSizeY=1024;
	
	// Here move it to any poiny on screen	
	var popUpLocationX=0;
	var popUpLocationY=0;
	
	if(url == null)
	{
		url="http://www.frontlinemag.net";
	}
	if(popUpSizeX<1240){
		scroll="yes";
	} 
	
	// URL of the popUp
	var popUpURL= url;
	
	splashWin = window.open(url,'Frontlinemagazin','fullscreen=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scroll+',resizable=1');
	
	splashWin.blur();
	window.focus();
	
	splashWin.resizeTo(popUpSizeX,popUpSizeY);
	splashWin.moveTo(popUpLocationX,popUpLocationY);
	splashWin.location=popUpURL;
	splashWin.focus();
}

var submitted = false;
function submitOnce(form) {
	if(submitted) { return false; }
	return (submitted = true);
}

function addOptionToSelect(selectElement, optionName, optionValue, isNewDefault, isSelected) {
	newOption = new Option(optionName, optionValue, isNewDefault, isSelected);
	selectElement.options[selectElement.options.length] = newOption;
}

function deleteOptionOfSelect(selectElement, optionIndex) {
	//alert('delete option index'+optionIndex);
	selectElement.options[optionIndex] = null;
}

function deleteAllOptionsOfSelect(selectElement) {
	for(i=selectElement.options.length-1;i>=0;i--)
		deleteOptionOfSelect(selectElement, i);
}

function getSelectedOptionValues(selectElement) {
	var optionValues = new Array();
	for (i = 0; i < selectElement.options.length; ++i)
		if (selectElement.options[i].selected == true)
			optionValues.push(selectElement.options[i].value);
	return optionValues;
}

/*
dataArray = [ [parentValue, elementValue, elementName],  [parentValue, elementValue, elementName] ]
originalValue = value of initial element (elementValue), function tries to focus this element if in range

*/
function updateSubselectContent(selectElement, dataArray, parentValue, originalValue) {
	deleteAllOptionsOfSelect(selectElement);
	originalInFocusRange = false;
	
	// find regions of that country and add them to the selection list
	for(j=0; j<dataArray.length; j++) {
		e = dataArray[j];
		// e[0] = country, e[1] = regionid, e[2] = regionname
		if(e[0]==parentValue) {
			isNewDefault = false;
			isSelected = false;
			if(originalValue == parseInt(e[1])) {
				isNewDefault = true;
				isSelected = true;
				originalInFocusRange = true;
			}
			addOptionToSelect(selectElement, e[2], e[1], isNewDefault, isSelected)
		}
	}
	
	// select first if original-RegionId not in focus
	if(!originalInFocusRange)
		selectElement.options[0].selected = true;
	
}

function updateSubselectContentMultiple(selectElement, dataArray, parentValues, originalValues) {
	deleteAllOptionsOfSelect(selectElement);
	originalInFocusRange = false;
	// find regions of that country and add them to the selection list
	for(j=0; j<dataArray.length; j++) {
		e = dataArray[j];
		eParentValue = parseInt(e[0]);
		eValue = parseInt(e[1]);
		eLabel = e[2];
		// e[0] = country, e[1] = regionid, e[2] = regionname
		for(k=0; k<parentValues.length; k++) {
			if(eParentValue==parentValues[k]) {
				isNewDefault = false;
				isSelected = false;
				for(n=0; n<originalValues.length; n++) {
					if(parseInt(originalValues[n]) == eValue) {
						isNewDefault = true;
						isSelected = true;
						originalInFocusRange = true;
						break;
					}
				}
				addOptionToSelect(selectElement, eLabel, eValue, isNewDefault, isSelected);
				break;
			}
		}
	}
	
	// select first if original-RegionId not in focus
	//if(!originalInFocusRange)
	//	selectElement.options[0].selected = true;
	
}
