function showAlexa(domainExtension)
{
	document.write('<script type="text/javascript" src="http://xslt.alexa.com/site_stats/js/t/a?url=www.u-trade.'+domainExtension+'"></script>');
}

function showTraficRo()
{
	document.write('<noscript><a href="http://www.trafic.ro/top/?rid=utrade" target="_blank"><img src="http://log.trafic.ro/cgi-bin/pl.dll?rid=utrade" width="88" height="31" border="0" alt="Trafic Ranking" title="Trafic Ranking" /></a></noscript>');
}

function initialization()
{
	document.getElementById('preloader').style.display='none';
}

function CreateBookmarkLink()
{
	if (window.sidebar)
	{
		//Firefox
		window.sidebar.addPanel(document.title, location.href, "U-Trade");
	}
	else if (document.all)
	{
		//IE
		if (window.external)
			window.external.AddFavorite(document.title, location.href);
		else
			alert("Permission has been denied by your browser");
	}
	else if (window.opera && window.print)
	{
		// Opera
		var mbm = document.createElement('a');
			mbm.setAttribute('rel','sidebar');
			mbm.setAttribute('href',location.href);
			mbm.setAttribute('title',document.title);
			mbm.click();
	}
}

function CreateHomePage(obj, FFErr)
{
	if (window.sidebar)
	{
		//Firefox
		obj.style.behavior = 'url(#default#homepage)';
		
		if (obj.setHomePage)
			obj.setHomePage(location.href);
		else
			alert(FFErr);
	}
	else if (document.all)
	{
		//IE
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(location.href);
	}
	else if (window.opera && window.print)
	{
		// Opera
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(location.href);
	}
}

function checkpasswords(pass1Err, pass2Err, pass3Err, pass4Err)
{
	pass1 = document.getElementById("password_reset")
	pass2 = document.getElementById("password_reset2")
	if (pass1.value=="")
	{
		alert(pass1Err+" !")
		pass1.focus();
		return false;
	}
	if (pass2.value=="")
	{
		alert(pass2Err+" !")
		pass2.focus();
		return false;
	}
	if ((pass1.value).length<5)
	{
		alert(pass3Err+" !")
		pass1.focus();
		return false;
	}
	if (pass1.value!=pass2.value)
	{
		alert(pass4Err+" !")
		pass2.focus();
		return false;
	}
}

function repostPreloader()
{
	document.getElementById("preloader").style.left = parseInt(document.body.offsetWidth / 2)+"px";	
}

function setFontSize(container, sizeInPixels)
{
	document.getElementById(container).style.fontSize = sizeInPixels+'px';
}


// sidebar
function showOpi()
{
	document.write('<img border="0" src="http://opi.yahoo.com/online?u=utrade_org&amp;m=g&amp;t=5=us" onclick="document.location=\'ymsgr:sendim?utrade_org\'" class="toolboxOpiImage" width="12" height="12" alt="Contact U-Trade" title="Contact U-Trade" id="item_opi" onmouseover="showOverLayer(this.id, \'Contact U-Trade\')" onmouseout="hideOverLayer()" />');	
}

function getElementTop(Elem)
{
	if(document.getElementById)
		var elem = document.getElementById(Elem);
	else if (document.all)
		var elem = document.all[Elem];
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null)
	{
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function getElementLeft(Elem)
{
	if(document.getElementById)
		var elem = document.getElementById(Elem);
	else if (document.all)
		var elem = document.all[Elem];
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null)
	{
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

var gadgetsHeight = 0;
var toolbarHeight = 670;
var isControlOpen = false;

function showOverLayer(myID, text)
{
	if (isControlOpen==false)
	{
		document.getElementById("OverLayer").style.display='';
		document.getElementById("OverLayer").style.top = getElementTop(myID)+"px";
		document.getElementById("OverLayer").style.left = (getElementLeft(myID)+40)+"px";
		document.getElementById("OverLayer").innerHTML = text;
	}
}

function hideOverLayer()
{
	if (isControlOpen==false)
		document.getElementById("OverLayer").style.display='none';
}

function showHideGadgets()
{
	if (document.getElementById("gadgetsContainer").style.display=='')
	{
		hideGadgets();
	}
	else
	{
		document.getElementById("gadgetsContainer").style.display = '';
		document.getElementById("gadgetsContainer").style.height = "0px";
		showGadgets();
	}
}
function showGadgets()
{
	if (gadgetsHeight < toolbarHeight)
	{
		gadgetsHeight = gadgetsHeight + 5;
		document.getElementById("gadgetsContainer").style.height = gadgetsHeight+"px";
		setTimeout("showGadgets()", 1);
	}
}
function hideGadgets()
{
	if (gadgetsHeight > 0)
	{
		gadgetsHeight = gadgetsHeight - 5;
		document.getElementById("gadgetsContainer").style.height = gadgetsHeight+"px";
		setTimeout("hideGadgets()", 1);
	}
	else
		document.getElementById("gadgetsContainer").style.display = 'none';	
}

function showReportABug(DetaliiText, ReportBugText, CancelText)
{
	isControlOpen = true;
	var content = '<div style="width:400px;"><div style="float:left;width:100px;">'+DetaliiText+':</div>';
	content += '<div style="float:left;width:300px;"><textarea style="width:290px;" id="report_bug" name="report_bug"></textarea></div></div>';
	content += '<div style="width:400px;"><div style="float:left;width:100px;height:10px;"></div>';
	content += '<div style="float:left;width:300px;"><input type="button" value="'+ReportBugText+'" onclick="activateReportBug()" /><input type="button" onclick="document.getElementById(\'OverLayer\').style.display=\'none\';isControlOpen = false" value="'+CancelText+'" /></div></div>';
	document.getElementById("OverLayer").innerHTML = content;
}




var responseSuccessReportABug = function(o)
{
	document.getElementById("tlb_box_3").innerHTML = o.responseText
};

var responseFailureReportABug = function(o)
{ }
var callbackReportABug =
{
	success:responseSuccessReportABug,
	failure:responseFailureReportABug
};

function activateReportBug(msgDetailsError, msgEmailError)
{
	if (document.getElementById("report_bug").value=="")
	{
		alert(msgDetailsError+" !");
		document.getElementById("report_bug").focus();
		return false;
	}
	if (document.getElementById("bug_report_email").value=="")
	{
		alert(msgEmailError+" !");
		document.getElementById("bug_report_email").focus();
		return false;
	}

	YAHOO.util.Connect.setForm("report_a_bug_frm");
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/inc/gadgets_controller.php?action=report_bug', callbackReportABug);
}



function showHoroscop()
{
	isControlOpen = true;
	showHint_ultimate('/inc/gadgets_controller.php?action=horoscope&myvar=nothing', 'OverLayer');	
}

function showWeather()
{
	isControlOpen = true;
	showHint_ultimate('/inc/gadgets_controller.php?action=weather&myvar=nothing', 'OverLayer');	
}

function showRateExchange()
{
	isControlOpen = true;
	showHint_ultimate('/inc/gadgets_controller.php?action=exchange_rate&myvar=nothing', 'OverLayer');	
}
// sidebar


function snapIn(jumpSpaces,position) 
{ 
	var msg = "U-Trade";
	var out = ""; 
	for (var i=0; i<position; i++)
		{out += msg.charAt(i);} 
	for (i=1;i<jumpSpaces;i++)
		{out += " ";} 
	out += msg.charAt(position); 
	window.status = out; 
	if (jumpSpaces <= 1)
	{ 
		position++; 
		if (msg.charAt(position) == ' ')
			{position++;};
		jumpSpaces = 100-position;
	} 
	else if (jumpSpaces >  3) 
		{jumpSpaces *= .09;} 
	else
		{jumpSpaces--;} 
	
	if (position != msg.length) 
	{
		var cmd = "snapIn(" + jumpSpaces + "," + position + ")"; 
		window.setTimeout(cmd,10); 
	}
	return true 
}
snapIn(50,0)

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {IsNumber = false;}
      }
	return IsNumber;
}

function showHiddenInput(hiddenInput, selectValue)
{
	if (selectValue == "X")
		document.getElementById(hiddenInput).style.display = 'block';
	else
		document.getElementById(hiddenInput).style.display = 'none';
}

function validateUserRegistration(language)
{
	__messages_ro = ["Completati username", "Completati prenumele", "Completati numele", "Completati parola", "Completati parola de verificare", "Completati adresa de e-mail"];
	__messages_en = ["Fill username field", "Fill firstname field", "Fill lastname field", "Insert password", "Re-enter password", "Insert e-mail address"];

	__type		  = ["", "", "", "", "", ""];
	__components  = ["usernameRegistration", "firstname", "lastname", "password", "password2", "emailRegistration"];
	__minLength   = ["3", "2", "2", "5", "5", "6"];
	__minField_ro = ["username", "prenume", "nume", "parola", "verificare parola", "e-mail"];
	__minField_en = ["username", "firstname", "lastname", "password", "verify password", "e-mail"];

	for (i=0;i<__components.length;i++)
	{
		if (document.getElementById(__components[i]).value == __type[i])
		{
			if (language == 'ro') alert(__messages_ro[i]);
			if (language == 'en') alert(__messages_en[i]);
			document.getElementById(__components[i]).focus();
			return false;
		}
		if (__minLength[i] != "")
		{
			if ((document.getElementById(__components[i]).value).length < __minLength[i])
			{
				if (language == 'ro') alert("Campul "+__minField_ro[i]+" nu pare a fi corect completat.");
				if (language == 'en') alert("The "+__minField_en[i]+" field doesn't look to be correct.");
				document.getElementById(__components[i]).focus();
				return false;
			}
		}
	}

	
	if ((document.getElementById("usernameRegistration").value).indexOf(" ") != -1)
	{
		if (language=="ro")
			alert ("Numele de utilizator nu poate contine spatii !");
		if (language=="en")
			alert ("Username cannot contain spaces !");
		
		document.getElementById("usernameRegistration").focus();
		return false;
	}

	
	if ((document.getElementById("password").value).indexOf(" ") != -1)
	{
		if (language=="ro")
			alert ("Parola nu poate contine spatii !");
		if (language=="en")
			alert ("The password cannot contain spaces !");
		
		document.getElementById("password").focus();
		return false;
	}


	sir = document.getElementById("emailRegistration").value;
	tmp = sir.indexOf("@", 1);
	tmp2 = sir.indexOf(".", 1);
	if (tmp == -1) {
		if (language == 'ro') alert("Adresa de e-mail incorecta !");
		if (language == 'en') alert("E-mail address is incorect !");
		document.getElementById("emailRegistration").focus();
		return false;
	}
	if (tmp2 == -1) {
		if (language == 'ro') alert("Adresa de e-mail incorecta !");
		if (language == 'en') alert("E-mail address is incorect !");
		document.getElementById("emailRegistration").focus();
		return false;
	}

	if (document.getElementById("password").value != document.getElementById("password2").value) {
		if (language == 'ro') alert("Parolele nu coincid !");
		if (language == 'en') alert("Passwords doesn't match !");
		document.getElementById("password2").focus();
		return false;
	}
	
	if (document.getElementById("terms_check_control").checked != true)
	{
		if (language == 'ro') alert("Trebuie sa fii de acord cu termenii si conditiile noastre pentru a putea continua inregistrarea !");
		if (language == 'en') alert("You must agree our terms and conditions before you continue !");
		document.getElementById("terms_check_control").focus();
		return false;
	}
}