/*
<fusedoc fuse="common.js" language="ColdFusion" version="2.0">
	<responsibilities>I have the search boxes for the order page and their Javascripts</responsibilities>
	<properties>
		<history author="Jeff Roberson" email="jlr@internetdatabases.com" role="Architect" date="12/19/2005"/>
		<history author="Jeff Roberson" email="jlr@internetdatabases.com" role="Architect" date="12/19/2005">
			added the generic hide_show function to hide and show divs used in the application.
		</history>
		<history author="Jeff Roberson" email="jlr@internetdatabases.com" role="Architect" date="12/27/2005">
			added popReport() for report options windows.
		</history>
		<history author="Jeff Roberson" email="jlr@internetdatabases.com" role="Architect" date="01/02/2006">
			Added in confirm_click function
			Added in textarea_max function
		</history>
	</properties>
	<io>
		<in/>
		<out/>
	</io>
</fusedoc>
*/
function ajax_login_check(data,url){
	check_val = data.search(/@@LoginRequired@@/i);
	if(check_val > 0)
	window.location = url;
	return void(0);
};
function textarea_cancel_enter(evt) {
 	var charCode = (evt.which) ? evt.which : event.keyCode;
   if(charCode == 13)
   	return false;
};
function textarea_max(textarea,size) {
                
	strText = textarea.value;
	size = size - 1;
	if(strText.length > size)
		textarea.value = strText.substr(0,size);
	return true;
};

function confirm_click(questions,linked){
	if(confirm(questions)) location.href = linked;
};

function old_confirm_click(question,link){
	bAnswer = confirm(question);
	if(bAnswer) {
		window.location.href = link;
		alert(link);
		return true;
	} else {
	return false;
	};
};
function op_change(box,change,over){
	
	if(over) {
		document.getElementById(box).style.background = "#71A1C1";
		//document.getElementById(change).style.display = "";
	} else {
		document.getElementById(box).style.background = "white";
		//document.getElementById(change).style.display = "none";
	};
};
	
function hide_show( hide , show ){
	// split the lists into an array
	// the hide list will be hidden and the show list will be show
	if( hide.length > 0 ) {
		var hide = hide.split( ',' );
		
		for (h = 0; h < hide.length; h++)
		{
			$("#" + hide[h] ).hide();
			//opacity(hide[h], 100, 0, 500);
			//document.getElementById( hide[h] ).style.display = "none";	
		} //end loop
	} // end if
	if( show.length > 0 ) {
		var show = show.split( ',' );
		for ( s = 0; s < show.length; s++ )
		{
			$("#" + show[s] ).show();
			//opacity(show[s], 0, 100, 500)
			//document.getElementById( show[s] ).style.display = "";	
		}// end loop
	} // end if
}

function popReport(high,wide) {
	var popWin = null;  
	var xPos = 0; 
	var yPos = 0; 
	if (high)
		high = high;
	else
		high = 550;
	if (wide)
		wide = wide;
	else
		wide = 550;		
	if (screen) { 
	  xPos = Math.floor((screen.width-550)/2); 
	  yPos = Math.floor((screen.height-330)/2); 
	} 
		popnewWindow = window.open('', 'report_options', 'width='+wide+',height='+high+',toolbar=no,directories=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,left='+xPos+',top='+yPos);   
		popnewWindow.focus();
	};
	
		
	function copyFields(qForm,Ajax){
		var allFields = qForm.getFields();
		removeAllFields(Ajax);
		for(var f in allFields){
		addField(Ajax,'hidden',f,allFields[f]);
		}
	}
	
	function removeAllFields( form ){
		for (var e = (form.elements.length -1); e > -1; e--){
		removeField (form,  form.elements[e].name )
		}
	    return true;
	}
	
	function getField (form, fieldName) {
	  if (!document.all)
	    return form[fieldName];
	  else  // IE has a bug not adding dynamically created field 
	        // as named properties so we loop through the elements array 
	    for (var e = 0; e < form.elements.length; e++)
	      if (form.elements[e].name == fieldName)
	        return form.elements[e];
	  return null;
	}
	
	function removeField (form, fieldName) {
	  var field = getField (form, fieldName);
	  if (field && !field.length)
	    field.parentNode.removeChild(field);
	}
	
	function addField (form, fieldType, fieldName, fieldValue) {
  	if (document.getElementById) {
    var input = document.createElement('INPUT');
      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  	};
  	}
	/* Function to Operate help */
	function help(){
		obj_right = document.getElementById('dash_right');
		obj_left = document.getElementById('dash_left');
		obj_right_contents = document.getElementById('right_contents');
		if(obj_right.style.width != '20%') {
			obj_left.style.width = '75%';
			obj_right.style.width = '20%';
			obj_right_contents.style.display = '';
		} else {
			obj_left.style.width = '97%';
			obj_right.style.width = '1%';
			obj_right_contents.style.display = 'none';
		}
			
	}