function redirect(page)
{
    window.location.href = page
}

function open_window(page,params)
{
    window.open(page,"popup",params)
}

function reset_iframe(id,src) {
    var _frame = document.getElementById(id);
    _frame.src = src;
}  
   
 function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function stopBubbling(e) {

  if(!e)
    e = window.event;
  
  if(e.stopPropagation)
    e.stopPropagation();
  
  if(e.preventDefault)
    e.preventDefault();
    
  e.cancelBubble = true;
  e.cancel = true;
  e.returnValue = false;
  return false;
     
}

function default_button(btnID, e)
{ 
    var btn = document.getElementById(btnID); 
    
     if (document.all) { 
       if (e.keyCode == 13) { 
            stopBubbling(e) 
            btn.click();
        } 
     } else if (document.getElementById || document.layers) { 
       if (e.which == 13) {         
      
            if( btn && btn.click ) {                                
                stopBubbling(e) 
                btn.click();     
            } else if ( btn &&  btn.onclick ) {
               var temp = eval(btn.onclick);               
                if( temp ) { 
                    stopBubbling(e)  
                    temp(e);                   
                } 
            }   
        }
     }      
}

function ShowInternationalDealer(ddl) {
    var value = ddl[ddl.selectedIndex].value;
    if( value != '0' ) {
        open_window(value, 'redirect', 'width=500px, height=500px, resizable=1, scrollbars=1');
    }
} 

function FindLocalRetailer(tbx_zip, ddl_states, mBehaviorID, baseURL) {
    
      var zip = tbx_zip.value;
      var state = ddl_states[ddl_states.selectedIndex].value;
    
      if( (zip == '' || zip == 'zip' ) && state == '' ) {
        alert("Invalid Zip Code And State"); 
        return false;
      }      
      
      var m = $find(mBehaviorID);
      if( m ) {
        var url = baseURL + '?zip=' + zip + '&state=' + state

        m.set_dynamicContextKey('{src: ' + url + ', width: 800px, height: 600px;}');   
        m.show()  
       }
       
      return true;
   } 
   
/*    function EmailSignup(tbxID, modalID, baseURL, e) {
        var tbx = $get(tbxID);

        if( tbx ) {
            if( tbx.value == '' || tbx.value == 'Sign up for KEEN emails' ) {
                stopBubbling(e)                      
                setTimeout('alert(\'Invalid Email Address\');', 100);
                return false;
            } else {
                OpenModal(modalID, baseURL + 'I_thanks.aspx?e=' + tbx.value, '610px', '300px', 'no')
                tbx.value =  'Sign up for KEEN emails';
               return true; 
            }
         }               
    }

    
    function EmailSignup(tbxID, modalID, baseURL, e) {
        var tbx = $get(tbxID);

        if( tbx ) {
            if( tbx.value == '' || tbx.value == 'Sign up for KEEN emails' ) {
                stopBubbling(e)                      
                setTimeout('alert(\'Invalid Email Address\');', 100);
                return false;
            } else {
                OpenModal(modalID, baseURL + 'I_register.aspx?e=' + tbx.value, '610px', '310px', 'no')
                tbx.value =  'Sign up for KEEN emails';
               return true; 
            }
         }               
    }
 */   
    function EmailSignup(tbxID, modalID, baseURL, e) {
        var tbx = $get(tbxID);

        if( tbx ) {
            if( tbx.value == '' || tbx.value == 'Sign up for KEEN emails' ) {
                stopBubbling(e)                      
                setTimeout('alert(\'Invalid Email Address\');', 100);
                return false;
            } else {
                OpenModal(modalID, 'http://www.keenfootwear.com/I_EU_emailsignup.aspx?e=' + tbx.value, '650px', '410px', 'no')
                tbx.value =  'Sign up for KEEN emails';
               return true; 
            }
         }               
    }
   
   function SearchProducts(url, tbxSearchID) {
        var Query = $get(tbxSearchID).value;
        if( Query == '' || Query == 'find products') {
          setTimeout('alert(\'Invalid Search Criteria\');',100)
           return false
        }                
        redirect(url + '?q=' + Query);
        return false;
    }  


function ValidatePhoneParts(part1, part2, part3) {
  
    //Validate Part 1   
    if( part1.length != 3 || !IsNumeric(part1) ) {
        return false
    } 
   
   //Validate Part 2   
    if( part2.length != 3 || !IsNumeric(part2) ) {
        return false
    } 
   
   //Validate Part 3    
       if( part3.length != 4 || !IsNumeric(part3) ) {
        return false
    } 
   return true; 
}

function PhoneNumberAutoTab(tbx, nextTbxID, e) {
    var tbx_next = $get(nextTbxID); 
    var sourceKeyCode = (e.keyCode) ? e.keyCode : e.charCode;
        
    if( sourceKeyCode != 9 && sourceKeyCode != 16) {     
        if( tbx.value.length == tbx.maxLength ) {
           tbx_next.focus();       
        }          
    } else {
         stopBubbling(e)
    } 
}

/***IMAGE CACHING FUNCTIONS***/
function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/***/

function OpenModal(behaviorID, url, width, height, scrolling) {
    var m = $find(behaviorID);

    if( scrolling == '' ) {
        scrolling = 'no';
    } 
     
    if( m ) {
        if( url != '' ) {        
            if( url.indexOf('?') == -1 ) {             
                url = url + '?behaviorID=' + behaviorID   
            } else {
                url = url + '&behaviorID=' + behaviorID   
            }
            
            m.set_dynamicContextKey('{src: ' + url + ', width: ' + width + ', height: ' + height + ', scrolling: ' + scrolling + '}');   
            }
        
        m.show()  
        return true;
    } else {
        return false;
    } 
    
}

function HideModal(behaviorID) {
    var m = $find(behaviorID);
    if( m ) {
        m.hide();
    }  
}



function UpdatePanel(target, args) {
    setTimeout('__doPostBack(\'' + target + '\', \'' + args + '\')',100)
}

function ChangePaginationPageSize(ddlID, baseURL) {
    var ddl = $get(ddlID);

    if ( baseURL.indexOf('?') == -1 ) {
        baseURL += "?"      
    } else {
        baseURL += "&"      
    }
   
    redirect(baseURL + 'cp=1&ps=' + ddl[ddl.selectedIndex].value);    
}

function GetFlashMovie(movieName) {     
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    } else {
        return document[movieName]
    } 
} 

function ClearDefaultText(tbxID, defaultText) {
    var tbx = $get(tbxID);
    if( tbx ) {

        if( tbx.value == defaultText ) {
            tbx.value = '';
        }
    }  
}

/***/

// Tab Functions
function tab(id, pnl, cont, onMouseover) {

    this.id = id;
    this.pnl = pnl;   
    this.container = cont;  
    this.onMouseover = onMouseover; 
    
   this._onChangeHandler = null;  
}

tab.prototype = {

    init:  function() {     
        this._onChangeHandler = Function.createDelegate(this, this._onChange);        
        var e = $get(this.get_id());
        
        if( !this.onMouseover ) {
            $addHandler(e, "click", this._onChangeHandler);        
        } else {
            $addHandler(e, "mouseover", this._onChangeHandler);      
        }
    },
   
    _onChange: function() {
        this.container._onChange(this.get_id());
    },  
   
    get_tabOnChangeHandler: function() {
        return this._onChangeHandler;
    },   
    
    get_id: function() {
        return this.id;
    },
    set_id: function(id) {
        this.id = id;
    },
   
   get_pnl: function() {
        return this.pnl;
    },
    set_pnl: function(pnl) {
        this.pnl = pnl;
    }    
    
}


// Tabs collection functions
function tabs() {
     this.page_tabs = new Array();
     this._tabOnChangeHandler = null;  
}

tabs.prototype = {

    init:  function() {    

         var _items = this.page_tabs; 
         for (x=0; x < _items.length; ++x)
         {       
            var pnl = $get(_items[x].pnl);
            pnl.style.display = "none" 
         }         
    },
   
   add:  function(tab) {
                
       tab.init();       
       this.page_tabs[this.get_length()] = tab;

   },
   
  
   _onChange: function(id) {

      this.tab_activate(id);
       
   },
   
   tab_activate: function(e) {
        var _items = this.page_tabs;
       
        for (x=0; x < _items.length; ++x)
         {        
            var pnl = $get(_items[x].pnl);
            var tb = $get(_items[x].id);
            var _children = tb.childNodes;
            
            if( _items[x].id == e ) {         
                  
                pnl.style.display = "block";       
                
                for( y=0; y < _children.length; y++) {

                    if( _children[y].tagName == 'IMG' ) {

                        if( _children[y].className == 'onstate' ) {
                            _children[y].className = 'active'; 
                        } else if (_children[y].className == 'offstate' ) {
                           _children[y].className = 'inactive';  
                        }
                    }    
                }  
                         
                
            }     
            else  {

                pnl.style.display = "none";
                
               for( y=0; y < _children.length; ++y) {

                    if( _children[y].tagName == 'IMG' ) {
                        if( _children[y].className == 'active'  ) {
                            _children[y].className = 'onstate'; 
                        } else if (_children[y].className == 'inactive' ) {
                           _children[y].className = 'offstate';  
                        }
                    }    
                    
                  }
               
                
            }
         }   
     } ,
     
     items: function() {
        return this.page_tabs;
     },
     
     get_length: function() {
        return this.page_tabs.length;
     }

}