function ImgSwap(img,ref)
{
    if (document.images)
        document.images[img].src = ref;
}

function ValidateSearch()
{
    var searchForm = null;
    var retVal = false;
    
    //if(BrowserIsNetScape()) searchForm = document.frmSearch;
    //else searchForm = frmSearch;
      
    var textBox = document.getElementById('searchText');
    var txt = textBox.value; // searchForm.searchText.value;
    
    if(IsBlank(txt))
    {
        alert('Please specify keyword(s) you would like to search for.');
        //searchForm.searchText.focus();
        textBox.focus();
    }
    else if(!IsValidValue(txt))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        //searchForm.searchText.select();
        textBox.select();
    }
    else
    {
        // make sure that words are separated with ;
        txt = txt.replace(",", ";");
        txt = txt.replace(":", ";");
        txt = txt.replace("+", ";");
        txt = txt.replace("&", ";");
        
        //searchForm.searchText.value = txt;
       textBox.value = txt;
        
        retVal = true;
    }
        
    return retVal;
}

 function ValidateTipForm()
{
    var bRetVal = false;
    
    var btn = document.getElementById("btnTipSubmit");
    btn.disabled = true;
    
    if(!IsValidValue(document.getElementById('tip_heading').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('tip_heading').select();
    }            
    else if(!IsValidValue(document.getElementById('tip_text').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('tip_text').select();
    }            
    else if(!IsValidValue(document.getElementById('user_name').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('user_name').select();
    }            
    else if(!IsValidValue(document.getElementById('user_city').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('user_city').select();
    }            
    else if(document.getElementById('category_id').value == 0 || document.getElementById('category_id').value == "0")
    {
        alert('Please select a category before submitting your tip.');
        document.getElementById('category_id').focus();
    }
    else if(IsBlank(document.getElementById('tip_heading').value))
    {
        alert('Please enter a name for your tip. This name will be used in tip listings.');
        document.getElementById('tip_heading').focus();
    }
    else if(document.getElementById('tip_heading').value.length > 50)
    {
        alert('Tip name cannot be longer than 50 characters.');
        document.getElementById('tip_heading').focus();
    }
    else if(IsBlank(document.getElementById('tip_text').value))
    {
        alert('Please enter your tip text.');
        document.getElementById('tip_text').focus();
    }
    else if(IsBlank(document.getElementById('user_name').value))
    {
        alert('Please enter your name.');
        document.getElementById('user_name').focus();
    }
    else if(document.getElementById('user_name').value.length > 50)
    {
        alert('Your name cannot be longer than 50 characters.');
        document.getElementById('user_name').focus();
    }
    else if(IsBlank(document.getElementById('user_city').value))
    {
        alert('Please enter your city of residence.');
        document.getElementById('user_city').focus();
    }
    else if(document.getElementById('user_city').value.length > 50)
    {
        alert('City name cannot be longer than 50 characters.');
        document.getElementById('user_city').focus();
    }
    else if(document.getElementById('tip_text').value.length > 512)
    {
        alert('Tip text is too long. Please try to limit it to a maximum of 512 characters.');
        document.getElementById('tip_text').select();
    }
    else if(document.getElementById('user_state').value == 0 || document.getElementById('user_state').value == "0")
    {
        alert('Please select your state/province of residence.');
        document.getElementById('user_state').focus();
    }
    else bRetVal = true;
    
    btn.disabled = bRetVal;

    return bRetVal;
}

function OpenTipBox(tipID)
{
    if(tipID > 0)
        window.open('Tip_Print.asp?t=' + tipID, 'tip_text', 'resizable=1;width=560;height=350');
    else
        alert('Sorry! There is no tip to view. Please try again.');
}

function OpenPrintBox(tipID)
{
    if(tipID > 0)
        window.open('Print.aspx?t=' + tipID, 'tip_print', 'resizable=1;width=560;height=350');
    else
        alert('Sorry! There is no tip to print. Please try again.');
}

function OpenSAFBox(tipID)
{
    if(tipID > 0)
        window.open('Tip_SAF.asp?t=' + tipID, 'tip_saf', 'resizable=1;width=560;height=350');
    else
        alert('Sorry! There is no tip to send. Please try again.');
}

function ValidateCategory()
{
    var retVal = false;
    
    if(IsBlank(document.getElementById('catText').value))
    {
        alert('Please specify a category name before submitting it.');
        document.getElementById('catText').focus();
    }
    else if(document.getElementById('catText').value.length > 18)
    {
        alert('Category name cannot be more than 18 characters in length.');
        document.getElementById('catText').select();
    }
    else if(!IsValidValue(document.getElementById('catText').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('catText').select();
    }            
    else retVal = true;
    
    return retVal;
}

function ValidateCategory2()
{
    var retVal = false;
    
    if(IsBlank(document.getElementById('cat2Text').value))
    {
        alert('Please specify a category name before submitting it.');
        document.getElementById('cat2Text').focus();
    }
    else if(document.getElementById('cat2Text').value.length > 18)
    {
        alert('Category name cannot be more than 18 characters in length.');
        document.getElementById('cat2Text').select();
    }
    else if(!IsValidValue(document.getElementById('cat2Text').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('cat2Text').select();
    }            
    else retVal = true;
    
    return retVal;
}

function ValidatePage(min, max, cat)
{
    var retVal = false;
    var p = document.getElementById('p').value;
    
    if(min == max)
        alert('Single page view! Action canceled.');
    else if((p == "") || (p < min || p > max) || (! IsNumeric(p)))
    {
        alert('Please specify a page number between ' + min + ' and '+ max + ' to continue.');
        
        document.getElementById('p').focus();
    }
    else 
    {
        document.getElementById('goBtn3').href = location.pathname  + "?c=" + cat  + "&p=" + p;
       
        retVal = true;   
    }
    
    return retVal;
}

function ValidateSAF()
{
    var retVal = false;
    
    if(!IsValidValue(document.getElementById('friendEmail').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('friendEmail').select();
    }            
    else if(!IsValidValue(document.getElementById('friendName').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('friendName').select();
    }            
    else if(!IsValidValue(document.getElementById('yourName').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('yourName').select();
    }            
    else if(!IsValidValue(document.getElementById('message').value))
    {
        alert('Special characters "<" and ">" are not allowed in this field.');
        document.getElementById('message').select();
    }            
    else if(IsBlank(document.getElementById('friendEmail').value))
    {
        alert('Please enter your friend\'s email to continue.');
        document.getElementById('friendEmail').focus();
    }
    else if(document.getElementById('friendEmail').value.length > 50)
    {
        alert('Your friend\'s email cannot be longer than 50 characters.');
        document.getElementById('friendEmail').focus();
    }
    else if(! ValidEmail(document.getElementById('friendEmail').value))
    {
        alert('Your friend\'s email is not a valid email address. Please provide a valid email.');
        document.getElementById('friendEmail').select();
    }
    else if(IsBlank(document.getElementById('friendName').value))
    {
        alert('Please enter your friend\'s name to continue.');
        document.getElementById('friendName').focus();
    }
    else if(document.getElementById('friendName').value.length > 50)
    {
        alert('Your friend\'s name cannot be longer than 50 characters.');
        document.getElementById('friendName').focus();
    }
    else if(IsBlank(document.getElementById('yourName').value))
    {
        alert('Please enter your name to continue.');
        document.getElementById('yourName').focus();
    }
    else if(document.getElementById('yourName').value.length > 50)
    {
        alert('Your name cannot be longer than 50 characters.');
        document.getElementById('yourName').focus();
    }
    else if(document.getElementById('message').value.length > 100)
    {
        alert('Message text cannot be longer than 100 characters.');
        document.getElementById('message').select();
    }
    else retVal = true;
    
    return retVal;
}
