function popup_upload_file(parameters)
	{
	{LeftPosition=(screen.width)?(screen.width-750)/2:100;TopPosition=(screen.height)?(screen.height-350)/2:100;}
	self.name = 'opener';
	remote = open('scripts/Upload_file.asp?' + parameters, 'remote', 'width=750,height=350,top=' + TopPosition + ',left=' + LeftPosition + ',location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no,fullscreen=no');
 	remote.focus();
	}

function limite(zone,max)
	{
	if(zone.value.length>=max){zone.value=zone.value.substring(0,max);}
	}

function calendar(formname,currentdate)
	{
	{LeftPosition=(screen.width)?(screen.width-250)/2:100;TopPosition=(screen.height)?(screen.height-190)/2:100;}
	self.name = 'opener';
	remote = open('scripts/calendar.asp?name=' + formname + '&sdate=' + currentdate, 'remote', 'width=250,height=190,top=' + TopPosition + ',left=' + LeftPosition + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,fullscreen=no');
 	remote.focus();
	}

function selectdate(formname,currentdate)
	{
	{LeftPosition=(screen.width)?(screen.width-250)/2:100;TopPosition=(screen.height)?(screen.height-190)/2:100;}
	self.name = 'opener';
	remote = open('scripts/chooseDate.asp?name=' + formname + '&sdate=' + currentdate, 'remote', 'width=250,height=190,top=' + TopPosition + ',left=' + LeftPosition + ',location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no,fullscreen=no');
 	remote.focus();
	}

function showhide(id)
	{
		var itm = null;
		if (document.getElementById) {
			itm = document.getElementById(id);
		} else if (document.all){
			itm = document.all[id];
		} else if (document.layers){
			itm = document.layers[id];
		}
		if (itm.style) {
			if (itm.style.display == "none") { itm.style.display = ""; }
			else { itm.style.display = "none"; }
		}
	}

function showhideconfig(id,show)
		{
			var itm = null;
			if (document.getElementById) {
				itm = document.getElementById(id);
			} else if (document.all){
				itm = document.all[id];
			} else if (document.layers){
				itm = document.layers[id];
			}
			if (itm.style) {
				if (itm.style.display == "none" && show == 1) 
					{ 
					itm.style.display = ""; 
					}
				if (itm.style.display == "" && show == 0) 
					{ 
					itm.style.display = "none"; 
					}
			}
		}
		
function checkdates(form)
		{
		if (form.start.value == ''){
			alert('Please enter a start date.');
			return false;
			form.start.focus();
			}
		if (form.end.value == ''){
			alert('Please enter an end date.');
			return false;
			form.end.focus();
			}
		}
		
function showhelp(helpfile,bookmark)
		{
		self.name = 'opener';
		helpwin = open('hlp' + helpfile + '.htm#' + bookmark, 'helpwin', 'width=400,height=500,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,fullscreen=no');
 		helpwin.focus();
		}
		
/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function ExpandMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById("masterdiv").style.display="block";
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

function ppdisplay_file(filename,nwidth,nheight)
	{
	{LeftPosition=(screen.width)?(screen.width-nwidth)/2:100;TopPosition=(screen.height)?(screen.height-nheight)/2:100;}
	self.name = 'opener';
	remote = open(filename, 'remote', 'width=' + nwidth + ',height=' + nheight +',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no,fullscreen=no');
 	remote.focus();
	}
	
function HighLightTR(backColor,textColor)
{  
	if(typeof(preEl)!='undefined') 
	{
		preEl.bgColor=orgBColor; 
		try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
	} 
	var el = event.srcElement;
	el = el.parentElement;
	orgBColor = el.bgColor;
	orgTColor = el.style.color;
	el.bgColor=backColor;
	
	try{ChangeTextColor(el,textColor);}catch(e){;}
	preEl = el; 
}

function ChangeTextColor(a_obj,a_color)
	{  ;
		for (i=0;i<a_obj.cells.length;i++)
		{
			a_obj.cells(i).style.color=a_color; 
		}
	}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

var doImage=doImage;var TType=TType;
function mhHover(tbl,idx,cls){var t,d;if(document.getElementById)t=document.getElementById(tbl);else t=document.all(tbl);if(t==null)return;if(t.getElementsByTagName)d=t.getElementsByTagName("TD");else d=t.all.tags("TD");if(d==null)return;if(d.length<=idx)return;d[idx].className=cls;}
function footerjs(doc){if(doImage==null){var tt=TType==null?"PV":TType;doc.write('<layer visibility="hide"><div style="display:none"><img src="http://c.microsoft.com/trans_pixel.asp?source=www&TYPE=' + tt + '&p=windows_sfu" width=0 height=0 hspace=0 vspace=0 border=0 /></div></layer>');}}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//##################################
// jQuery functions
//##################################

function toggle_home(rowid,state,numrecs){
	//toggle indicator for current and neighbour
	var cur_indicator_id, cur_indicator_neighbour,cur_indicator_value;
	var cur_display, cur_display_neighbour;
	
	if (state == 'active'){
		cur_indicator_id = '#toggle_tck_'+rowid;
		cur_indicator_neighbour = '#toggle_tck_p_'+rowid;
		cur_display = '#toggle_disp_'+rowid;
		cur_display_neighbour = '#toggle_disp_p_'+rowid;
	} else {
		cur_indicator_id = '#toggle_tck_p_'+rowid;
		cur_indicator_neighbour = '#toggle_tck_'+rowid;
		cur_display = '#toggle_disp_p_'+rowid;
		cur_display_neighbour = '#toggle_disp_'+rowid;
	}
	
	//preserve current indicator value
	cur_indicator_value = $(cur_indicator_id).html();
	
	//collapse all others
	$('.hidden-row-ajax').hide();
	$('.hidden-row-ajax').removeClass('rowDisplayed');
	
	$('.toggle_display').removeClass("selected-link");
	$('.toggle_indicator').html("+");
	
	if (cur_indicator_value=='+'){
		
		$(cur_indicator_id).html('-');
		$(cur_indicator_neighbour).html('+');
		
		//toggle bold current link
		$(cur_display).toggleClass("selected-link");
		$(cur_display_neighbour).removeClass("selected-link");
		
		//fetch results via ajax
		fetch_home_res(rowid,state,numrecs);
		
		//show row if hidden
		if (!$("#details_row_"+rowid).hasClass('rowDisplayed')) {
			$("#details_row_"+rowid).show();
			$("#details_row_"+rowid).addClass('rowDisplayed');
		}
		
	} else {
		$(cur_indicator_id).html('+');
		$(cur_indicator_neighbour).html('+');
		
		//toggle bold current link
		$(cur_display).removeClass("selected-link");
		$(cur_display_neighbour).removeClass("selected-link");
		
		//hide row if shown
		if ($("#details_row_"+rowid).hasClass('rowDisplayed')) {
			$("#details_row_"+rowid).hide();
			$("#details_row_"+rowid).removeClass('rowDisplayed');
		}
	}
}

function fetch_home_res(rowid,state,numrecs){
	var div_details_id = '#details_div_'+rowid;
	
	$(div_details_id).block({
		message: '<h4><img src="images/spinner.gif" />&nbsp;&nbsp;Loading '+state+' tickets</h4>',
		css: { border: '0px solid #F5911F', width: '200px', padding: '10px'}
	});
	
	$.ajax({
		type:"POST",
		url:"ajax/get_tickets.asp",
		async:false,
		data: "type="+state+"&tab_id="+rowid+"&numrec="+numrecs+"&nocache="+new Date().getTime(),
		success: function(msg) {
			if (msg!='') {
				//deblocheaza
				$(div_details_id).unblock();
				 //afiseaza rezultatele
				$(div_details_id).html(msg);
			}
		},
		error: function(msg) {
			$(div_details_id).unblock();
			alert("An error occured while fetching "+state+" tickets, please refresh this window and try again!");
		}
	});
}

function check_lock_status(tname, record_id, user_id, screen_id){
	$("#main-content-area").block({
		message: '<h4><img src="images/spinner.gif" />&nbsp;&nbsp;Please wait, loading ...</h4>',
		css: { 
			border: '2px solid #F5911F', 
			width: '230px', 
			padding: '10px',
			top:'100px'
		},
		overlayCSS: { 
        	backgroundColor: '#fff', 
        	opacity:         0.6 
	    },
	    centerY: false
	});
	
	$.ajax({
		type:"POST",
		url:"ajax/check_lockstatus.asp",
		data: "tname="+tname+"&record_id="+record_id+"&user_id="+user_id+"&nocache="+new Date().getTime(),
		success: function(msg) {
			if (msg!='') {
					//deblocheaza
					$("#main-content-area").unblock();
					if (msg == '0'){	//if row is not locked, redirect
						location='default.asp?r='+screen_id+'&edit='+record_id;
					} else {	//else, show warning
						alert(msg);
					}
				}
		},
		error: function(msg) {
			$("#main-content-area").unblock();
			alert("An error occured while checking ticket status, please refresh this window and try again!");
		}
	});	
}

function save_forward_ticket(idcat,idrec,defemail){
	var frwd = $('#frwd').val();
	
	$("#main_forward_content").block({
		message: '<h4><img src="images/spinner.gif" />&nbsp;&nbsp;Please wait, saving ...</h4>',
		css: { border: '2px solid #F5911F', width: '230px', padding: '10px'}
	});
	
	$.ajax({
		type:"POST",
		url:"ajax/forward_ticket_save.asp",
		data: "idcat="+idcat+"&idrec="+idrec+"&iduser="+frwd+"&nocache="+new Date().getTime(),
		success: function(msg) {
			if (msg!='') {
					//deblocheaza
					$("#main_forward_content").unblock();
					if (msg == '0'){	//data saved, change traffic light and close this box
						change_traffic_light(idcat,idrec,defemail);
					} else {	//else, show warning
						alert(msg);
					}
				}
		},
		error: function(msg) {
			$("#main_forward_content").unblock();
			alert("An error occured while forwarding ticket, please refresh this window and try again!");
		}
	});	
	
	return false;	
}

function change_traffic_light(idcat,idrec,defemail){
	$.ajax({
		type:"POST",
		url:"ajax/forward_ticket_retrieve.asp",
		data: "idcat="+idcat+"&idrec="+idrec+"&defemail="+defemail+"&nocache="+new Date().getTime(),
		success: function(msg) {
			if (msg!='') {
					if (msg == 'error'){	//data saved, change traffic light and close this box
						alert("An error occured while changing current traffic lights, please refresh this window and try again1!");
					} else {	//else, show warning
						$("#traf_id_"+idrec).html(msg);
						tb_init('#thk_dynamic_'+idrec);	//re-initialize thickbox for last updated element
						tb_remove();
					}
				}
		},
		error: function(msg) {
			alert("An error occured while changing current traffic lights, please refresh this window and try again2!");
		}
	});	
}

function searchTickets(u_id,u_ad){
	
	var search = $('#search_for').val();
	var r = true;
	var t = '';
	
	if (search == null || search.length <1) {
	    t +="Please specify a ticket number to search for!\n";
	    r = false;    
	}
	
	if (t!='' || !r) {
	    alert(t);
	    return false;
	} else {
		
		$("#display-homepage").block({
			message: '<h4><img src="images/spinner.gif" />&nbsp;&nbsp;Please wait, saving ...</h4>',
			css: { border: '2px solid #F5911F', width: '230px', padding: '10px'}
		});
		
		$.ajax({
			type:"POST",
			url:"ajax/search_tickets.php",
			data: "u_id="+u_id+"&u_ad="+u_ad+"&search="+search+"&nocache="+new Date().getTime(),
			success: function(msg) {
				if (msg!='') {
						//deblocheaza
						$("#display-homepage").unblock();
						$("#display-homepage").html(msg);
					}
			},
			error: function(msg) {
				$("#display-homepage").unblock();
				alert("An error occured while searching tickets, please try again later!");
			}
		});	
		return false;
	}
}

function displayMngUserButton(type){
	if (type=="show"){
		$("#mnguser").show();
	} else {
		$("#mnguser").hide();
	}
}