﻿// Main menu functions
function higlightSubMenu(index, obj, item) {
    if (index == 0) {
        document.getElementById('main_navigation').className = 'page_top_main_navigation_container_hl';
        obj.className = 'main_menu_top_level_sel_fr';
    }
    else obj.className = 'main_menu_top_level_sel';
    if (document.getElementById(item + index)) {
        var container = FindPosition(obj);
        document.getElementById(item + index).style.top = container.y + obj.offsetHeight + "px";
        if (index == 0) document.getElementById(item + index).style.left = container.x - 3 + "px";
        else            document.getElementById(item + index).style.left = container.x + "px";
    }
}

function unhiglightSubMenu(index, obj, item) {
    if (index == 0) {
        document.getElementById('main_navigation').className = 'page_top_main_navigation_container';
    }
    obj.className = 'main_menu_top_level';
}

function FindPosition(obj) {
    var curleft = obj.offsetLeft || 0; 
    var curtop = obj.offsetTop || 0;
    while (obj = obj.offsetParent) {   
        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;
    }
    return { x: curleft, y: curtop };
}


// Homepage slider functions
function DoSlide(SliderID) {
    var Slider = document.getElementById(SliderID);
    if (Slider) {
        if (Slider.style.display == "block")
            Slider.style.display = "none";
        else
            Slider.style.display = "block";
    }
}

function searchClear(obj, defalutText)
{
    if (obj.value == defalutText)
    {
        obj.value = '';
    }
}
function searchSet(obj, defaultText)
{
    if ( obj.value == '' )
        obj.value = defaultText;
}
function searchDoSearch(event, uniqueId, obj)
{
    if (event.keyCode == 13)
    {
        obj.value = escapeHTML(obj.value);
        __doPostBack(uniqueId,'');
    }
}
function searchEscapeHtml(uniqueId)
{
    var searchText = document.getElementById(uniqueId);
    searchText.value = escapeHTML(searchText.value);
    return true;
}
function escapeHTML(str)
{
    //var str = str.replace(/'/g,"&quot;")
    var str = str.replace(/\&/g,"&amp;")
    str = str.replace(/>/g,"&gt;")
    str = str.replace(/</g,"&lt;")
   return str;
}

/*Check Contact page function*/
function CheckForm(firstName,phone,company,name,email)
{
    var wrongCount = 0;    
    var _SpacereqExp = new RegExp("[A-Za-z0-9_]");
    
    if(firstName!='')
    {        
        if(_SpacereqExp.test(document.getElementById(firstName).value))
        {
           document.getElementById(firstName).style.border="1px solid #DDDDDD";    
        }else
        {
            document.getElementById(firstName).style.border="1px solid red";
            wrongCount++;        
        }
    }
    
    
    if(phone!='')
    {        
        var _reqExpression = new RegExp("^[0-9]*$");
        if(!_reqExpression.test((document.getElementById(phone).value))||document.getElementById(phone).value=='')
        {   
            document.getElementById(phone).style.border="1px solid red";
            wrongCount++;
        }else{document.getElementById(phone).style.border="1px solid #DDDDDD";}
        
    }
    
    if(company!='')
    {
        if(_SpacereqExp.test(document.getElementById(company).value))
        {   
            document.getElementById(company).style.border="1px solid #DDDDDD";            
        }else
        {
            document.getElementById(company).style.border="1px solid red";
            wrongCount++;
        }
    }
    
    if(name!='')
    {
        if(_SpacereqExp.test(document.getElementById(name).value))
        {               
            document.getElementById(name).style.border="1px solid #DDDDDD";
        }else
        {
        document.getElementById(name).style.border="1px solid red";
        wrongCount++;        
        }
    }    

    if(email!='')
    {
        var reqExpression =/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;             
        if(!reqExpression.test((document.getElementById(email).value)))
        {   
            document.getElementById(email).style.border="1px solid red";
            wrongCount++;
        }else{document.getElementById(email).style.border="1px solid #DDDDDD";}
    }
    if (wrongCount > 0) return false;
    else return true;
}

function checkByRequest(FormType,firstName,phone,company,name,email)
{
    document.getElementById(firstName).style.border="1px solid #DDDDDD";    
    document.getElementById(phone).style.border="1px solid #DDDDDD";    
    document.getElementById(company).style.border="1px solid #DDDDDD";
    document.getElementById(name).style.border="1px solid #DDDDDD";
    document.getElementById(email).style.border="1px solid #DDDDDD";
    
    var localWrong = 0;
    var returnValue = false;
    
    if(document.getElementById(phone).value!='')
    {        
        var _reqExpression = new RegExp("^[0-9]*$");
        if(!_reqExpression.test(document.getElementById(phone).value))
        { 
            document.getElementById(phone).style.border="1px solid red";
            localWrong++;
        }
    }     
    
    if(document.getElementById(email).value!='')
    {
        var reqExpression =/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if(!reqExpression.test((document.getElementById(email).value)))
        {   
            document.getElementById(email).style.border="1px solid red";
            localWrong++;
        }
    }
        
    if(FormType=='RequestByPhone')
        returnValue = CheckForm('', phone, '', name, email);    
    if(FormType=='RequestByEmail')    
       returnValue = CheckForm('','','',name,email);
     if(FormType=='RequestByFeedBack')
        returnValue = CheckForm(firstName,'',company,name,email);
     
     if(returnValue && localWrong ==0)
       return true;
     else
       return false;
}

/*end check contact page function*/

function waterMarkValidate(id, regularExpr, defValue)
{
    var toReturn = new Object();
    var obj = document.getElementById(id);
    toReturn.IsValide = regularExpr.test(obj.value);
    if ( obj.value == defValue)
        toReturn.IsValide = false;
    toReturn.Object = obj;
    return toReturn;
}
function validateCaseStudyMailSend( funcResults )
{
    var result = true;
    for( var i=0; i < funcResults.length; i++)
    {
        var fnValidResult = funcResults[i];
        if (fnValidResult.IsValide)
            fnValidResult.Object.className = fnValidResult.Object.className.replace(/[\s]?casestudy_input_error/g,'');
        else 
        {
            result = false;
            fnValidResult.Object.className = fnValidResult.Object.className + ' casestudy_input_error';
        }
    }
    return result;
}

/***** RELATED WEBSITES CONTROL *****/
function ShowWebsites() {
    var Container = document.getElementById("RelatedWebsites");
    if (Container) {
        Container.style.display = "block";
        Container.style.left = (FindPosition(Container.parentNode).x + Container.parentNode.offsetWidth - Container.offsetWidth) + "px";
        Container.style.top = (FindPosition(Container.parentNode).y + Container.parentNode.offsetHeight) + "px";
        Container.parentNode.className = "relatedwebsites_header_over";
    }
}

function HideWebsites() {
    var Container = document.getElementById("RelatedWebsites");
    if (Container) {
        Container.style.display = "none";
        Container.parentNode.className = "relatedwebsites_header";
    }
}
/***** END RELATED WEBSITES CONTROL *****/
/* Begin Langyage seklector*/
function ShowSubContainer(containerElement)
{
    if(containerElement.className!='base_language_show')
    {        
        containerElement.className='base_language_show';                    
        var subLangs = document.getElementById('SubLanguages');
        if(subLangs)
        {
            subLangs.style.left = (FindPosition(subLangs.parentNode).x + subLangs.parentNode.offsetWidth - subLangs.offsetWidth) + "px";        
            subLangs.style.top = (FindPosition(subLangs.parentNode).y + subLangs.parentNode.offsetHeight) + "px";
        }
    }
    
}

function HideSubContainer(containerElement)
{    
    containerElement.className='base_language_hide';
}
/*Language selector End*/

/* Newsletter popup */
function HighlightNewsletterBox() {
    var container = document.getElementById("NewsletterPopup");
    var _control = document.getElementById("NewsletterContainer");
    if (container && _control) {
        var Position = FindPosition(container.parentNode);
        if (container.style.display == "none" || container.style.display == "") {
            container.style.display = "block";
            container.style.left = Position.x + (_control.offsetWidth / 2) + "px";
            container.style.top = Position.y - 40 + "px";
        }
        else
            container.style.display = "none";
    }
}
/* END Newsletter popup */

/*Set center position for Element*/

function SetCenterPosition(menuId, flashId, calcHeight) {
    var menuElem = document.getElementById(menuId);
    var flashElem = document.getElementById(flashId);
    var offSetByHeight = 125;
    /**/
    var widthParent;
    var heightScreen; //window.innerHeight;window.screen.height;    
    heightScreen = document.documentElement.clientHeight;


    if (menuElem != null && flashElem != null) {
        widthParent = menuElem.parentNode.offsetWidth;
        menuElem.style.left = ((widthParent / 2) - (menuElem.offsetWidth / 2)) + 'px';

        widthParent = flashElem.parentNode.offsetWidth;
        flashElem.style.left = ((widthParent / 2) - (flashElem.offsetWidth / 2)) + 'px';
    }
    if (calcHeight) {
        if (flashElem != null && menuElem != null) {
            menuElem.style.top = ((heightScreen / 2) + offSetByHeight) + 'px';
            flashElem.style.top = ((heightScreen / 2) - flashElem.offsetHeight + offSetByHeight) + 'px';
        }
    }
}

/**/


function HideMainMenuElements(parentContainerID, parentContainerMaxWidth) {
    var parentConatainer = document.getElementById(parentContainerID);
    if (parentConatainer != null) {   
        var childContainers = parentConatainer.childNodes;
        if (childContainers!=null) {
            var containersWidth = 0;
            var hideAllNext = false;
            for (var i = 0; i < childContainers.length; i++) {
                if (childContainers[i].nodeType == 1) {
                    if (hideAllNext) {
                        childContainers[i].style.display = 'none';
                        continue;
                    }
                    if (childContainers[i].clientWidth + containersWidth <= parentContainerMaxWidth) {
                        containersWidth += childContainers[i].clientWidth;
                    }
                    else {
                        childContainers[i].style.display = 'none';
                        hideAllNext = true;
                    }
                }
            }
        }
    }
}