﻿// JScript File
function initMenu(openIndex) {
 
        $('#VMenu ul:not(.current)').hide();
        
        //$('#VMenu ul:first').show();
         
        $('#VMenu li a').click(
         
        function() {
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                return false;
                }
         
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#VMenu ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
            return false;
            }
        }
    );
}

function ValidateAskUs(form) {
var valid = true;
    

    if(form.txtName.value=="" && valid){
        msg="* Required field";
        form.txtName.focus();       
        valid=false;
    }    
    if((form.txtEmail.value=="" || !isValidEmail(form.txtEmail.value)) && valid){
        document.getElementById("msg").innerHTML='Invalid email address.';
        return false;
    }
//    if(form.txtPhone.value.trim()=="" && valid){
//        msg="* Required field";
//        form.txtPhone.focus();       
//        valid=false;
//    }    
    if(form.txtQ.value =="" && valid){
        msg="* Required field";
        form.txtQ.focus();       
        valid=false;
    }    
    if(valid){
        form.action="send.aspx?type=askus";
        form.submit();
        alert("Thank you...");
    }
    else{
        document.getElementById("msgAskus").innerHTML=msg;
    }

}
function isValidEmail(str) {
   return !(typeof(str) == 'undefined' || str == null) && ((str.indexOf(".") > 2) && (str.indexOf("@") > 0));
}
function InitTopMenu()
{
    $(document).ready(function(){   
  
    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)   
  
    $("ul.topnav li span").click(function() { //When trigger is clicked...   
  
        //Following events are applied to the subnav itself (moving subnav up and down)   
        $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click   
  
        $(this).parent().hover(function() {   
        }, function(){   
            $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up   
        });   
  
        //Following events are applied to the trigger (Hover events for the trigger)   
        }).hover(function() {   
            $(this).addClass("subhover"); //On hover over, add class "subhover"   
        }, function(){  //On Hover Out   
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"   
    });   
  
});  

}

function InitTables()
{
if(typeof($('#tblMain').get(0)) == 'undefined')
        return;

$.each($('#tblMain .tblItem'), function(){
    $(this).addClass('darkBlue').next().hide();
});

$.each($('#tblMain .tblItem') , function(){
$(this).mouseover(function()
            {
                $.each($('#tblMain .tblItem'), function(){
                    $(this).removeClass('SelectedItem');
                });
                $(this).addClass('SelectedItem');
                $('#tdItemTitle').html($(this).html());
                $('#tdItemContent').html($(this).next().html());
            })
});

}

function InitTables2()
{
if(typeof($('.tblMain').get(0)) == 'undefined')
    return;

$('#tdItemContent .tblMain th').each(function(){
    $('.tblMain').hide();
    $('#divCategories').append('<a class="darkBlue">' + $(this).html() + '</a><br/>');
    $('#divCategories a').mouseover(function(){
        $('#tdItemTitle').html($(this).html());
        $('.tblMain').hide();
        $('.tblMain:eq(' + $('#divCategories a').index(this) + ')').show();
        $('#divCategories a').addClass('darkBlue');
        $(this).removeClass('darkBlue');
    });
});
$('.tblMain table td:not(.tblItem)').hide();
$('.tblMain table .tblItem').mouseover(function(){
    //$('#tdItemTitle').html($(this).closest('.tblMain').find('th').html());
    $('.tblMain table td:not(.tblItem)').hide();
    $('.tblMain table .tblItem').removeClass('tblItemOver');
    $(this).addClass('tblItemOver');
    $('#divContent2').html($(this).next().html());
    
});

}
var url = "";
function mapGoTo(i)
{
    if(url == "")
    {
        url = location.href;
        url = url.replace('#','');
    }
    location.href = url + "#table" + i;
}

function hidePopups()
{
    $("div.CompPopUp").hide();
    $("div.close").click(function(){
        $(this).parent().slideUp('normal');
    });
}

function compGoTo(i)
{
    $("div.CompPopUp").hide();
    $('#popup' + i).slideToggle("normal");
}

function InitComplianceLifeCycle()
{
    if(typeof($('#tblSteps').get(0)) == 'undefined')
        return;
        
      $('#tblSteps .StepItem img:eq(0)').attr('src',$('#tblSteps .StepItem img:eq(0)').attr('src').replace('off', 'on'));
      $('#tblStepsContent .trStep').hide();
      $('#tblStepsContent .trStep:eq(0)').show();
    $('#tblSteps .StepItem img').mouseover(function(){
        $('#tblSteps .StepItem img').each(function(){$(this).attr('src',$(this).attr('src').replace('on', 'off'));}); 
        $(this).attr('src',$(this).attr('src').replace('off', 'on'));
        $('#tblStepsContent .trStep').hide().parent().hide();
        $('#tblStepsContent .trStep:eq(' + $('#tblSteps .StepItem img').index(this) + ')').fadeIn("slow").parent().show();
    });       
}

function ValidateForm(Subject)
{
    if(!$('#divInputs').length)
        return;

    //validate
    var ErrorMessge = "";
    var valid = true;
    $('#divInputs input').each(function(){
        if($(this).parent().prev().prev().html() != null)
        {
            if($(this).parent().prev().prev().html().indexOf("*") == 0 && trim($(this).attr('value')) == "")
            {
                ErrorMessge += $(this).parent().prev().html().replace(":","") + ",";
                valid = false;
                //$(this).focus();
            }
        }
    });
    
    $('#divInputs .validateMail').each(function(){
        if(trim($(this).attr('value')).length > 0 && trim($(this).attr('value')).indexOf('@') < 2)
        {
            ErrorMessge += "Invalid " + $(this).parent().prev().html().replace(":","") + ",";
            valid = false;
            $(this).focus();
        }
    });
    
    if(!valid)
    {
        alert("Requiered fields:" + ErrorMessge);
        return false;
    }
    else
    {
    
        var Query = "";
        
        $('#divInputs input:text').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs textarea').each(function(){
            Query += "Description=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs select').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).find('option:selected').text() + "&";
        });
        
        //alert(Query);
        $.get("Send.aspx?Key=12985645&Subject=" + Subject + "&" + "FromMail=" + $('#divInputs .validateMail').attr('value') + "&" + Query, function(data){
            alert(data);
	    location.href="/";
        });
        return true;
    }
}

function InitSpecialUL()
{
    if(typeof($('#tbSpecialUl').get(0)) == 'undefined')
        return;
        
    $('#tbSpecialUl li a').click(function(){
                            //$('#tbSpecialUl li div').hide("normal");
                            if($(this).next().html() != "")
                                $(this).next().toggle();
                            return false;
                        });
}

function showTable(i)
{
    if($('.MapTable:visible').length > 0)
    {
        $('.MapTable:visible').fadeOut("normal", function(){
            $('.MapTable:eq(' + i + ')').fadeIn("normal");
        });
    }
    else
        $('.MapTable:eq(' + i + ')').fadeIn("normal");
    
}

function InitMapTables()
{
    $('.MapTable td').each(function(){
            if($(this).html() == "")
                $(this).html('&nbsp;');
        });
    $('.MapTable').hide();
}

function SearchKeyword()
{
    var searchKeyword = trim($('#txtSearch').attr('value'));
    if(searchKeyword != "")
        location.href = 'search_' + searchKeyword + '.html';
}

function Search() 
{
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) 
    {
        document.getElementById('SearchButton').click();
        return false;
    }
    return true;
}

function trim(strText) 
{    
while('' + strText.charAt(0) == ' ') 
{        strText = strText.substring(1, strText.length);    }    
while('' + strText.charAt(strText.length-1)==' ') {        
strText = strText.substring(0, strText.length-1);    }   
 return strText;
 }


function InitLogin()
{
    if($('#divLogIn').length)
    {
        $('#divLogIn').show();
    }
}

function ValidateLogin()
{
    if($('#chkTerms').get(0).checked)
    {
        if(ValidateForm('Market Access'))
            $('#divLogIn').hide();
    }
    else
        alert('Please accept Terms & Conditions');
}