// 
// JAVASCRIPT FUNCTIONS
// 

// 
// INITIALIZE :: flashMode
// 

var FlashMode = 0;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
	if (navigator.plugins && navigator.plugins["Shockwave Flash"] && (versionIndex = navigator.plugins["Shockwave Flash"].description.indexOf(".")) != - 1) {
		var versionString = navigator.plugins["Shockwave Flash"].description.substring(versionIndex-1, versionIndex);
		versionIndex = parseInt( versionString );
		if ( versionIndex >= 6 ) {
				FlashMode = 1;
		}
	}
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('FlashMode = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('</SCRIPT\> \n');
}

// 
// FUNCTION :: test_include 
// 

function test_include(){
  alert('include working');
}

// 
// FUNCTION :: JSO
// 

function JSO(obj_name){
 if(document.getElementById(obj_name)){
  return document.getElementById(obj_name);
  }else{
    return false;
  }
}

// 
// FUNCTION :: setCookie
// 

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires.toGMTString() : "") +
	  ((path) ? "; path=" + path : "") +
	  ((domain) ? "; domain=" + domain : "") +
	  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// 
// FUNCTION :: getCookie
// 

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
  } else
	begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
	end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// 
// FUNCTION :: deleteCookie
// 

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
	document.cookie = name + "=" + 
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// 
// FUNCTION :: fixDate 
// 

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
	date.setTime(date.getTime() - skew);
}

// 
// FUNCTION :: formatAsMoney 
// 

function formatAsMoney(mnt) {
  mnt -= 0;
  mnt = (Math.round(mnt*100))/100;
  return (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
}

function selectedPage(list_name) {
  if(document.getElementById(list_name)){
  
    target_list = document.getElementById(list_name);
	  for (i = 0; i < target_list.options.length; i++){
		  if (target_list.options[i].selected){ 
			  return i;
      }
		}
    
	}
}

// 
// FUNCTION :: moveUp 
// 

function moveUp(list_name) {
  if(document.getElementById(list_name)){
	  target_list = document.getElementById(list_name);
    
  	for (i = 1; i < target_list.options.length; i++){
      if(target_list.options[i].selected == true){
        selected = i;
      
    		tempPageText  = target_list.options[selected-1].text;
    		tempPageValue = target_list.options[selected-1].value;
    		target_list.options[selected-1].text = target_list.options[selected].text;
    		target_list.options[selected-1].value = target_list.options[selected].value;
    		target_list.options[selected].text = tempPageText;
    		target_list.options[selected].value = tempPageValue;
        
    		target_list.options[selected].selected = false;
    		target_list.options[selected-1].selected = true;
      
      }
  	}
  
  }
}

// 
// FUNCTION :: moveDn 
// 

function moveDn(list_name) {
  if(document.getElementById(list_name)){
    target_list = document.getElementById(list_name);
	
	  for (i = (target_list.options.length-1); i > 0; i--){
      if (target_list.options[i].selected == true) {
        selected = i;
        
	  	  tempPageText  = target_list.options[selected+1].text;
		    tempPageValue = target_list.options[selected+1].value;
		    target_list.options[selected+1].text = target_list.options[selected].text;
  		  target_list.options[selected+1].value = target_list.options[selected].value;
	  	  target_list.options[selected].text = tempPageText;
		    target_list.options[selected].value = tempPageValue;
        
  		  target_list.options[selected].selected = false;
	  	  target_list.options[selected+1].selected = true;
        
      }
    }
    
	}
}

// 
// FUNCTION :: moveTo
// 

function moveTo(from_list,to_list) {
  if(document.getElementById(from_list) && document.getElementById(to_list)){

    // get list handles
    JSO_from_list = document.getElementById(from_list);
    JSO_to_list   = document.getElementById(to_list);
    
    
    // copy items
    for (i = 0; i < JSO_from_list.options.length; i++){
      if(JSO_from_list.options[i].selected == true){
        selected = i;
    
        // get text and value from from_list selection
        from_text  = JSO_from_list.options[selected].text;
        from_value = JSO_from_list.options[selected].value;
        
        // get to lists length
        to_list_length = JSO_to_list.options.length;
        
        // create new object in to_list
        JSO_to_list.options[to_list_length] = new Option(from_text);
        JSO_to_list.options[to_list_length].value = from_value;
        JSO_to_list.options[to_list_length].selected = true;
        
      }
    }
    
    // remove original
    for (i = 0; i < JSO_from_list.options.length; i++){
      if(JSO_from_list.options[i].selected == true){
        selected = i;
        
        // remove moved item from original list
        JSO_from_list.options[selected] = null;
        i=i-1;
        
      }
    }
    
    // remove selection
    for (i = 0; i < JSO_from_list.options.length; i++){
      JSO_from_list.options[i].selected = false;
    }

	}
}

// 
// FUNCTION :: copyTo
// 

function copyTo(from_list,to_list) {
  if(document.getElementById(from_list) && document.getElementById(to_list)){

    // get list handles
    JSO_from_list = document.getElementById(from_list);
    JSO_to_list   = document.getElementById(to_list);
    
    
    // copy items
    for (i = 0; i < JSO_from_list.options.length; i++){
      if(JSO_from_list.options[i].selected == true){
        selected = i;
    
        // get text and value from from_list selection
        from_text  = JSO_from_list.options[selected].text;
        from_value = JSO_from_list.options[selected].value;
        
        // get to lists length
        to_list_length = JSO_to_list.options.length;
        
        // create new object in to_list
        JSO_to_list.options[to_list_length] = new Option(from_text);
        JSO_to_list.options[to_list_length].value = from_value;
        JSO_to_list.options[to_list_length].selected = true;
        
      }
    }
    
    // remove selection
    for (i = 0; i < JSO_from_list.options.length; i++){
      JSO_from_list.options[i].selected = false;
    }

	}
}

// 
// FUNCTION :: removeFrom 
// 

function removeFrom(from_list) {
  if(document.getElementById(from_list)){

    // get list handles
    JSO_from_list = document.getElementById(from_list);    
    
    // remove original
    for (i = 0; i < JSO_from_list.options.length; i++){
      if(JSO_from_list.options[i].selected == true){
        selected = i;
        
        // remove moved item from original list
        JSO_from_list.options[selected] = null;
        i=i-1;
        
      }
    }
    
    // remove selection
    for (i = 0; i < JSO_from_list.options.length; i++){
      JSO_from_list.options[i].selected = false;
    }

	}
}

// 
// FUNCTION :: select_list_contents 
// 

function select_list_contents(page_id,object_id,list_name){
  if(document.getElementById('F_'+object_id) && document.getElementById(list_name)){
    my_form = document.getElementById('F_'+object_id);
    my_list = document.getElementById(list_name);
    
    my_list.multiple = true;

	  for (i = 0; i < my_list.options.length; i++){
		  my_list.options[i].selected = true;
		}
    
  }
}

// 
// FUNCTION :: USE_popup
// 

function USE_popup(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

// 
// FUNCTION :: findPosX 
// 

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

// 
// FUNCTION :: findPosY 
// 

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// 
// FUNCTION :: submit_link 
// 

function submit_link(link) {
	document.form1.action = link;
	document.form1.submit();
}

// 
// FUNCTION :: validate_form 
// 

required_registry = '';

function validate_form(form_id,required_registry){

  // find and check the value of any elements registered as required
	
	ASV_required_registry = required_registry.split(",");
	
	// loop through required_registry
  required_missing = false;
	for(i=0; i<((ASV_required_registry.length)-1); i++){
	
	  // get elements value
		if(document.getElementById(ASV_required_registry[i])){
		  element = document.getElementById(ASV_required_registry[i]);
		} else {
		  element = false;
		}
		
		// if element not found flag missing
	  if(element == false){
		  required_missing = true;
		} 
		// if element found but empty flag missing and hilight element
		else {
		  if(element.value == ''){
			  required_missing = true;
				element.className = 'USE-red-box';
			} else {
			  element.className = 'USE-gray-box';
			}
		}
		
	}
	
	if(required_missing == true){
	  alert('The hilighted fields are required');
	} else {
	  JSO(form_id).submit();
	}
	
}

// 
// PNG fix?
//