// JavaScript Document

function gen_rand_color(field){
	
	var color_code = Array(0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F");
	
	var rand_num = 0;
	
	var color_string = "";
	
	while(color_string.length < 6){
		rand_num = Math.floor(Math.random() * (15 + 1));
		color_string += color_code[rand_num];
	}
	
	return color_string;
	
}

function oq(me,you){
	
	if(me.value == "Other"){you.disabled = false;}
	else {you.disabled = true;}
}

function confirm_delete(){
		
		input_box = confirm("Are you sure?");
		
		if (input_box==true)
		{ 
			return true;
		}
		
		else
		{
			return false;
		}

}

function check_is_selected(form){

	var i = 0;
	var signal = false;
	
	for(i=0 ; i< form.length; i++){
		if(form.elements[i].id.indexOf("edit_record") != -1){
			if(form.elements[i].checked == true)
			 signal = true;
		}
	}

	if(!signal){
		alert("Please select at least 1 record.");
		return false;
	}
	else{
		if(confirm_delete()){
			return true;
		}
		else{
			return false;
		}
	}
}

function redirection_select(me,base_url){
	
	var selIndex= me.options.selectedIndex;
	var selValue = me.options[selIndex].value;
	var endstring = base_url.indexOf("?");
	var temparr = new Object();
	//temparr["filter"] = '1';
	
	
	if(selValue != 'null2' && selValue != "default"){
		temparr['content'] = selValue;
		temparr.length = 1;
	
		
		
		window.location.href = renew_get_var(base_url,temparr);
	}
	/*
	if(endstring == -1){
		base_url = base_url + "?";
		endstring = base_url.length;
	}else{
		base_url = base_url + "&";
		endstring = base_url.length;
	}
	
	
	var new_url = base_url.substring(0,endstring);
	
	window.location.href = new_url+ "filter=1&" + selValue;*/
	//return window.document.href= base_url+;
	
}

function check_radio_selected(form){
		
		if (form.upload_to[2].checked==true){
			form.userlist.disabled = false;	
		}else{
			form.userlist.disabled = true;	
		}
		

}

function select_all(input, frm){
	
	
		// loop through all elements
		for (i=0; i<frm.length; i++) 
		{	// Look for our checkboxes only
			if (frm.elements[i].id.indexOf("edit_record") != -1) 
			{
				if(input.checked){
					// If any are checked then confirm alert, otherwise nothing happens
					frm.elements[i].checked = true;
				}
				else{
					frm.elements[i].checked = false;
				}
			}
		}
}

function check_deselect(input, target){
	if(target.checked == true){
		if(input.checked == false)
			target.checked = false;
	}
	
}


<!--
	
		var colorField = '';
		var colorFunction = '';
	
		function getX(obj) {
			return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
		}
		
		function getY(obj)
    	{
    		return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
   		 }
	
	
		
				// CLICK ON THE COLOR TO CHOOSE
		function clickColor($field, color) {

			hoverColor($field, color);
			document.getElementById($field).value = color;
			document.getElementById("colortable_"+$field).style.visibility = 'hidden';
			if (colorFunction !== "") {
				eval(colorFunction);
			}
		}
		
		// HOVER OVER A COLOR
		function hoverColor($field, color) {
			
			td = document.getElementById($field + '_colortable');
			td.style.backgroundColor = '#'+color;
		}
		
		// PICK THE COLOR		
		function pickColor(field) {
			colorField = field;
			
			inputTable = document.getElementById(field+"_colortable");
			colorTable = document.getElementById("colortable_" + field);
			colorTable.style.left = getX(inputTable);
			colorTable.style.top = getY(inputTable) + 18 + "px";
			colorTable.style.visibility = 'visible';
			
		}
		
		// HIDE COLOR TABLE
		function hideColorTable($field) {
			colorTable = document.getElementById("colortable_"+ $field);
			colorTable.style.visibility = 'hidden';
			document.getElementById($field+"_colortable").style.backgroundColor = document.getElementById($field).value;
		}
		
		// SHOW COLOR TABLE
		function showColorTable($field) {
			colorTable = document.getElementById("colortable_" + $field);
			colorTable.style.visibility = 'visible';

		}
		
		// INPUT TEXT FIELD IS MANUALLY CHANGED
		function changeColor(field) {
			document.getElementById(field+"_colortable").style.backgroundColor = '#' + document.getElementById(field).value;
		}
		


function loading_show()
{

	var loading = document.getElementById('loading');
	if (!loading)
	{
		loading = document.createElement('div');
		loading.id = 'loading';
		loading.innerHTML = '<font style="font-family:verdana; font-size:12px; color:white;">Loading...</' + 'font>';
		loading.style.position = 'absolute';
		loading.style.top = '0px';
		loading.style.right = '0px';
		loading.style.backgroundColor = '#CC4444';
		loading.style.width = '65px';
		loading.style.padding = '2px';
		document.getElementsByTagName('body').item(0).appendChild(loading);
	}
	loading.style.display = 'block';
}

function loading_hide()
{

	var loading = document.getElementById('loading');
	if (loading) {
		loading.style.display = 'none';
	}

}

function windowopen(url){
	window.open(url,'help','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no');
	
}

function renew_get_var($cur_url, $new_vars_array){

		$cur_vars_array = new Object();
		$new_url = "";
		
		if($cur_url.indexOf("?") != -1){
			$get = $cur_url.split("?");		
			
			if($get[1].indexOf("&") != -1){
					$cur_tails = $get[1].split("&");
					
					for(i = 0 ; i < $cur_tails.length ; i++){
						if($cur_tails[i].indexOf("=") != -1){
							$cur_vars = $cur_tails[i].split("=");
							$cur_vars_array[$cur_vars[0]] = $cur_vars[1];
						}
					}
			}else{
				if($get[1].indexOf("=") != -1){
					$cur_vars = $get[1].split("=");
					$cur_vars_array[$cur_vars[0]] = $cur_vars[1];
				}
			}
			
			for(keyVar in $new_vars_array){
					$cur_vars_array[keyVar] = $new_vars_array[keyVar];
			}
			
			/*
			if(!empty($new_php))
				$new_url = $new_php . "?";
			else
				$new_url = $get[0]. "?";
			*/
			
			$new_url = $get[0]+ "?";
			
			for(keyVar in $cur_vars_array){
				 $new_url += keyVar +"="+$cur_vars_array[keyVar]+"&";
			}
			
			$new_url.substr(0,$new_url.length-1);
			
		}else{
			/*
			if(!empty($new_php)){
				$cur_url = $new_php;
			}
			*/
			
			if($new_vars_array.length > 0 ){
				$new_url = $cur_url + "?";

				for(keyVar in $new_vars_array){
					 $new_url += keyVar +"="+$new_vars_array[keyVar]+"&";
				}
				
				$new_url.substr(0,$new_url.length-1);
			}
			else
				$new_url = $cur_url;				
			
		}

		
		return $new_url;
		
		
	}


