/*
* $Id: functions.js,v 1.1 2006/04/26 11:56:38 razvan.stanga Exp $
*/

// init
_browser = getBrowser ();
detectFlashVersion ();

function checkCookie () {

var acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookies=yes';
    if(document.cookie.indexOf('acceptsCookies=yes') != -1) {
	acceptsCookies = true;
    }
    return acceptsCookies;
} else {
  acceptsCookies = true;
  return acceptsCookies;
}
}


function setCookie (name, value, hours, path, domain, secure) {
    if ( checkCookie () == true ) {
        name = 'b'+name;
	var not_NN2 = (navigator && navigator.appName
		       && (navigator.appName == 'Netscape')
		       && navigator.appVersion
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) {
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) {
		var numHours = hours;
	    } else if (typeof(hours) == 'number') {
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':'');
    }
}


function getCookie(name) {
    if(document.cookie == '') {
		return false;
    } else {
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) {
	    	firstChar += name.length + 1;
	    	lastChar = theBigCookie.indexOf(';', firstChar);
	    	if(lastChar == -1) lastChar = theBigCookie.length;
	    	return unescape(theBigCookie.substring(firstChar, lastChar));
		} else {
	    	return false;
		}
    }
}

function getBrowser () {
	var browserName = navigator.appName;
	if ( browserName.search ('Internet Explorer') != -1  ) {
		return 'Internet Explorer';
	} else if ( browserName.search ('Netscape') != -1 ) {
        return 'Netscape';
	} else if ( browserName.search ('Opera') != -1 ) {
        return 'Opera';
	} else if ( browserName.search ('Firefox') != -1 ) {
        return 'Firefox';
	} else {
		return 'Other';
	}
}

function setVisibility (n, act) {
	try {
	if ( getBrowser () == 'Internet Explorer' ) {
        var selOp = eval ("document.all.div_"+n+"");
	} else {
        var selOp = eval ("document.getElementById ('div_"+n+"');");
	}
	//var selOp = eval ("document.all.div_"+n+"");
	if ( act == 't' ) {
       	selOp.style.display='';
	} else if ( act == 'f' ) {
		selOp.style.display='none';
	}
	}
	catch (ex) {}
}

function toNumber ( nr ) {
	return parseFloat ( nr );
}

function addBR ( field, f ) {
	
	txt = getValue (field, f);
	i = 1;
	while ( txt.search ('[:::]') != -1 ) {
		txt = txt.replace ("[:::]", '\r\n');
		i++;
		if ( i >= 150 ) {
			break;
		}
	}
	setValue (field, f, txt);
}

function goTO ( url, val ) {
	if ( val ) {
		window.location=url;
	}
}

function detectFlashVersion () {
	// flash version detection
	var flash = new Object();

	flash.installed = false;
	flash.version='0.0';

	if (navigator.plugins && navigator.plugins.length)
	{
		for (x=0; x<navigator.plugins.length; x++)
		{
			if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1)
			{
				flash.version=navigator.plugins[x].description.split('Shockwave Flash ')[1];
				flash.installed = true;
				break;
			}
		}
	} else if (window.ActiveXObject) {
		for (x=2; x<10; x++)
		{
			try
			{
				oFlash=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+x+"');");
				if (oFlash)
				{
					flash.installed = true;
					flash.version=x+'.0';
				}
			}
			catch(e) {}
		}
	}

	flash.ver = (flash.installed && parseInt(flash.version) >= 2) ? parseInt(flash.version) : false;
	if ( flash.ver < 8 ) {
		goTO ('http://www.fengpui.ro/error.html', 1);
	}
}
