﻿// 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 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 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 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 = location.href;
        });
        return true;
    }
}

function isValidEmail(str) 
{
   return !(typeof(str) == 'undefined' || str == null) && ((str.indexOf(".") > 2) && (str.indexOf("@") > 0));
}

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 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)) 
    {
        $('#SearchButton').click();
        return false;
    }
    return true;
}

function InitMapTable()
{
    if(!('.Continent').length > 0)
        return;

    $('.Continent').hide();
    $('.country').hide();
}

function showTable(country)
{
    if(!('.Continent').length > 0)
        return;

    $('.Continent').hide();
    $('.country').hide();
    $('.Continent a').each(function(){
     //alert($(this).attr('name'));
     if($(this).attr('name') == country)
     {
        //$.prettyPhoto.open($(this).closest('.Continent'),'Title','Description');
        $('#inline-1').html($(this).closest('.Continent'));
        $(this).closest('.Continent').show();
        $(this).closest('.country').show();
        $('#aPopupOpen').click();
     }
    });
}

function InitFlash()
{
//    if($(".zoom").length > 0)
//    {
//        $(".zoom").attr("rel","prettyPhoto[flash]");
//    }
      //$(".zoom[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
}

function InittblSupport()
{
    $('.tblSupport a').each(function(){
        $(this).hover(function(){
            $(this).parent().parent().find('td').css('color','#0054b1');
        },function(){
            $(this).parent().parent().find('td').css('color','#5a5a5a');
        });
    });
}