$(document).ready(function() {

    /*kentico BizForm apply this class to the image submit button*/
    $(".FormButton").hover(
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
	  },
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_on", "_off"));
	  }
	);
    /*you can apply this class to image buttons so they will have rollover effections*/
    $(".ImageButton").hover(
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
	  },
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_on", "_off"));
	  }
	);

    /*any pages use Tab menu layout: News & Events, Resources etc. */
    $(function() {
        $("#tabs").tabs();
        //$("#tabs").bind("tabsselect", function(event, ui) {ui.tab.hash=window.location.hash;})

    });


    /* User Event */
    $('.eventDate').click(function() {
        $(this).next('div').slideToggle('slow').siblings('div:visible');
        $(this).toggleClass('active');
        $(this).siblings('.eventDate').removeClass('active');
        var expando = $(this).children('img').attr("src");
        if (expando == '/images/plus.gif') $(this).children('img').attr("src", "/images/minus.gif");
        else $(this).children('img').attr("src", "/images/plus.gif");
    });


    /* News & Events */
    //alert(document.location.href.lastIndexOf('NewsEvents.aspx#tabs1'));
    if (0 < document.location.href.toLowerCase().lastIndexOf('newsevents.aspx#tabs1')) {
        $("#tabs-1").show();
        $("#tabs-2").hide();
        $("li#tabNews a").addClass("selected");

    } else if (0 < document.location.href.toLowerCase().lastIndexOf('newsevents.aspx#tabs2')) {
        $("#tabs-2").show();
        $("#tabs-1").hide();
        $("li#tabEvents a").addClass("selected");
    } else if (0 < document.location.href.toLowerCase().lastIndexOf("/newsevents/news/")) {
        $("#tabs-1").show();
        $("#tabs-2").hide();
        $("li#tabNews a").addClass("selected");
    } else if (0 < document.location.href.toLowerCase().lastIndexOf("/newsevents/events/")) {
        $("#tabs-1").hide();
        $("#tabs-2").show();
        $("li#tabEvents a").addClass("selected");
    } else if (0 < document.location.href.toLowerCase().lastIndexOf('/newsevents')) {
        $("#tabs-1").show();
        $("#tabs-2").hide();
        $("li#tabNews a").addClass("selected");
    }

    $("li#tabNews a").click(function() {
        $("#tabs-1").show();
        $("#tabs-2").hide();
        $("li#tabNews a").addClass("selected");
        $("li#tabEvents a").removeClass("selected");
    });

    $("li#tabEvents a").click(function() {
        $("#tabs-2").show();
        $("#tabs-1").hide();
        $("li#tabEvents a").addClass("selected");
        $("li#tabNews a").removeClass("selected");
    });


    /* Resources */
	if (0 < document.location.href.toLowerCase().lastIndexOf('resources.aspx?tabs-1')) {
        $("#tabs").tabs('select', 0)
    }
    if (0 < document.location.href.toLowerCase().lastIndexOf('resources.aspx?tabs-2')) {
        $("#tabs").tabs('select', 1)
    }
    if (0 < document.location.href.toLowerCase().lastIndexOf('resources.aspx?tabs-3')) {
        $("#tabs").tabs('select', 2)
    }
    if (0 < document.location.href.toLowerCase().lastIndexOf('/resources/rental-demo-viewer.aspx?video=0')) {
        $.cookie('DemoPage', '888c8604-1a42-4679-8b7a-079a28c67a56', { path: '/' });//dev:339bc10d-b613-4877-9a1f-d4c9be4de58a
        $.cookie('DemoVideo', '?video=0', { path: '/' });
        $.cookie('RegisterFor', 'equip-soft Rentals Demo', { path: '/' });
        if ($.cookie('ResourcesRegister')) {

        } else {
            document.location.href = '/Resources/Registration.aspx';
        }
    } else if (0 < document.location.href.toLowerCase().lastIndexOf('/resources/service-demo-viewer.aspx?video=1')) {
        $.cookie('DemoPage', '8827116b-3817-4afc-bd27-1be81786b583', { path: '/' });//dev:7e3474d3-1892-4d52-9659-047dff2e9edc
        $.cookie('DemoVideo', '?video=1', { path: '/' });
        $.cookie('RegisterFor', 'equip-soft Service Demo', { path: '/' });
        if ($.cookie('ResourcesRegister')) {

        } else {
            document.location.href = '/Resources/Registration.aspx';
        }
    } else if (0 < document.location.href.toLowerCase().lastIndexOf('/resources/parts-demo-viewer.aspx?video=2')) {
        $.cookie('DemoPage', 'd3dd2c61-e5b0-4a7a-90d0-e59d3c7bdd90', { path: '/' });//dev:f89c7a6b-c4f3-4d39-b2be-98135bf79ab1
        $.cookie('DemoVideo', '?video=2', { path: '/' });
        $.cookie('RegisterFor', 'equip-soft Parts Demo', { path: '/' });
        if ($.cookie('ResourcesRegister')) {

        } else {
            document.location.href = '/Resources/Registration.aspx';
        }
    } else if (0 < document.location.href.toLowerCase().lastIndexOf('/resources/sales-demo-viewer.aspx?video=3')) {
        $.cookie('DemoPage', '669baaab-4d84-4c70-9d55-ce05dce0abd8', { path: '/' });//dev:723f5fd6-1b4e-4241-b6b6-8071b3fa92bf
        $.cookie('DemoVideo', '?video=3', { path: '/' });
        $.cookie('RegisterFor', 'equip-soft Sales Demo', { path: '/' });
        if ($.cookie('ResourcesRegister')) {

        } else {
            document.location.href = '/Resources/Registration.aspx';
        }
    }

    $("a.checkCookies").click(function() {
        
		if (0 < document.location.href.lastIndexOf('/Products---Services/Parts.aspx')) {
        $.cookie('DemoPage', 'fc837b8c-7c1f-4145-86a3-78b3ab1ea36a', {path: '/'});
        $.cookie('DemoVideo', '?video=2', {path: '/'});
        $.cookie('RegisterFor', 'equip-soft Parts Demo', { path: '/' });
        } else if (0 < document.location.href.lastIndexOf('/Products---Services/Rentals.aspx')) {
        $.cookie('DemoPage', 'fc837b8c-7c1f-4145-86a3-78b3ab1ea36a', {path: '/'});
        $.cookie('DemoVideo', '?video=0', {path: '/'});
        $.cookie('RegisterFor', 'equip-soft Rentals Demo', { path: '/' });
        } else if (0 < document.location.href.lastIndexOf('/Products---Services/Service-Management.aspx')) {
        $.cookie('DemoPage', 'fc837b8c-7c1f-4145-86a3-78b3ab1ea36a', {path: '/'});
        $.cookie('DemoVideo', '?video=1', {path: '/'});
        $.cookie('RegisterFor', 'equip-soft Service Demo', { path: '/' });
        } else if (0 < document.location.href.lastIndexOf('/Products---Services/Sales---Customer-Relationship-Management.aspx')) {
        $.cookie('DemoPage', 'fc837b8c-7c1f-4145-86a3-78b3ab1ea36a', {path: '/'});
        $.cookie('DemoVideo', '?video=3', {path: '/'});
        $.cookie('RegisterFor', 'equip-soft Sales Demo', { path: '/' });
        } else if (0 < document.location.href.lastIndexOf('/About-Us.aspx')) {
        $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', {path: '/'});
        $.cookie('DemoVideo', '?tabs-1', {path: '/'});
        $.cookie('RegisterFor', 'Download Industry Built Equip-Soft Brochure Proof', { path: '/' });
        } else  if (0 < document.location.href.toLowerCase().lastIndexOf('/resources')) {
            $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', { path: '/' });
            $.cookie('DemoVideo', '?tabs-1', { path: '/' });
            $.cookie('RegisterFor', this, { path: '/' });
			
		
			
            /*$("#tabs-1 a").click(function () { 
            $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', {path: '/'});
            $.cookie('DemoVideo', '#tabs-1', {path: '/'});		
            });
            $("#tabs-2 a").click(function () { 
            $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', {path: '/'});
            $.cookie('DemoVideo', '#tabs-2', {path: '/'});
            });
            $("#tabs-3 a").click(function () { 
            alert('hi');
            $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', {path: '/'});
            $.cookie('DemoVideo', '#tabs-3', {path: '/'});
            });*/
        }
//        else if (0 < document.location.href.toLowerCase().lastIndexOf('/about')) {
//            $.cookie('DemoPage', 'e0a305f5-1774-4125-9189-b814c194a675', { path: '/' });
//            $.cookie('DemoVideo', '?tabs-1', { path: '/' });
//            $.cookie('RegisterFor', this, { path: '/' });
//		    
//        }
       
        if ($.cookie('ResourcesRegister')) {

        } else {
            this.href = '/Resources/Registration.aspx';
            this.target = '_self';
        }

    });

//alert($.cookie('ResourcesRegister'));
    
	if (($.cookie('RegisterFor')) && ($(".HiddenTextBoxField"))) {
		$(".HiddenTextBoxField").attr("value",$.cookie('RegisterFor'));
		//alert($(".HiddenTextBoxField").attr("value"));
	}
    //alert(document.location.href.lastIndexOf('/Resources.aspx') + $.cookie('DemoVideo'));

    /*//alert(document.location.href);
    if (0 < document.location.href.lastIndexOf('Resources.aspx#demos')) {
		
	} else if (0 < document.location.href.lastIndexOf('Resources.aspx#casestudies')) {
		
	}
    $("li#tabProduct a").click(function () { 
    $("#tabs-1").show();
    $("#tabs-2").hide();
    $("#tabs-3").hide();
    });
	
	$("li#tabDemos a").click(function () { 
    $("#tabs-2").show();
    $("#tabs-1").hide();
    $("#tabs-3").hide();
    });
	
	$("li#tabCase a").click(function () { 
    $("#tabs-3").show();
    $("#tabs-1").hide();
    $("#tabs-2").hide();
    });*/
    function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return ""
    }

    function setCookie(c_name, value, expiredays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
    }

    function checkCookie() {
        username = getCookie('username');
        if (username != null && username != "") {
            alert('Welcome again ' + username + '!');
        }
        else {
            username = prompt('Please enter your name:', "");
            if (username != null && username != "") {
                setCookie('username', username, 365);
            }
        }
    }

    $('input.sendToFriendEmailTextbox').val("Email Address");
    $('input.sendToFriendEmailTextbox').css({ 'color': 'rgb(153,153,153)' });

    $("input.sendToFriendEmailTextbox").focus(function () {
		if(this.value == 'Email Address'){
			this.value='';	
			$(this).css({'color' : 'rgb(0,0,0)'});				
		}
	});
$("input.sendToFriendEmailTextbox").blur(function () {
		if(this.value==''){this.value='Email Address';}
		$(this).css({'color' : 'rgb(153,153,153)'});	
	});

	

/*Bing Search*/
	if ($('#WLSearchBoxButton')){
		$('#WLSearchBoxButton').click(function(){
			constructBingSearchString();			   
		});
	}
	
	$(function(){
		$('#WLSearchBoxInput').keydown(function(e){
			if (e.keyCode == 13) {
				constructBingSearchString();
				return false;
			}
		});
	});
	
	function constructBingSearchString() {
		var formTarget = "http://www.bing.com/search?go=&qs=n&sk=&sc=5-11"; // http://www.bing.com/search?q=tools&go=&form=QBLH&qs=n&sk=&sc=5-11&q1=site:equip-soft.com
		if ($('#WLSearchBoxInput').val() != '') {
			formTarget = formTarget + '&q=' + $('#WLSearchBoxInput').val(); // keyword field
		}
		if ($('.WLSearchBoxFORM').val() != '') {
			formTarget = formTarget + '&FORM=' + $('.WLSearchBoxFORM').val();
		}
		if ($('.WLSearchBoxq1').val() != '') {
			formTarget = formTarget + '&q1=' + $('.WLSearchBoxq1').val(); // domain of your site
		}
		//alert(formTarget);
		window.open(formTarget,'newpage',''); // 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'			
	
	}


});
