String.prototype.trim = function () {
	return this.replace(/^\s*|\s*$/g, "");
}

Array.prototype.getUniqueValues = function () {
	var hash = new Object();
	for (j=0; j<this.length; j++) 
		hash[this[j]] = true;

	var array = new Array();
	for(value in hash) 
		array.push(value)

	return array;
}

//remove duplciated values and split into correct lines
function normalizeInput(obj)
{
	ret = obj.value.trim().split(/\s|[^A-Za-z0-9_.@-]/).getUniqueValues();
	ret.sort();
	obj.value = ret[0];
	for(i=1; i<ret.length; i++)
		obj.value += "\n" + ret[i];
}


function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) 
			d.MM_p=new Array();

		var i,j = d.MM_p.length, a = MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) { 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}

function openWin(url, w, h, name)
{
	if(!w)                  w = screen.width - 50;
	else if(w>screen.width)	w = screen.width;

	if(!h)                    h = screen.height - 100;
	else if(h>screen.height)  h = screen.height;

	if(!name)
		name = 'newwin';

	win = window.open(url, name, "width=" + w + ",height=" + h + ",resizable=1,scrollbars=1");
	win.focus()
}

function getObject(id){

	if(document.getElementById){
		return document.getElementById(id);
	}
	else if(document.all){
		return document.all[id];
	}
	return null;
}

function getElement(formObj, name)
{
	for(i=0; i<formObj.elements.length; i++) {
		e = formObj.elements[i];
		if(e.name==name)
			return e;
	}
}

function showHideLayer(obj, status) 
{
	var subobj = getObject(obj);
//	var subobj = document.getElementById(obj);

	if(status=='block' || status=='none') {
		subobj.style.display = status;
		return;
	}

	if( subobj.style.display == "block") {
		subobj.style.display = "none";
	} else {
		subobj.style.display = "block";
	}
}

function clearForm(formObj)
{
	for(i=0; i<formObj.elements.length; i++) {
		e = formObj.elements[i];
		if(e.type=='hidden' || e.type=='button')
			continue;
		if(e.type=='select-one')
			e.selectedIndex = 0;
		else if(e.type=='checkbox' || e.type=='radio')
			e.checked = false
		else {
			e.value = '';
		}
	}
}

function checkAll(formObj, v) 
{
	for(i=0; i<formObj.elements.length; i++) {
		e = formObj.elements[i];
		if(e.type=='checkbox')
			e.checked = v;
	}
}
 
//http://techpatterns.com/downloads/javascript_cookies.php
function Set_Cookie(name, value, expires, path, domain, secure) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	//if the expires variable is set, make the correct 
	//expires time, the current script below will set 
	//it for x number of days, to make it for hours, 
	//delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	var cookieStr = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) +  ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
//	alert(cookieStr);
	document.cookie = cookieStr;

}

function changeLang()
{
//	alert("English version will be published later");
//	return;

//	var url = parent.mainFrame.location.href;
	var url = parent.topFrame.location.href;
	var pos = url.lastIndexOf('/');

	if(pos<0)
		return;

	var file = url.substr(pos+1);
	if(file.substr(0, 2)=='e-') {
		parent.topFrame.location.href = 'top.html';
		parent.leftFrame.location.href = 'left.html';
//		parent.mainFrame.location.href = url.substr(0, pos+1) + file.substr(2);
	} else {
		parent.topFrame.location.href = 'e-top.html';
		parent.leftFrame.location.href = 'e-left.html';
//		alert('English version is still under construction. Apologies for any inconveniences');
//		parent.mainFrame.location.href = url.substr(0, pos+1) + 'e-' + file;
	}
}
