﻿

function SetSearchCategory(searchOption) {
    //var url = 'http://localhost:8088/';
    var url = 'http://www.qiosk.com/';
    var param = '';

    // thisForm = document.forms[0]
    thisForm = document.qmagsgcse
    //alert(thisForm)
    // alert(thisForm.action);
    if (searchOption == "1")//Petroleum Products
    {
        param = 'oilandgas/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:di6qsx8nkca";
    }
    else if (searchOption == "2") // Electrical Engineering
    {
        param = 'electricaleng/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:myujo2rl16a";
    }
    else if (searchOption == "3") //Insurance
    {
        param = 'insurance/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:dhszqmd_ove";
    }
    else if (searchOption == "4") //Power, Energy & Electricity
    {
        param = 'powerenergy/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:khl4wkziws8";
    }
    else if (searchOption == "5") // Telecommunications Technology
    {
        param = 'telecom/?q=' + thisForm.q.value;

        //return false;
        // thisForm.action='http://www.qiosk.com/telecom';
        //thisForm.action='http://localhost:8088/telecom';
        thisForm.cx.value = "012722360977371548741:tenfjjsci6c";
    }
    else if (searchOption == "6") //Computers & Software
    {
        thisForm.cx.value = "012722360977371548741:_uvxk9h9tpc";
    }
    else if (searchOption == "7") //Water and Waste Water Management
    {
        param = 'water/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:cx7hwvku1nm";
    }
    else if (searchOption == "8") //All
    {
        param = 'all/?q=' + thisForm.q.value;
        thisForm.cx.value = "012722360977371548741:0zcmtdkkuki";
    }

    if (param != '') {
        RedirectUrl(url + param)
        return false;
    }
    return true;
}

function RedirectUrl(url) {
    top.location.href = url;

}



function SetCatDescription(thisObj) {

    ////////// removed on 1 oct 09 not need on qiosk.com
    //////////document.getElementById('catDesc').style.visibility = "visible";

    return;

    var chosenoption = thisObj.options[thisObj.selectedIndex]

    var viewtitle = document.getElementById('viewtitle');


    if (thisObj.selectedIndex != 0)
        viewtitle.innerHTML = "Click here to view " + chosenoption.text + " titles";
    else
        document.getElementById('catDesc').style.visibility = "hidden";
}

function Validate(thisForm) {
    // alert('mk')

    //searchOption = document.getElementById("option").value
    // searchOption = getCheckedValue(thisForm.SearchOption) //for radio buttons

    //alert('not implemented yet');
    //return false;

    searchOption = getSelectedValues(thisForm.SearchOption)
    if (searchOption == "") {
        alert('Please select search category');
        return false;

    }
    if (thisForm.q.value == "") {
        alert('Please enter keyword to search');
        return false;
    }


    if (!SetSearchCategory(searchOption)) {
        return false;
    }

    // window.location.href = 'http://localhost:8088/telecom?q='+thisForm.q.value;
    //return false;

    //alert(searchOption)

    return true

}
/*******************/

//alert(querySt('q'))
function querySt(ji) {
    hu = parent.window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
    return "";
}


//FindInnerText: returns the inner text (without html) of given control.
function FindInnerText(objControl, innerText, nestingLevel) {
    //maybe microsoft already done the job for us?
    if (typeof objControl.innerText != "undefined")
        return objControl.innerText;

    //standard browser. check recursion limit:
    if ((typeof nestingLevel != "undefined") && (nestingLevel > 100))
        return innerText;

    //set defaults:
    if (typeof innerText == "undefined")
        innerText = "";
    if (typeof nestingLevel == "undefined")
        nestingLevel = 0;

    //stop condition:
    if (!objControl)
        return innerText;

    var text = objControl.nodeValue;
    if (!text)
        text = "";

    //take into consideration line breaks:
    if (objControl.nodeName.toLowerCase() == "br")
        return "\n";

    //iterate child elements:
    for (var i = 0; i < objControl.childNodes.length; i++) {
        text += FindInnerText(objControl.childNodes[i], objControl.childNodes[i].nodeValue, nestingLevel + 1);
    }

    //all done.
    return text;
}
function findLinkLen(obj) {

    return FindInnerText(obj).length

    /*for(i in obj)
    {
    //document.write("<br>" + i + " = " + obj[i]);
    // msg.innerHTML +="<br>" + i + " = " + obj[i];
    msg.innerHTML +='\n' +i ;
    }*/
}
// function findPos(obj) from http://www.quirksmode.org/js/findpos.html
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}
function findPosX(obj) {
    findLinkLen(obj);

    var curleft = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;

        } while (obj = obj.offsetParent);
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        do {

            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return curtop;
}

function showTip(obj, msgId) {

    if (msgId = '')
        return
    // alert(findPos(obj))

    // thisForm = document.forms[0]

    thisForm = document.qmagsgcse;


    msgId = getSelectedValues(thisForm.SearchOption)
    msgId = 'cat' + msgId;
    var msgBox = document.getElementById('messageBox')


    var len = findLinkLen(obj);
    //alert(l);
    var p = findPos(obj);
    var x = findPosX(obj) + 85; //len ; //obj.offsetLeft+obj.offsetWidth+5;
    var y = findPosY(obj); //obj.offsetTop;

    //alert(y);
    //alert(msgBox);
    //alert(x + " " + y);
    if (parseInt(x) != 'NaN')
        x = x + 'px';
    if (parseInt(y) != 'NaN')
        y = y + 'px';
    //alert(x + " " + y);

    msgBox.style.top = y;
    msgBox.style.left = x;

    contentsBox = document.getElementById('contents')
    contentsBox.innerHTML = document.getElementById(msgId).innerHTML;
    //alert(contentsBox);
    msgBox.style.display = "block"
    //alert('mks');
}


function show1(obj, msg) {

    // alert(findPos(obj))
    var msgBox = document.getElementById('messageBox')
    var len = findLinkLen(obj);
    //alert(l);
    var p = findPos(obj);
    var x = findPosX(obj) + 85; //len ; //obj.offsetLeft+obj.offsetWidth+5;
    var y = findPosY(obj); //obj.offsetTop;

    //alert(y);
    //alert(msgBox);
    //alert(x + " " + y);
    if (parseInt(x) != 'NaN')
        x = x + 'px';
    if (parseInt(y) != 'NaN')
        y = y + 'px';
    //alert(x + " " + y);

    msgBox.style.top = y;
    msgBox.style.left = x;

    contentsBox = document.getElementById('contents')
    contentsBox.innerHTML = msg
    //alert(contentsBox);
    msgBox.style.display = "block"
    //alert('mks');
}

function closeMsg() {
    document.getElementById('messageBox').style.display = 'none';
}

function print() {
    var newwindow = window.open("/demo/PrintTutorial.aspx?ak=" + Message);
    newwindow.blur()
}

function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}


function getSelectedValues(select) {
    var r = new Array();
    for (var i = 0; i < select.options.length; i++)
        if (select.options[i].selected)
        r[r.length] = select.options[i].value;
    return r;
}

function getSelectedTexts(select) {
    var r = new Array();
    for (var i = 0; i < select.options.length; i++)
        if (select.options[i].selected)
        r[r.length] = select.options[i].text;
    return r;
}

