var url;


/*
 Example 1: confirm_action('block','User','Tom')
   action_name: block
   object_type: User
   object_name: Tom
 
 Example 2: confirm_action('delete','Category','Cars')
   action_name: delete
   object_type: Category
   object_name: Cars
*/
function confirm_action(action_name,object_type,object_name){
  if(action_name == "") action_name = "perform the selected operation on";
  action_object = "";
  if(object_type != ""){
    action_object = "the " + object_type;
    if(object_name != "") action_object = action_object + " ";
  }
  if(object_name != "") action_object = action_object + '"' + object_name + '"';
  if(action_object == "") action_object = "the current record";
  return confirm("Are you sure \nyou want " + action_name + " " + action_object + "?");
}

function clickClear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickRecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function LocationVisibility(Show,Hide,thediv,thearr){
  what = document.getElementById(thediv).style.display == 'none' ? 'block' : 'none' ;
  document.getElementById(thediv).style.display=what;
  if (what == 'none'){
	  document.getElementById('AdsLink').innerHTML = Show;
	  document.getElementById(thearr).src = url + 'images/arrow1.gif';
  }
  else{
    document.getElementById('AdsLink').innerHTML = Hide;
    document.getElementById(thearr).src = url + 'images/arrow2.gif';
  }
  return false;
}

var display_hours;
var display_minutes;
var display_seconds;
function count_down_timer(ticket_id, hours, minutes, seconds){
		
		if(seconds > 0){
			seconds--;
		}else if(seconds == 0) {
		
			if(minutes > 0){
				seconds = 59;
				minutes--;
			}else if(minutes == 0){
			
				if(hours > 0){
					minutes = 60;
					hours--;
				}else if(hours == 0){
					hours = 0;
				}
			}
			
		}
		
		if(hours < 10){
			display_hours = '0' + hours;
		}else{
			display_hours = hours;
		}
		if(minutes < 10){
			display_minutes = '0' + minutes;
		}else{
			display_minutes = minutes;
		}
		if(seconds < 10){
			display_seconds = '0' + seconds;
		}else{
			display_seconds = seconds;
		}
		
		document.getElementById('count_down_'+ticket_id).innerHTML = display_hours + 'h:' + display_minutes + 'm:' +  display_seconds + 's';		
		
		if(hours != 0 || minutes != 0 ||  seconds != 0){
	    	setTimeout("count_down_timer("+ticket_id+", "+hours+", "+minutes+", "+seconds+");", 1000);
	    }
	    
		
	}
	
	
var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

 function generate_security_code(){
 		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 10;
		var random_code = '';
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			random_code += chars.substring(rnum,rnum+1);
		}
		return random_code;
 }
 

		
 
 var readyState = true;
 var readyTimerState;
 var last_xmlhttp_status;
 
 function getValueFromUrl(url, set_object_id){
  
  var xmlhttp=false;
  try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e) {
	    xmlhttp = false;
	  }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 xmlhttp = new XMLHttpRequest();
  }
  
  var get_url = '';
			
	get_url = url + "&sec_code="+generate_security_code();
	if(readyState){
		readyState = false;
		var response_text = '';	
		xmlhttp.open("GET", get_url, true);
			 xmlhttp.onreadystatechange = function() {	
				if (xmlhttp.readyState == 4) {
					if(xmlhttp.status == 200){
						response_text = xmlhttp.responseText;
						document.getElementById(set_object_id).innerHTML = response_text;
					}
				}else if(xmlhttp.readyState == 0){
					alert("Sorry there was a problem while executing your request!!\nPlease refresh your page.");
				}
				last_xmlhttp_status = xmlhttp.readyState;
				
			};
			
		xmlhttp.send(null);
		readyState = true;
	}else{
		clearTimeout(readyTimerState);
			if(!readyState){
				readyTimerState = setTimeout("getValueFromUrl('"+url+"');", 4000);
			}else if(last_xmlhttp_status == 0){
				alert("Sorry there was a problem while executing your request!!\nPlease refresh your page.");
			}
	}

 }
 

