﻿// JScript File
id_selected = "";

function onBoothClick( id )
{
  window.open("Booth.aspx?id=" + id,"_blank","toobar=0, menubar=0, resizable=1, location=0, width=600, height=260, scrollbars=1"); 
}

function onExhibitorClick( id )
{
   doc = window.frames[0];
   
   if(doc.document.getElementById(id) != null){
     if (  !isSelected(id) ) 
      {
          if ( canSelect( id ) )
          {
              width = parseInt( doc.document.getElementById(id).style.width  ) ;
              height = parseInt( doc.document.getElementById(id).style.height );
              
              doc.document.getElementById(id).style.width = width + "px" ;
              doc.document.getElementById(id).style.height = height + "px";
              
              doc.document.getElementById(id).style.zIndex = "99";
              
              doc.document.getElementById(id).style.border = "#0000ff 2px solid";
              
              setChoice( id );
          }
      }
      else
      {
          width = parseInt( doc.document.getElementById(id).style.width  );
          height = parseInt( doc.document.getElementById(id).style.height );
          
          
          doc.document.getElementById(id).style.width = width + "px" ;
          doc.document.getElementById(id).style.height = height + "px";
          
          doc.document.getElementById(id).style.zIndex = "50";
          
          doc.document.getElementById(id).style.border = "1px solid black";
          doc.document.getElementById(id).style.textDecoration = "none";
          
          unSetChoice(id);
      }
   }
   else{
     alert("Invalid Booth Number");
   }
}



function canSelect( id )
{

     if ( document.getElementById(listClientID).options )
     {
        var len = document.getElementById(listClientID).options.length;
        if ( len == 4)
        {
            alert("Your booth request limit of four has been exceeded. Please remove a booth from your booth request list in order to add another.");
            return false;
        }
     }
     
     doc = window.frames[0];
     if ( doc.document.getElementById( id ).style.backgroundColor.toLowerCase() == available_color.toLowerCase() || HexToDec(available_color.toLowerCase()) == doc.document.getElementById( id ).style.backgroundColor.toLowerCase() )
        return true;
     else
     {
        alert("The selected booth is unavailable.");   
        return false;
     }
     
}
function isSelected(id)
{
    
    doc = window.frames[0];
    var x = doc.document.getElementById(id).style.border;
    x = x.toLowerCase();
    x = x.substring(x.indexOf('#') , 7);
    
    if ( x == '#0000ff' )
    {
        return true;
    }
    else
    {
        var z  = doc.document.getElementById(id).style.border.indexOf('255');
        if ( z != -1 )
            return true;
        else
            return false;
    }
    
}

function setChoice(id)
{
    var newOption = document.createElement("OPTION");
    newOption.value = id;
    newOption.text = id;    
    document.getElementById(listClientID).options.add( newOption);
}

function unSetChoice(id)
{
    for( i =0; i<document.getElementById(listClientID).options.length; i++)
    {
        if ( document.getElementById(listClientID).options[i].value == id)
        {
            document.getElementById(listClientID).remove(i);
            return true;
        }
    }
}

function remove_option()
{
    var id = "";
    for( i =0; i<document.getElementById(listClientID).options.length; i++ )
    {
        if ( document.getElementById(listClientID).options[i].selected )
        {
            id = document.getElementById(listClientID).options[i].value;
            break;
        } 
    }
    
    onExhibitorClick(id);
}

function Add_Option_by_Input()
{
    id = document.forms[0].txtChoice.value;
    if ( id == "")
        return;
           
    onExhibitorClick(id);
}
function moveUp()
{
    var selected_option = -1;
    
    for( i =0; i<document.getElementById(listClientID).options.length; i++ )
    {
        if ( document.getElementById(listClientID).options[i].selected )
        {
            selected_option = i;
            break;
        } 
    }
    
    if ( selected_option == -1)
        return;
    
    if ( selected_option == 0)
        return;
    
    else
    {
        move_to_option = selected_option - 1;
        switchOptions( move_to_option , selected_option );                
    }
}

function moveDown()
{
    var selected_option = -1;
    
    for( i =0; i<document.getElementById(listClientID).options.length; i++ )
    {
        if ( document.getElementById(listClientID).options[i].selected )
        {
            selected_option = i;
            break;
        } 
    }
    
    if ( selected_option == -1)
        return;
    
    if ( selected_option == (document.getElementById(listClientID).options.length -1 ))
        return;
    
    else
    {
        move_to_option = selected_option +1;
        tmp_d = document.getElementById(listClientID).options[selected_option].id;
        switchOptions( move_to_option , selected_option );                
    }
}

function switchOptions( option_1 , option_2 )
{
      drop_down_ids = document.getElementById(listClientID);  
      
      tmp_id = drop_down_ids.options[option_1].value;
      drop_down_ids.options[option_1].value = drop_down_ids.options[option_2].value;
      drop_down_ids.options[option_1].text = drop_down_ids.options[option_2].text;
      
      drop_down_ids.options[option_2].value = tmp_id;
      drop_down_ids.options[option_2].text = drop_down_ids.options[option_2].value;
      drop_down_ids.options[option_1].selected = true;
      drop_down_ids.options[option_2].selected = false;
      
}
function HexToDec( hex_value )
{
   

   Input = hex_value.substring(1, hex_value.length ).toUpperCase();
   a = GiveDec(Input.substring(0, 1));
   b = GiveDec(Input.substring(1, 2));
   c = GiveDec(Input.substring(2, 3));
   d = GiveDec(Input.substring(3, 4));
   e = GiveDec(Input.substring(4, 5));
   f = GiveDec(Input.substring(5, 6));

   x = (a * 16) + b;
   y = (c * 16) + d;
   z = (e * 16) + f;
    
   return "rgb("+x+", "+y+", "+z+")";
   
}

function GiveDec(Hex)
{
   if(Hex == "A")
      Value = 10;
   else
   if(Hex == "B")
      Value = 11;
   else
   if(Hex == "C")
      Value = 12;
   else
   if(Hex == "D")
      Value = 13;
   else
   if(Hex == "E")
      Value = 14;
   else
   if(Hex == "F")
      Value = 15;
   else
      Value = eval(Hex);

   return Value;
}
function redirect( r_location )
{
    open( r_location ,'windowname','width=600px,height=600px,scrollbars,resizable,status');
}



function reset_ids()
{
    /* extract the ids from the id_selected object and set the 
       divs to border black */
    while( id_selected.indexOf(';') != -1 )
    {
        current_div_id = id_selected.substring( 0 , id_selected.indexOf(';'));
        
        if ( current_div_id != "" )
        {
            if ( d.getElementById( current_div_id ) )
            {
            
                div_tmp_obj = d.getElementById( current_div_id );
                div_tmp_obj.style.borderColor = "black";
            
            }
        }
        
        id_selected  = id_selected.substring(  id_selected.indexOf(';') + 1 );         
        
    }
    id_selected = "";
}

function isUnique(id)
{
    tmp_array  = id_selected.split(';');
    
    for ( i=0;i<tmp_array.length;i++)
    {
        if ( tmp_array[i] ==  id ) 
        {
            tmp_array[i] = "";
            id_selected = tmp_array.join(";");
            return false;
        }
    }
    
    return true;
}

var once = true;
function CheckStatus( id )
{
    if ( once )
    {
        alert ( document.getElementById(listClientID).options.length );
        once = false;
    }
    for( i=0 ; i<document.getElementById(listClientID).options.length ; i++ )
    {
        if ( document.getElementById(listClientID).options[i].value == id )
        {
              
              width = parseInt( doc.document.getElementById(id).style.width  ) ;
              height = parseInt( doc.document.getElementById(id).style.height );
              doc.document.getElementById(id).style.width = width + "px" ;
              doc.document.getElementById(id).style.height = height + "px";
              doc.document.getElementById(id).style.zIndex = "99";
              doc.document.getElementById(id).style.border = "#0000ff 2px solid";
              setChoice( id );
        }
    }
}