﻿// JScript File
function resetRequestQuoteForm()
{
    window.document.getElementById("InputName").value="";
}

function initMenu(openIndex) {
 
        $('#VMenu ul:not(.current)').hide();
        //$('#VMenu ul ul').show();
        //$('#VMenu ul:first').show();
        //$('.open').prev().unbind('click');
        //$('.open').click(function(){return false;})
        $('.open').show();
        $('#VMenu li a').click(
        function() {//alert();
            var checkElement = $(this).next();
            if(checkElement.is('ul') && (checkElement.is(':visible:not(.open)'))) 
            {
                $('#VMenu ul:visible:not(.open)').slideUp('normal');
                return false;
            }
            if(checkElement.is('ul') && (!checkElement.is(':visible:not(.open)'))) 
            {
                $('#VMenu ul:visible:not(.open)').slideUp('normal');
                    checkElement.slideDown('normal');
                    return false;
            }
            $('.open').show();
            $('.open').prev().unbind('click');
            $('.open').prev().click(function(){return false;})
            
         
        }
    );
        $('#VMenu li li a').unbind('click');
        $('#VMenu li li a').click(function(){
            if($(this).next().length > 0)
            {
            $(this).next().slideToggle("normal");
            return false;
            }
        });
        $('#VMenu li li li a').unbind('click');
}

$(document).ready(function(){
    if($('#d1').length > 0)
        openCloseList('1');
});
function openCloseList(divNum)
{
    
    $('#d' + divNum).slideToggle('normal',function(){
        if ($('#d' + divNum).css('display') == 'none') 
        {
            window.document.getElementById("a"+divNum).src=window.document.getElementById("a"+divNum).src.replace("redOpenArrow","gray_arrow");
        } 
        else 
        {
            window.document.getElementById("a"+divNum).src= window.document.getElementById("a"+divNum).src.replace("gray_arrow","redOpenArrow");
        }
    });
}

function initRepTable(country)
{
    var CountryClass = "";
    if(typeof(country) != 'undefined' || country != null)
    {
        CountryClass = "." + country;
    }
    else if($("." + $('#ddlRegions').val()).length > 0)
        CountryClass = "." + $('#ddlRegions').val();
    else
        CountryClass = ".ISRAEL";
    
    $('#divCountriesTables tr').each(function(){
        $(this).css("background-color","#ffffff").parent().parent().css("border", "none");;
    }); 
    //alert(CountryClass + country);
    $.scrollTo(CountryClass, 1000, function(){
        $(CountryClass).css("background-color","#ededed").parent().parent().css("border", "dashed 1px #1280c9");}
    );
}
$(document).ready(function(){
//$('#tblRep').hide();
});

function resetGlossary()
{
    location.href = location.href.split('#')[0];
}

function searchGlossary()
{
    var keyword = $('#srchInput').attr('value').toLowerCase();
    $("dd").hide();
    $("dt").hide();
    
    if($('#findButton').val() == 'Reset')
    {
        resetGlossary();
    }
    
    if(keyword == "")
    {
        $("dd").show();
        $("dt").show();
        if($('.selectionhighlight').length > 0)
            resetGlossary();
    }
    else if(!$("dd:contains(" + keyword + ")").length > 0)
    {
        alert("No keywords found");
        //if($('.selectionhighlight').length > 0)
            resetGlossary();
    }
    else
    {
        $('#findButton').val('Reset');
        $("dd:contains(" + keyword + ")").each(function(){
            //alert(keyword + " - " + $(this).html().replace(keyword, '<span style="color:red;">' + keyword + '</span>'));
            $(this).show().html($(this).html().replace(keyword, "<span class='selectionhighlight'>" + keyword + "</span>")).prev().show();
        });
        
        $("dt:contains(" + keyword + ")").each(function(){
            //alert(keyword + " - " + $(this).html().replace(keyword, '<span style="color:red;">' + keyword + '</span>'));
            $(this).show().html($(this).html().replace(keyword, "<span class='selectionhighlight'>" + keyword + "</span>")).next().show();
        });
        //$("dt:contains(" + keyword + ")").show().addClass("selectionhighlight");
        $(".GlossaryLetter").parent().show();
        
        $("dd").each(function(){
            if(!$(this).next('dt').is(':visible') > 0 || !$(this).next().length > 0)
                $(this).hide();
        });
    }
}

function InitFAQItems()
{
    if(!$('.FAQItem').length)
        return;
        
    $('.FAQItem td').hide();
    
    $('.FAQItem td').each(function(){
        $(this).html("<div style='color:#1280ef;float:left; width:10px;'><b>A:</b></div><div style='width:505px; float:right;'>" + $(this).html() + "</div>");
    });
    $('.FAQItem th').each(function(){
        $(this).html("<b style='color:#1280ef;'>Q:</b>&nbsp;" + $(this).html());
        $(this).click(function(){ 
            $(this).parent().parent().find('td').toggle();
        });
    })
}

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 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 activateLoginFormOnEnter()
{
	var key = event.keyCode;
	if(key == 13)
	{
		document.LoginForm.submit();
	}
}

function Login()
{
    var User = $('#InputEmail').attr('value');
    var Password = $('#InputPassword').attr('value');
    var chkRemember = $('#chkRemember').attr('checked');
    if(trim(User) == "" || trim(Password) == "")
    {
        $('#divMsg').html('Please type email and password');
        return;
    }
    
    $.post('Module_CheckLogin.aspx', {email : User, password : Password, remember : chkRemember}, function(data){
    if(data.length > 0)
    {
          location.href = 'userArea.html';  
    }
    else
    {
        $('#divMsg').html('Invalid user information');
    }
    });
}

function Register()
{
    var Message = "";

    var InputName = $('#InputName').attr('value');
    var InputFax = $('#InputFax').attr('value');
    var InputLastname = $('#InputLastname').attr('value');
    var InputWebsite = $('#InputWebsite').attr('value');
    var InputTitle = $('#InputTitle').attr('value');
    var InputAddress = $('#InputAddress').attr('value');
    var InputCity = $('#InputCity').attr('value');
    var InputCompany = $('#InputCompany').attr('value');
    var InputEmail = $('#InputEmail').attr('value');
    var InputPhone = $('#InputPhone').attr('value');
    var InputZipCode = $('#InputZipCode').attr('value');
    var DDlCountry = $('#ddlCountry').attr('value');
    var DDlState = $('#ddlState').attr('value');
    var DDlIndustry = $('#ddlIndustry').attr('value');
    var chkRecieveInfo = $('#chkRecieveInfo').attr('checked');
    
    if(trim(InputName) == "")
        Message = Message + "First Name is Required<br/>";
    
    if(trim(InputLastname) == "")
        Message = Message + "Last Name is Required<br/>";
    
    if(trim(InputEmail) == "")
        Message = Message + "Email is Required<br/>";
    
    if(trim(InputCompany) == "")
        Message = Message + "Company is Required<br/>";
    
    if(trim(InputPhone) == "")
        Message = Message + "Phone is Required<br/>";
    
//    if(trim(DDlCountry) == "")
//    {
//        Message = Message + "Country is Required<br/>";
//    }
//    else
//    {
//        if(trim(DDlState) == "")
//        Message = Message + "State is Required<br/>";
//    }
//    
//    if(trim(DDlIndustry) == "")
//        Message = Message + "Industry is Required<br/>";
//    
    if(trim(InputZipCode) == "")
        Message = Message + "Zip Code is Required<br/>";
    if(Message != "")
    {
        $('#divMessage').html(Message);
    }
    else
    {
        $.post('Register.aspx',{InputName : InputName, InputFax : InputFax, InputLastname : InputLastname, InputWebsite : InputWebsite, 
        InputTitle : InputTitle, InputAddress : InputAddress, InputCompany : InputCompany, InputEmail : InputEmail, DDlCountry : DDlCountry, 
        InputPhone : InputPhone, DDlIndustry : DDlIndustry, InputCity : InputCity, DDlState : DDlState, chkRecieveInfo : chkRecieveInfo},
        
        function(data){
            $('#divMessage').html(data);
            //location.href = 'userArea.html';
        });
    }
}

function openWindow(theURL,winName,features) { 
    if(features=="")
        features = "scrollbars=0, menubars=0, toolbars=0, location=0, directories=0, status=0, width=330, height=150, top=200, left=300, resizable=0";    
  
    window.open(theURL,winName,features);
}

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("*") > 1 && 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.substr(0,ErrorMessge.length -1));
        return false;
    }
    else
    {
    
//        $('#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).attr('value') + "&";
//        });

        var Query = "";
        $('#divInputs input:text').each(function(){
            Query += trim($(this).parent().prev().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('value') + "&";
        });
        
        $('#divInputs input:checkbox').each(function(){
            if($(this).closest('.ConfigItem').is(':visible'))
                Query += trim($(this).parent().next().html()).replace(" ","_").replace(" ","_").replace(" ","_").replace(":","").replace("*","") + "=" + $(this).attr('checked') + "&";
        });
        
        $('#divInputs textarea').each(function(){
            Query +=  $(this).attr('title') + $(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);
        });
        return true;
    }
}

function clearForm()
{
    $('#divInputs textarea').attr('value','');
    $('#divInputs input').attr('value','');
    $('#divInputs input').attr('checked',false);
}


function showConfigOptions()
{
    if(!$('#tblConfig').length)
            return;
    
    $('#tblConfig .ConfigItem').hide();
    $('#tblConfig .ConfigItem:eq(' + $('#ddlProducts').get(0).selectedIndex + ')').show();
    
    if($('#tblConfig .ConfigItem:eq(' + $('#ddlProducts').get(0).selectedIndex + ') input:checkbox').length > 0)
        $('#divConfigHeader').show();
    else
        $('#divConfigHeader').hide();
}
