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);
	    }
	    
		
	}

 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;
 }
 
 
 function showHideObject(object_id, close_object_id, delete_info_message){
	
	if(close_object_id != null){
		if(document.getElementById(close_object_id).style.display == 'block'){
			document.getElementById(close_object_id).style.display = 'none'; 
		}
	}

	if(document.getElementById(object_id).style.display == 'block'){
		document.getElementById(object_id).style.display = 'none'; 
	}else{
	    document.getElementById(object_id).style.display = 'block';
	}
	
	if(delete_info_message == true){
		if(document.getElementById('info_message') != null){
			document.getElementById('info_message').innerHTML = '';
		}
	}
}
 function showObject(object_id, delete_info_message){
	
	if(document.getElementById(object_id) != null){
		if(document.getElementById(object_id).style.display == 'none'){
			document.getElementById(object_id).style.display = 'block'; 
		}
	}
	
	if(delete_info_message == true){
		if(document.getElementById('info_message') != null){
			document.getElementById('info_message').innerHTML = '';
		}
	}
}
 function hideObject(object_id, delete_info_message){
	
	if(document.getElementById(object_id) != null){
		if(document.getElementById(object_id).style.display == 'block'){
			document.getElementById(object_id).style.display = 'none'; 
		}
	}
	
	if(delete_info_message == true){
		if(document.getElementById('info_message') != null){
			document.getElementById('info_message').innerHTML = '';
		}
	}
}


function reset_form(form_param, ignore_elements, is_form_name){
	//alert(ignore_elements);
	if(undefined == ignore_elements.length){
		ignore_elements = array('');
	}
	var form = form_param;
	if(is_form_name){
		
		if(document.getElementById(form_param) != null){
			form = document.getElementById(form_param);	
		}else{
			form = document.getElementsByName(form_param);
		}
	}

	for(i=0; i<form.length; i++){
		   //alert(form[i].type+'---'+form[i].name);
		  //for(var j=0; j<ignore_elements.length; j++){
			  	
			   //if(ignore_elements[j] != form[i].name){alert(form[i].name);
			   if(ignore_elements.indexOf(form[i].name) == -1){
			  		if(form[i].type == 'text' || form[i].type == 'textarea'){
			   			form[i].value = "";
			   		}else if(form[i].type == 'select-one'){
			   		
			   		
				   		form[i].value = "";
				   		if(form[i].value != ""){
				   			form[i].value = 0;
				   		}
			   					   		
			   		}
			   		
			   } 
		  //}
	}
}
function changeValue(object_id, value){
	if(document.getElementById(object_id) != null){
		document.getElementById(object_id).value = value; 
	}
}



 

