var downsubs = {
    onmouseover: function (div) {
        div.className = div.className + "_over";
    },
    onmouseout: function (div) {
        div.className = div.className.split("_over").join("");
    },
    loading: function () {
        $('loader').appear({to: 1});
    },
    unloading: function () {
        $('loader').fade({to: 0});
    },
    /*download: {
        popup: {
            close: function() {
                $('ifdownload').src = 'download.cjp.htm';
                $('download_popup').style.visibility = "hidden";
            },
            open: function(fileId) {
                $('download_popup').style.visibility = "visible";
                $('ifdownload').src = 'download.cjp.htm?id=' + fileId;
                downsubs.download.popup.onscroll();
            },
            onscroll: function() {
                if ($('download_popup').style.visibility == "visible") {
                    $('download_popup').style.top = (document.documentElement.scrollTop + 130) + "px";
                }
            }
        }
    },*/
    dock: function () {
        new MacStyleDock(document.getElementById('dock'),
        [
            {
                name: 'pub_dock_alternative4u',
                src: 'resources/images/pub_dock_alternative4u_',
                extension: '.png',
                sizes: [141, 160],
                onclick: function(){
                    window.location.href = "http://www.alternative4u.com";
                }
            },{
                name: 'pub_dock_itzizy',
                src: 'resources/images/pub_dock_itzizy_',
                extension: '.png',
                sizes: [141, 160],
                onclick: function(){
                }
            }, {
                name: 'pub_dock_lifetech',
                src: 'resources/images/pub_dock_lifetech_',
                extension: '.png',
                sizes: [141, 160],
                onclick: function(){
                    window.location.href = "http://www.lifetech-world.com";
                }
/*            }, {
                name: 'pub_dock_verbatim',
                src: 'resources/images/pub_dock_verbatim_',
                extension: '.png',
                sizes: [141, 160],
                onclick: function(){
                }*/
/*            }, {
                name: 'pub_dock_smc',
                src: 'resources/images/pub_dock_smc_',
                extension: '.png',
                sizes: [141, 160],
                onclick: function(){
                    window.location.href = "http://wlan.smc.com/home.php";
                }*/
            }
        ],
        141, 110, 160, 125, 2);
    },
    autocomplete: {
        seasonId: "",
        episodeId: "",
        seasons: function (tvshowId) {
            downsubs.loading();
            new Ajax.Request('downsubs/downsubs/SeasonsList.proteu?t=' + tvshowId, {
                onSuccess: function(result) {
                    var jsondata = eval('(' + result.responseText + ')');
                    var results = jsondata.results;
                    $("searchSeriesSeason").descendants().each(Element.remove);
                    $("searchSeriesSeason").insert('<option value="0"></option>');
                    for (var i=0;i < results.length; i++)
                    {
                        $("searchSeriesSeason").insert('<option value="' + results[i].id +'"' + ((i == 0 && downsubs.autocomplete.seasonId == "") || downsubs.autocomplete.seasonId == results[i].id ? ' selected' : '') + '>Temp. ' + results[i].value +'</option>');
                    }
                    if (downsubs.autocomplete.seasonId != "") {
                        $("searchSeriesSeason").value = downsubs.autocomplete.seasonId;
                    } else {
                        $("searchSeriesSeason").selectedIndex = 1
                    }
                    downsubs.autocomplete.episodes(results[$("searchSeriesSeason").selectedIndex - 1].id);
                    downsubs.autocomplete.seasonId = "";
                    if (results.length > 0) {
                        $('searchTextInput').style.width = "250px";
                        $("searchSeriesInput").style.visibility = "visible";
                    }
                    downsubs.unloading();
                }
            });
        },
        episodes: function (seasonId) {
            downsubs.loading();
            new Ajax.Request('downsubs/downsubs/EpisodesList.proteu?s=' + seasonId, {
                onSuccess: function(result) {
                    var jsondata = eval('(' + result.responseText + ')');
                    var results = jsondata.results;
                    $("searchSeriesEpisode").descendants().each(Element.remove);
                    $("searchSeriesEpisode").insert('<option value="0"></option>');
                    for (var i=0;i < results.length; i++)
                    {
                        $("searchSeriesEpisode").insert('<option value="' + results[i].id +'"' + ((i == 0 && downsubs.autocomplete.episodeId == "") || downsubs.autocomplete.episodeId == results[i].id ? ' selected' : '') + '>Ep. ' + results[i].value +'</option>');
                    }
                    if (downsubs.autocomplete.episodeId != "") {
                        $("searchSeriesEpisode").value = downsubs.autocomplete.episodeId;
                    } else {
                        $("searchSeriesEpisode").selectedIndex = 1
                    }
                    downsubs.autocomplete.episodeId = "";
                    downsubs.unloading();
                }
            });
        },
        change: function() {
            if ($('tvShowId').value != "") {
                $('tvShowId').value = "";
                $("searchSeriesSeason").descendants().each(Element.remove);
                $("searchSeriesInput").style.visibility = "hidden";
                $('searchTextInput').style.width = "450px";
                $("searchSeriesSeason").descendants().each(Element.remove);
                $("searchSeriesEpisode").descendants().each(Element.remove);
            }
            return true;
        },
        focus: function() {
            var options = {
                script:'downsubs/downsubs/TvshowsList.proteu?',
                varname:'t',
                json:true,
                shownoresults:true,
                maxresults:10,
                callback: function (obj) {
                    $('tvShowId').value = obj.id;
                    downsubs.autocomplete.seasons(obj.id);
                }
            };
            new AutoComplete('searchTextInput', options);
            return true;
        }
    },
    adframe: {
    load: function() {
        /*if (window.location.href.indexOf("?d=") > -1) {
            var urls = [
                "http://www.lifetech-world.com"
            ];
            var urlIndex = parseInt(urls.length * Math.random());
            if (urls[urlIndex] != "") {
                $('adframe').style.height = (document.body.clientHeight - $('adframe').offsetTop) + 'px';
                window.setTimeout("downsubs.loading();", 1000);
                window.setTimeout("$('adframe').src = '"+ urls[urlIndex] +"';", 2000);
            }
        }*/
    },
    loaded: function() {
        downsubs.unloading();
        $('adframe') && $('adframe').contentWindow && $('adframe').contentWindow.focus();
    }
    }
};

window.onscroll = function() {
    //downsubs.download.popup.onscroll();
}


window.onload = function() {
    if ($('list_area_lastinserted') && $('list_area_mostdownloaded')) {
        var h = Math.max($('list_area_lastinserted').offsetHeight, $('list_area_mostdownloaded').offsetHeight);
        if ($('list_area_lastinserted').offsetHeight == h) {
            $('list_area_mostdownloaded').style.height = (h + 15) + 'px';
        } else if ($('list_area_mostdownloaded').offsetHeight == h) {
            $('list_area_lastinserted').style.height = (h + 15) + 'px';
        }
    }
    $('loader').fade({to: 0});
    $('page_bg1').style.backgroundImage = "url(/resources/images/img_right_"+ (parseInt(3 * Math.random()) + 1) +".jpg)";
    $('page_bg2').style.backgroundImage = "url(/resources/images/img_left_"+ (parseInt(3 * Math.random()) + 1) +".jpg)";
    //downsubs.adframe.load();
}

var dropdown = {
	dropdowns: new Array(),
	showing: false,
	hidden: true,
	add: function(name, items, target, field) {
		dropdown.dropdowns.push([name, items]);
		for (var i = 0; i < items.length; i++) {
			var value = items[i];
			i++;
			$(items[i]).setAttribute('dropdown.field', field);
			$(items[i]).setAttribute('dropdown.value', value);
			$(items[i]).setAttribute('dropdown.target', target);
			$(items[i]).onclick = function () {
				$(this.getAttribute('dropdown.field')).value = this.getAttribute('dropdown.value');
				$(this.getAttribute('dropdown.target')).innerHTML = this.innerHTML;
			}
            $(items[i]).onmouseover = function() {
                downsubs.onmouseover(this);
            };
            $(items[i]).onmouseout = function() {
                downsubs.onmouseout(this);
            };
		}
	},
	show: function(name) {
		dropdown.showing = true;
		dropdown.hidden = false;
		for (var i = 0; i < dropdown.dropdowns.length; i++) {
			if (dropdown.dropdowns[i][0] == name) {
				$('searchLanguageDropDown').appear({duration: 0});
			}
		}
	},
	hide: function(name) {
		dropdown.showing = false;
		window.setTimeout("dropdown._hide('"+ name +"');", 150);
	},
	_hide: function(name) {
		if (dropdown.showing || dropdown.hidden) {
			return;
		}
		dropdown.hidden = true;
		for (var i = 0; i < dropdown.dropdowns.length; i++) {
			if (dropdown.dropdowns[i][0] == name) {
				$('searchLanguageDropDown').fade({duration: 0});
			}
		}
	}
}


function validContactForm() {
    _return = true;
    if (document.forms["frmContact"].elements["contactName"].value == "") {
        document.getElementById("contactNameAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactNameAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactEmail"].value == "") {
        document.getElementById("contactEmailAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactEmailAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactComment"].value == "") {
        document.getElementById("contactCommentAlert").style.visibility = "visible";
        _return = false;
    } else {
        document.getElementById("contactCommentAlert").style.visibility = "hidden";
    }
    if (document.forms["frmContact"].elements["contactEmail"].value != "" &&
        !emailCheck(document.forms["frmContact"].elements["contactEmail"].value)) {
        document.getElementById("contactEmailAlert").style.visibility = "visible";
        _return = false;
    }
    return _return;
}

<!-- Begin
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

function google_friendconnect_comments() {
var skin = {};
skin['FONT_FAMILY'] = 'tahoma,sans-serif';
skin['BORDER_COLOR'] = '#333333';
skin['ENDCAP_BG_COLOR'] = '#333333';
skin['ENDCAP_TEXT_COLOR'] = '#abc837';
skin['ENDCAP_LINK_COLOR'] = '#abc837';
skin['ALTERNATE_BG_COLOR'] = '#ffffff';
skin['CONTENT_BG_COLOR'] = '#ffffff';
skin['CONTENT_LINK_COLOR'] = '#88aa00';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#abc837';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#ffffff';
skin['DEFAULT_COMMENT_TEXT'] = '- o seu coment\xe1rio aqui -';
skin['HEADER_TEXT'] = 'Coment\xe1rios';
skin['POSTS_PER_PAGE'] = '5';
google.friendconnect.container.setParentUrl('/' /* location of rpc_relay.html and canvas.html */);
google.friendconnect.container.renderReviewGadget(
 { id: 'comments',
   site: '03734553120193993256',
   'view-params':{"disableMinMax":"false","scope":"PAGE","allowAnonymousPost":"true","startMaximized":"false"}
 },
  skin);
}
