var currentUser = "";

function showOrHideElement(obj){
  document.getElementById(obj).style.display = document.getElementById(obj).style.display == "block" ? "none" : "block";
}

function clearText(obj, lang){
	var strDefaultDate = lang == "pt-BR" ? "DD/MM/AAAA" : "YYYY-MM-DD";
	if(document.getElementById(obj).value == strDefaultDate){
		document.getElementById(obj).value = "";
		document.getElementById(obj).style.color = "#2C5700";
	}
}

function setText(obj, lang){
	var strDefaultDate = lang == "pt-BR" ? "DD/MM/AAAA" : "YYYY-MM-DD";
	if(document.getElementById(obj).value == ""){
		document.getElementById(obj).value = strDefaultDate;
		document.getElementById(obj).style.color = "#B5CF8E";
	}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id);
    if (object){
      object.style.opacity = (opacity / 100);
      object.style.MozOpacity = (opacity / 100);
      object.style.KhtmlOpacity = (opacity / 100);
      object.style.filter = "alpha(opacity=" + opacity + ")";
    }
}

function hideItem(id) {
    var object = document.getElementById(id);
    if (object){
        object.style.display = 'none';
    }
}

function showNotice(id) {
	var object = document.getElementById(id);
	if (object){
		document.getElementById(id).style.display = 'block'
		opacity(id, 0, 100, 500);
		window.setTimeout('javascript:opacity(\'' + id + '\', 100, 0, 500);', 5000);
		window.setTimeout('javascript:hideItem(\'' + id + '\');', 5500);
	}
}

function numbersonly(myfield, e, dec){
	var key, keychar;

	if(window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;

	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) || (key ==45) || (key==47))
		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}

function handleHour(obj){
	if(obj.checked){
		//Show de Solution div
		document.getElementById('ticket-submit-close').style.display = 'block'
		//Hide the Comment div
		document.getElementById('ticket-submit-comment').style.display = 'none'
		//Show the Solution label
		document.getElementById('solution-detail').style.display = 'block';
		//Hide the Comment label
		document.getElementById('comment-detail').style.display = 'none';

		//If the textArea comment_textcomment isn't blank, copy its content
		//to the textArea closeticket_solution
		if(document.getElementById('comment_textcomment').value != ''){
			document.getElementById('closeticket_solution').value = document.getElementById('comment_textcomment').value;
		}
	}
	else{
		//Show de Solution div
		document.getElementById('ticket-submit-close').style.display = 'none'
		//Hide the Comment div
		document.getElementById('ticket-submit-comment').style.display = 'block'
		//Show the Solution label
		document.getElementById('solution-detail').style.display = 'none';
		//Hide the Comment label
		document.getElementById('comment-detail').style.display = 'block';

		//If the textArea closeticket_solution isn't blank, copy its content
		//to the textArea comment_textcomment
		if(document.getElementById('closeticket_solution').value != ''){
			document.getElementById('comment_textcomment').value = document.getElementById('closeticket_solution').value;
		}
	}
}

/* Flash Notice Customization */
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
  
	el.floatIt=function()
	{  
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
		document.documentElement && document.documentElement.clientWidth ?
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0)
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
} 

function FormattedFlashNotice(msg){
	document.getElementById("flash").innerHTML= msg;

	JSFX_FloatDiv("flash", 10,0).floatIt();
  
	jQuery("#flash").slideDown("slow");
	document.getElementById("flash").style.display="block";

	setTimeout(function(){
		jQuery("#flash").slideUp("slow", function () {
			document.getElementById("flash").style.display="none";
			document.getElementById("flash").innerHTML="";
		});
	}, 3000);
}