﻿function OpenSimpleUrl(url){
    window.open(url);
}

function GetFormControl(controlId){
    var frm = document.forms[0];
    if (frm != undefined){
        for(var i = 0; i < frm.length; i++){
            e = frm.elements[i];
            if (e.id.indexOf(controlId) != -1){
                return e;
            }
        }
    }
    
    return null;
}

function ShowCountryListDiv(showObjId, hideObjId, topPosition, leftPosition){
    var countriesDiv = document.getElementById(showObjId);
    if (countriesDiv != undefined){
        countriesDiv.style.top = topPosition;
        countriesDiv.style.left = (document.body.clientWidth / 2) + leftPosition;
        countriesDiv.style.display = "";
    }
    
    var countriesDiv = document.getElementById(hideObjId);    
    if (countriesDiv != undefined){
        countriesDiv.style.top = 0;
        countriesDiv.style.left = 0;
        countriesDiv.style.display = "none";
    }
}

function HideCountryListDiv(objId){
    var countriesDiv = document.getElementById(objId);    
    if (countriesDiv != undefined){
        countriesDiv.style.top = 0;
        countriesDiv.style.left = 0;
        countriesDiv.style.display = "none";
    }
}

function SiteSearchSubmit(url, searchBtn) {

    var cx = GetHtmlControl("cx");
    var cof = GetHtmlControl("cof");
    var ie = GetHtmlControl("ie");
    var q = GetHtmlControl("q");

    if (cx != null && cof != null && ie != null && q != null) {
        var queryString = "cx=" + cx.value + "&cof=" + cof.value + "&ie=" + ie.value + "&q=" + q.value + "&sa=Search";
    }

    if (document.all("cx") != undefined) {
        cx = document.all("cx");
        cof = document.all("cof");
        ie = document.all("ie");
        q = document.all("q");

        if (cx != undefined && cof != undefined && ie != undefined && q != undefined) {
            var queryString = "cx=" + cx.value + "&cof=" + cof.value + "&ie=" + ie.value + "&q=" + q.value + "&sa=Search";
        }
    }

    document.location.href = url + "?" + queryString;
}

function CheckForEnter(e, urlPath) {
    var keyPressCode = 0;
    if (window.event){
        keyPressCode = e.keyCode;
    }

    if (e.which) {
        keyPressCode = e.which;
    }

    if (parseFloat(keyPressCode) == 13) {
        SiteSearchSubmit(urlPath, "");
        return false;
    }

    return true;
}

function GetHtmlControl(controlId) {
    var frm = document.forms[0];
    if (frm != undefined) {
        for (var i = 0; i < frm.length; i++) {
            e = frm.elements[i];
            if (e.name.indexOf(controlId) != -1) {
                return e;
            }
        }
    }

    return null;
}