﻿
// Disable Return Key Press
document.onkeypress = DisableReturnKey;

// -----------------------------------------------------------------------------------------------
function DisableReturnKey(evt)
{
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type == "text")) { return false; }
}

// -----------------------------------------------------------------------------------------------
function SearchFocus(obj) { obj.style.backgroundColor='#f3f2f0'; }

// -----------------------------------------------------------------------------------------------
function SearchBlur(obj) { if (!trim(obj.value).length > 0) { obj.style.backgroundColor='transparent'; } }

// -----------------------------------------------------------------------------------------------
function Search(evt)
{
    var keyNum;
    if (window.event) { keyNum = evt.keyCode; } // IE
    else if (evt.which) { keyNum = evt.which; } // Netscape/Firefox/Opera

    if ((keyNum == 13) || (evt == 'do'))
    {
        var searchInput = document.getElementById('ctl00_inputSearch');
        var strSearch = trim(removeSpaces(searchInput.value));

        // Go to search page when theres a value to search for
        if (strSearch != '')
        {
            if (document.domain == 'localhost') { window.location = 'http://localhost:1000/Search.aspx?par1=' + strSearch; }
            else { window.location = 'http://' + document.domain + '/search/' + strSearch + '/'; }
        }
    }
}

// -----------------------------------------------------------------------------------------------
function ShowTab(tabCurrent, tabTotal)
{
	for (var t = 1; t <= tabTotal; t++)
    {
        addClass = false;
        if (tabCurrent == t) { addClass = true; }

        $("#tabFeedBtn"+t).toggleClass("tabActive", addClass); //swap active class
        //$("#tabFeedBtn"+t).click(blur()); // hide the focus box -> possibly causing IE window to loose focus also

        if (tabCurrent != t) { $("#tabContent"+t).css("display", "none"); }
        else { $("#tabContent"+tabCurrent).css("display", "block"); }
    }
}

// NOT IN USE
// -----------------------------------------------------------------------------------------------
function ShowThis(elmId)
{
    if (elmId != null)
    {
        theElm = document.getElementById(elmId);
        if (theElm.style.display == 'none') { $(theElm).css("display", "block"); }
        else { $(theElm).css("display", "none"); }
    }
}

// -----------------------------------------------------------------------------------------------

// http://docs.jquery.com/Attributes

// $('input[name=foo]').val();
// $('[name=foo]').val();

// $('input[name=baz]:checked').val(); <-- radio
// $('input[name="baz"]')[0].checked = true; <-- radio, possible same for checkbox

// $('#foo').val('this is some new text');

// -----------------------------------------------------------------------------------------------

//// -----------------------------------------------------------------------------------------------
//function ShowVideo(vid)
//{
//	conVidPlay.innerHTML = '<object id=\"objVidPlay\" type=\"application/x-shockwave-flash\" data=\"player.swf\" width=\"615\" height=\"420\"><param name=\"movie\" value=\"player.swf\" /><param name=\"allowFullScreen\" value=\"true\" /><param name=\"FlashVars\" value=\"configxml=videos/'+vid+'.xml\" /></object>';
//	vidTitle.innerHTML = document.getElementById(vid).innerHTML;
//}

//// jQuery slideshow - homepage only
//// -----------------------------------------------------------------------------------------------
//function processSlideshow(elem, imageList, imageDuration, fadeSpeed, current)
//{
//    var listSize = imageList.length;
//    if (!current || current >= listSize) current = 0;
//    if (!imageDuration) imageDuration = 2000;
//    if (!fadeSpeed) fadeSpeed = 1000;
//    $(elem + " img").attr("src", imageList[current]);
//    if (current == (listSize - 1)) { $(elem).css("background", "transparent url(" + imageList[0] + ") no-repeat");
//    } else {
//        $(elem).css("background", "transparent url(" + imageList[current + 1] + ") no-repeat");
//    }
//    $(elem + " img").animate({ opacity: "1" }, imageDuration).animate({ opacity: "0.01" }, fadeSpeed, function() 
//    { $(this).css("opacity", "1"); processSlideshow(elem, imageList, imageDuration, fadeSpeed, current + 1) });
//}

// onmouseover="RollOverImg(this)" onmouseout="RollOutImg(this)"
// -----------------------------------------------------------------------------------------------
function RollOverImg(elm)
{
    if (elm.id == 'imgBuscar') { $('#'+elm.id).attr('src', '/assets/images/site/btn-buscar1.gif'); }
    else if (elm.id == 'imgSocio1') { $('#'+elm.id).attr('src', '/assets/images/site/socios1b.jpg'); }
    else if (elm.id == 'imgSocio2') { $('#'+elm.id).attr('src', '/assets/images/site/socios2b.jpg'); }
    else if (elm.id == 'imgSocio3') { $('#'+elm.id).attr('src', '/assets/images/site/socios3b.jpg'); }
    else if (elm.id == 'imgSocio4') { $('#'+elm.id).attr('src', '/assets/images/site/socios4b.jpg'); }
    else if (elm.id == 'imgSocio5') { $('#'+elm.id).attr('src', '/assets/images/site/socios5b.jpg'); }
    else if (elm.id == 'imgSocio6') { $('#'+elm.id).attr('src', '/assets/images/site/socios6b.jpg'); }
    else if (elm.id == 'imgSocio7') { $('#'+elm.id).attr('src', '/assets/images/site/socios7b.jpg'); }
    else if (elm.id == 'imgSocio8') { $('#'+elm.id).attr('src', '/assets/images/site/socios8b.jpg'); }
}

// -----------------------------------------------------------------------------------------------
function RollOutImg(elm)
{
    if (elm.id == 'imgBuscar') { $('#'+elm.id).attr('src', '/assets/images/site/btn-buscar0.gif'); }
    else if (elm.id == 'imgSocio1') { $('#'+elm.id).attr('src', '/assets/images/site/socios1a.jpg'); }
    else if (elm.id == 'imgSocio2') { $('#'+elm.id).attr('src', '/assets/images/site/socios2a.jpg'); }
    else if (elm.id == 'imgSocio3') { $('#'+elm.id).attr('src', '/assets/images/site/socios3a.jpg'); }
    else if (elm.id == 'imgSocio4') { $('#'+elm.id).attr('src', '/assets/images/site/socios4a.jpg'); }
    else if (elm.id == 'imgSocio5') { $('#'+elm.id).attr('src', '/assets/images/site/socios5a.jpg'); }
    else if (elm.id == 'imgSocio6') { $('#'+elm.id).attr('src', '/assets/images/site/socios6a.jpg'); }
    else if (elm.id == 'imgSocio7') { $('#'+elm.id).attr('src', '/assets/images/site/socios7a.jpg'); }
    else if (elm.id == 'imgSocio8') { $('#'+elm.id).attr('src', '/assets/images/site/socios8a.jpg'); }
}





// -----------------------------------------------------------------------------------------------
// Useful utility functions
// -----------------------------------------------------------------------------------------------
String.prototype.startsWith = function(str)
{ return (this.match("^" + str) == str) }

// -----------------------------------------------------------------------------------------------
String.prototype.endsWith = function(str)
{ return (this.match(str + "$") == str) }

// -----------------------------------------------------------------------------------------------
String.prototype.trim = function()
{ return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")) }

// -----------------------------------------------------------------------------------------------
function removeSpaces(str)
{
    return str.replace(/\s+/, "-");
}

// -----------------------------------------------------------------------------------------------
function trim(str)
{
    var result = str.replace(/^\s+|\s+$/g, '');
    return result;
}

// -----------------------------------------------------------------------------------------------
// Supports +, (), [] and space
function isNumeric1(strIn)
{
    var validChars = "+0123456789. ()[]";
    var isNumeric = true;
    var cChar;
    if (strIn == '') { return false; }
    for (i = 0; i < strIn.length && isNumeric == true; i++)
    {
        cChar = strIn.charAt(i);
        if (validChars.indexOf(cChar) == -1) { isNumeric = false; }
    }
    return isNumeric;
}

// -----------------------------------------------------------------------------------------------
function isNumeric2(str)
{
    if (str == '') { return false; }
    var result = str.match(/^[0-9]*$/);
    return result;
}

// -----------------------------------------------------------------------------------------------
function isValidEmail(email)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if (email.match(emailExp)) { return true; }
	else { return false; }
}

// -----------------------------------------------------------------------------------------------
function createCookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

// -----------------------------------------------------------------------------------------------
//readCookie("ssCookie")
//readCookie("ssCookie", "cUserType")
// -----------------------------------------------------------------------------------------------
function readCookie(name, branch)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	var retString;

    for (var i = 0; i < ca.length; i++)
    {
	    var c = ca[i];
	    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
	    if (c.indexOf(nameEQ) == 0) { retString = c.substring(nameEQ.length, c.length); }
    }

	if (branch == null)
	{
	    return retString;
	}
	else
	{
	    var br = retString.split('&');
	    
        for (var i = 0; i < br.length; i++)
        {
	        var b = br[i];
	        while (b.charAt(0) == ' ') b = b.substring(1, b.length);
	        if (b.indexOf(branch) == 0) { retString = b.substring(branch.length, b.length).replace("=", ""); }
        }
    
	    return retString;
	}

	return null;
}

// -----------------------------------------------------------------------------------------------
function eraseCookie(name)
{
	createCookie(name, "", -1);
}
