/************************************************************************
	Functions from Netscape's JavaScript Guide
	http://developer.netscape.com/docs/manuals/js/client/jsguide/
*************************************************************************/
function setCookie( name, value, expire, path ) {
	document.cookie = name + '=' + escape(value)
		+ ((expire == null)? '' : ('; expires=' + expire.toUTCString()))
		+ ((path == null)? '' : ('; path=' + path));
}

function getCookie(Name) {
	var search = Name + '='
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search) 
		if (offset != -1) { // if cookie exists 
			offset += search.length 
			// set index of beginning of value
			end = document.cookie.indexOf(';', offset) 
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
	return '';
}

function deleteCookie ( name,path,domain ) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
/*************************************************************************/


/************************************************************************
	returns a string expression, rounded to two signs
*************************************************************************/
function round( x ) {
	//return x.toLocaleString();
	var ch;
	var str= (Math.round(x*100)/100).toLocaleString();
	var index = 0;
	ch = str.charAt(index);
	str = ( ch == '.' || ch == ',' ) ? '0' + str : str;
	
	index = str.length-3;
	ch = str.charAt(index);
	if( ch == '.' || ch == ',' )
		return str;
	
	index = str.length-2;
	ch = str.charAt(index);
	if( ch == '.' || ch == ',' )
		return str = '0';
	
	//return str + ch + '00';
		
		
	if (str.charAt(str.length-3)=='.'||str.charAt(str.length-3)==',') {
		str+='';
	}
	else if (str.charAt(str.length-2)=='.'||str.charAt(str.length-2)==',') {
		str+='0';
	}
	else	{
		str+=',00';
	}
	
	return str;
}


/************************************************************************
	returns a parent object "parentTagName"
*************************************************************************/
function getParent( obj, parentTagName ){
	if( obj ){
		while((obj = obj.parentNode))
			if(obj.tagName == parentTagName)
				return obj;
	}
	return null;
}

function getChild( obj, childTagName ){
	if( obj ){
		while((obj = obj.childNode))
			if(obj.tagName == childTagName)
				return obj;
	}
	return null;
}

function getNextObject(obj, tag) {
    var next = obj;
    while(!next || next.tagName != tag )
        next = next.nextSibling;
    return next;
}

function SlideBlock(obj) {
	if(!obj) return;
	obj.style.display = (obj.offsetHeight == 0) ? 'block' : 'none';
	return false;
}

/************************************************************************

*************************************************************************/
function ltrim( source ){
	var index = 0;
	while( source.charAt(index) == ' ' ) index++;
	return source.substr(index);
}

function rtrim( source )	{
	if( source.length == 0 )
		return source;
	var index = source.length - 1;
	while( source.charAt(index) == ' ' ) index--;
	return source.substring(0, index + 1);
}

function trim( source )	{
	return ltrim(rtrim(source));
}

/************************************************************************

*************************************************************************/
function emailCheck(email) {
	var emailReg = '^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$';
	var regex = new RegExp(emailReg);
	return regex.test(email);
}

function phoneCheck(phone) {
	//var phoneReg = '^(\+?\\d)*\s*(\(?\\d{3}\)?\\s*)*\\d{3}(-|\\s|.)?\\d{2}(-|\\s|.)?\\d{2}$';
	//var phoneReg = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	//var regex = new RegExp(phoneReg);
	//return regex.test(phone);
	return true;
}

function ConfirmHandle(message) {
	return window.confirm(message);
}


