<!-- ALIEN CODE-->

//PAGE METRICS

// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//END PAGE METRICS

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
	}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function getRealLeft(obj) {
    xPos = obj.offsetLeft;
    tempEl = obj.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(obj) {
    yPos = obj.offsetTop;
    tempEl = obj.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

function strip_tags(source) {
var newString = "";
   var inTag = false;
   for(var i = 0; i < source.length; i++) {
   
        if(source.charAt(i) == '<') inTag = true;
        if(source.charAt(i) == '>') {
              inTag = false;
              i++;
        }
   
        if(!inTag) newString += source.charAt(i);

   }

   return newString;
}

var detectbrow=navigator.userAgent.toLowerCase();
var browsername;
if (checkIt('msie')&&!checkIt('opera'))
{
 optparam=-1;
 browsername='msie';
}
else
{optparam=null;}


function checkIt(string)
{
place = detectbrow.indexOf(string) + 1;
thestring = string;
return place;
}

<!-- END ALIEN CODE-->


function array_delete_element(array, index)
{
	
}

function clearlist(list)
{
 for(i=list.length;i>=0;i--)
 {
 list.remove(i);
 }
}

function addlistelement(list, element, value, optparam, first)
{
 var newel = document.createElement('option');
 newel.text = element;
 newel.value = value;
 list.add(newel, optparam);
}

function arraytolist(arr, list, optparam, clear)
{
 if (clear) {clearlist(list);}
 for(i=0;i<=arr.length-1;i++)
 {
	 var newel = document.createElement('option');
	 newel.text = arr[i];
	 newel.value = arr[i];
	 list.add(newel, optparam);
 }
}

function multipleselected(list)
{
counter=0;
if (list.selectedIndex<0)
{
 	return -1; //no selection!
}

for(var i=list.selectedIndex;i<list.length;i++)
{
	if (list.options[i].selected == true)
	{
	counter++;	
	}
	if (counter>1)
	{
		return 1;
	}
}
 if (counter==1)
 {
	return 0; //single selection
 }
}

function hasspaces(s)
{
 var ss= new String();
 ss=s;
 if (ss.indexOf(" ")>=0)
 {
 return true;
 }
 else	
 {
 return false;
 }
}

function islegalname(name, accepted)
{
 nums= new String("0123456789");
 lits= new String("abcdefghijklmnopqrstuvwxyz");
 accs= new String();
 accs=accepted;
 accs=accs.toLowerCase();
 ss=new String(name);
 ss= ss.toLowerCase();
 bfound=false;
 for (i=0;i<=ss.length-1;i++)
 {
	for (j=0;j<=nums.length-1;j++)
	{
		if (ss.charAt(i)==nums.charAt(j))
		{
			bnum=true;
			break;
		}
		else
		{
			bnum=false;
		}
	}
	for (j=0;j<=lits.length-1;j++)
	{
		if (ss.charAt(i)==lits.charAt(j))
		{
			blit=true;
			break;	
		}
		else
		{
			blit=false;
		}
	}
	for (j=0;j<=accs.length-1;j++) <!-- check accepted chars -->
	{
		if (ss.charAt(i)==accs.charAt(j))
		{
			bother=true;
			break;	
		}
		else
		{
			bother=false;
		}
	}
	bfound=bnum||blit||bother;
	if (!bfound){break};
 }
 return bfound;
}

function hasillegals(s, ills) <!-- ills must be an Array -->
{
 var ss= new String();
 ss=s;
 for (i=0;ills.length-1;i++)
 {
	if (ss.indexOf(ills[i])>=0)
	{
	return true;
	}
 }
}

function isvalidemail(email)
{
 var s= new String();
 s=email;
 var ss= s.split('@');	 
 if (!islegalname(ss[0], '._')) <!-- theoretical username -->
 {
 return false;
 }
 if (!islegalname(ss[1], '._-')) <!-- theoretical domain name -->
 {
 return false;
 }
 if ((s.indexOf('@')<=0)|| <!-- no @ in it -->
	(s.indexOf('@')==s.length-1)|| <!-- misplaced @ in it -->
	(s.indexOf('@')>=s.length-4)||
	(s.indexOf('@')!=s.lastIndexOf('@'))|| <!-- too many @s -->
	(s.indexOf('.')<=0)||<!-- no . in it -->
	(s.lastIndexOf('.')==s.length-2)||<!-- misplaced . in it -->
	(s.lastIndexOf('.')<s.length-4)||
	(s.lastIndexOf('.')==s.lastIndexOf('@')+1)<!-- the @. situation -->
     	)
 {
 return false; 
 }
 else
 {
 return true;
 }
}

function isObject(item)
{
	return (item && typeof item == 'object') || isFunction(item);
}
function isArray(item)
{
	return isObject(item) && item.constructor == Array;
}

function isFunction(item) {
    return typeof item == 'function';
}

function removespaces(fs)
{
 var s="";
 split=fs.split(" ");
 for(i=0;i<=split.length-1;i++)
 {
  s=s+split[i];
 }
 return s;
}

function FindInArray(arr, text) // returns index of Text in array; if not fount returns -1
{
 temp=new String();
 temp= text;
 for(i=0; i<=arr.length-1; i++)
 {
	if (arr[i].toUpperCase() == temp.toUpperCase())
	{
		return i;
	}
 }
 return -1;	
}

function FindInList(options, text) // returns index of Text in array; if not fount returns -1
{
 temp=new String();
 temp= text;
 for(i=0; i<=options.length-1; i++)
 {
	if (options[i].value.toUpperCase() == temp.toUpperCase())
	{
		return i;
	}
 }
 return -1;	
}

function IsNavigKey(key)
{
 	result=false;
	var navigs = new Array(0,8);
	for (i=0;i<=navigs.length-1;i++)
	 {
		result=(key==navigs[i]);
		if (result)
		{
		 	//alert(key);
			break;	
		}	
	 }
	return result; 
}

function ShortenStr(source, maxlen, ellipsis)
{
	sub=source.substr(0, maxlen);
	if(maxlen<source.length && ellipsis)
		sub+='...';
	return sub;	
}

function GetNodeText(node)
{
	node=node.firstChild;
	while(node.nodeName.toLowerCase()!='#text')
		node=node.firstChild;
	if(browsername=='msie')
	{
		return Trim(node.nodeValue.replace(/[\r\n]+/g, " "));
	}	
		else
	{	
		return Trim(node.nodeValue.replace(/[\r\n]+/g, " "));
	}	
}

function nos_GetElementsByAttribute(attr, value)
{
	nodes=document.getElementsByTagName('*');
	result=new Array();
	for(var i=0;i<nodes.length;i++)
	{
		if(nodes[i].getAttribute(attr)==value)
		{
			result.push(nodes[i]);		
		}
	}
	return result;
}

function nos_SelectGetSelection(elem)
{
	//returns selected options in a SELECT element
	var res=new Array();
	for(var i=0;i<elem.options.length;i++)
	{	
		if(elem.options[i].selected)
			res.push(elem.options[i]);
	}
	return res;
}

function nos_SelectDeleteSelection(elem)
{
	//deletes selected options in a SELECT element
	var i=elem.options.length-1;
	while(i>=0)
	{	
		if(elem.options[i].selected)
		{
			elem.options[i]=null;
		}
		i--;
	}	
}

function nos_SelectMoveSelected(elem, direction)
{
	if(!elem || elem.options.selectedIndex<0)
		return;
	switch(direction.toLowerCase())
	{
		case 'up':
			var move=elem.options.selectedIndex-1;
		break;
		
		case 'down':
			var move=elem.options.selectedIndex+1;
		break;		
	}
	
	if(move<0 || move>=elem.options.length)
		return;
	
	aux_value=elem.options[move].value;
	aux_innerHTML=elem.options[move].innerHTML;
	elem.options[move].value=elem.options[elem.options.selectedIndex].value;	
	elem.options[move].innerHTML=elem.options[elem.options.selectedIndex].innerHTML;
	
	elem.options[elem.options.selectedIndex].value=aux_value;
	elem.options[elem.options.selectedIndex].innerHTML=aux_innerHTML;
	elem.options[elem.options.selectedIndex].selected=false;
	
	elem.options[move].selected=true;
}

function quotes_to_entity(source)
{
	return source.replace(/"/g, '&#34');
}

function ViewportWidth()
{
	return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
}

function ViewportHeight()
{
	return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
}

function ViewportXOffset()
{
	return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
}

function ViewportYOffset()
{
	return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
}

function nos_ShowSplash()
{
	splash=document.getElementById('splash_screen');
	splash.style.display='block';
}

nos_utf8_chars_replace=new Array('ă','î','â','ţ','ş','Ă','Î','Â','Ţ','Ş');
nos_utf8_chars_replacements=new Array('a','i','a','t','s','A','I','A','T','S');

function nos_urlize_string(s, sep)
{
	if(!sep)
		sep='_';
	for(i=0;i<nos_utf8_chars_replace.length;i++)
	{
		s=s.replace(nos_utf8_chars_replace[i], nos_utf8_chars_replacements[i]);
	}	
	s=s.replace(/\s+/gim, sep).toLowerCase();
	return s;
}


function parseURL(url)
{
	var a = document.createElement('a');
	a.href = url;
	return {
		source: url,
		protocol: a.protocol.replace(':',''),
		host: a.hostname,
		port: a.port,
		query: a.search,
		params: (function(){
		var ret = {},
		seg = a.search.replace(/^\?/,'').split('&'),
		len = seg.length, i = 0, s;
		for (;i<len;i++) {
		if (!seg[i]) { continue; }
		s = seg[i].split('=');
		ret[s[0]] = s[1];
	}
	return ret;
	})(),
	file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
	hash: a.hash.replace('#',''),
	path: a.pathname.replace(/^([^\/])/,'/$1'),
	relative: (a.href.match(/tp:\/\/[^\/]+(.+)/) || [,''])[1],
	segments: a.pathname.replace(/^\//,'').split('/')
	};
}
//URL QUERY-ALTERING FUNCTIONS//
function nos_param_from_query(query, param)
{
	var pos=query.indexOf("?"+param);
	if(pos<0)
		pos=query.indexOf("&"+param);
		
	var endpos=query.indexOf("&", pos+1);
	if(endpos<0)//it is the last param, no "&" after it
		endpos=query.length;
		
	if(pos>=0)
	{
		var replaced=query.substring(pos, endpos);
		return replaced;
	}		
	return "";
}

function nos_param_value(query, param)
{
	var full=nos_param_from_query(query,param);
	var pos=full.indexOf(param+"=");
	return full.substring(pos+(param+"=").length);
}

function nos_modif_query(query, param, value)
{
	var replaced=nos_param_from_query(query,param);
	query=query.replace(replaced, "");
	if(query.indexOf('?')<0)
	{
		pos=query.indexOf('&');
		if(pos<0)
			query+="?"+param+"="+value;
			else
			query=query.replace(/\&/, '?'+param+'='+value+'&');
	}
	else		
		query+="&"+param+"="+value;
	return query;
}				

function nos_del_from_query(query, param)
{
	replaced=nos_param_from_query(query, param);
	query=query.replace(replaced, "");
	//replace first "&" with "?" IF the param being removed was at the beginning of query
	if(replaced.indexOf('?')==0)
		query.replace(/&/,'?')
	return query;
}	