/*********************************************************
'Filename:      global.js
'Website:       Robb Report Vacation Homes
'Created By:    Michael England
'Created Date:

Modified        By              Description
----------------------------------------------------------

*********************************************************/

// SHARE TOOLS MENU
var share_menu_timer;
var share_menu_id = "share_menu";

function share_menu_mouseover(){
    clearTimeout(share_menu_timer);
    Effect.Appear(share_menu_id,{duration:.25,queue:'end'});
}

function share_menu_mouseout(){
    share_menu_timer = setTimeout("share_menu_clear()",250);
}

function share_menu_clearTimeout(){
    clearTimeout(share_menu_timer);
}

function share_menu_clear(){
    Effect.Fade(share_menu_id,{duration:.25,queue:'start'});
}

// /SHARE TOOLS MENU

// EMAIL VALIDATION
function echeck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)

    if (str.indexOf(at)==-1){
        alert("Invalid email address.");
        return false;}
    
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid email address.");
        return false;}
    
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid email address.");
        return false;}
    
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid email address.");
        return false;}
    
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid email address.");
        return false;}
    
    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid email address.");
        return false;}
    
    if (str.indexOf(" ")!=-1){
        alert("Invalid email address.");
        return false;}
    
    return true; 
}

function ValidateForm(){
    var emailID=document.frmNewsletter.email
    
    if ((emailID.value==null)||(emailID.value=="")){
    alert("Please enter your email address.");
    emailID.focus();
    return false;
    }
    
    if (echeck(emailID.value)==false){
    emailID.value="";
    emailID.focus();
    return false;}
    
    return true;
}
// /EMAIL VALIDATION

// HIDE/SHOW SELECTS
function hide_selects(){
    selects = document.getElementsByTagName("select");
    for(i=0;i<selects.length;i++)
    {
        selects[i].style.visibility = "hidden";
    }
}

function show_selects(){
    selects = document.getElementsByTagName("select");
    for(i=0;i<selects.length;i++)
    {
        selects[i].style.visibility = "visible";
    }
}
// /HIDE/SHOW SELECTS

// ENABLE/DISABLE ELEMENT
var old_onclick;

function disable_element(element_id, timeout){
    var object = document.getElementById(element_id);
    old_onclick = object.onclick;
    object.onclick = "return false";
    object.style.opacity = ".5";
    object.style.filter = "alpha(opacity=50)"
    
    if(timeout>0){setTimeout("enable_element('"+element_id+"')",timeout);}
}

function enable_element(element_id){
    var object = document.getElementById(element_id);
    object.onclick = old_onclick;
    object.style.opacity = "1";
    object.style.filter = "alpha(opacity=100)"
}
// /ENABLE/DISABLE ELEMENT

// ADD TO FAVORITES
function CreateBookmarkLink(title,url){

    var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';
    
    if(window.sidebar){
        window.sidebar.addPanel(title, url,"");
    } else if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        // IE4/Win generates an error when you
        // execute "typeof(window.external.AddFavorite)"
        // In IE7 the page must be from a web server, not directly from a local 
        // file system, otherwise, you will get a permission denied error.
        window.external.AddFavorite(url, title); // IE/Win
    } else if(isKonq) {
        alert('You need to press CTRL + B to bookmark our site.');
    } else if(window.opera) {
        void(0); // do nothing here (Opera 7+)
    } else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
        alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
        alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
        alert('In order to bookmark this site you need to do so manually through your browser.');
    }
}
// /ADD TO FAVORITES

function resize(height) {
    document.getElementById("multimediaGallery").style.height = height + "px";
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function MediaGallery_DoFSCommand(command, args) {
    var MediaGalleryObj = isInternetExplorer ? document.all.MediaGallery : document.MediaGallery;
    if (command == "resize") {
        if (!isNaN(args)) {
            if (document.getElementById("multimediaGallery") != null)
                document.getElementById("multimediaGallery").style.height = Math.round((args * (345 / 439)) - (66 * (args / 499))) + "px";

            if (document.getElementById("ctl00_cphBodyContent_mlcMedia") != null)
                document.getElementById("ctl00_cphBodyContent_mlcMedia").style.height = Math.round((args * (345 / 439)) - (66 * (args / 499))) + "px";            
        }
}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<script language=\"VBScript\"\>\n');
    document.write('On Error Resume Next\n');
    document.write('Sub MediaGallery_FSCommand(ByVal command, ByVal args)\n');
    document.write(' Call MediaGallery_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('</script\>\n');
} else {

}
