/**
	@Function:
		addressRecord
	@Description:
		Generates new object with properties country, cities and cityvalues.
	@Parameters:
		c = Selected country's name.
		ct = Cities in the selected country.
		ct2 = City numbers of the selected countries.
*/
function objRecord(c, ct, ct2) { 
   this.parent = c; 
   this.child = ct;
   this.childvalue = ct2;
} 

/**
	@Function:
		setCountry
	@Description:
		When the user selects an option from the countrylist, 
		then this funtion will populate the list of cities where TietoEnator has office(s).
	@Parameters:
		obj = Source selection box inside the form.
		targetBox = Target selection box where the new content is populated.
*/
function setElement( obj, targetBox ){
	//Get list of cities into an array.
	
	var arrChild = arrRecords[obj.selectedIndex+1].child.split('|');
	
	//Get list of numeric city values into an array.
	var arrChildVal = arrRecords[obj.selectedIndex+1].childvalue.split('|');
	
	//Call emptyList function.
	emptyList(obj.form.elements[targetBox]);
	
	//Populate the target box with new content.
	for(i=0; i<arrChild.length; i++){
		obj.form.elements[targetBox].options[i] = new Option(arrChild[i],arrChildVal[i]);
	}
}

/**
	@Function:
		emptyList
	@Description:
		Clears the contents from given SELECT -element.
	@Parameters:
		objList = Options are deleted from this selection list.		
*/
function emptyList(objList) {
	for(i=objList.options.length;i>0;i--){
		objList.options[i]=null;
	}
}

/**
	@Function:
		resets found elements to their initial values. Select boxes to their first option element and clears check boxes.
	@Description:
		Used on search pages.
	@Parameters:
*/
function resetFields() {
	var form;
	var elems;
	var i;
	
	form = document.forms[0];
	
	elems = form.getElementsByTagName('select')
	for(i=0; i<elems.length; i++) {
		elems[i].options[0].selected = true;
	}
	
	elems = form.getElementsByTagName('input')
	for(i=0; i<elems.length; i++) {
		switch(elems[i].type) {
			case 'text':
				elems[i].value = '';
				break;
			case 'checkbox':
				//alert(elems[i]);
				elems[i].checked = false;
				break;
		}
	}
}

/**
	@Function:
		checks some check boxes
	@Description:
		Used on the hugins subscribe to news page.
	@Parameters:
		elm, id	
*/
function checkHuginFormAll(elm,id){
	for (var i = 0; i < elm.form.elements.length; i++)
		if (elm.form.elements[i].id.indexOf(id) == 0)
			elm.form.elements[i].checked = elm.checked;
}

/**
	@Function:
		Opens a new window based on given parameters
	@Description:
		Whenever custom popup window is needed this function should be used to open the window
	@Parameters:
		url					= The url to be opened
		windowName			= Name of the new window
		windowProperties	= Properties of the new window (width, height and so on.)
*/
function openWindow(url,windowName,windowProperties)
{
	popupWindow = window.open(url,windowName,windowProperties);
	if (window.focus) 
	{
		popupWindow.focus();
	}
	return false;
}