﻿
var IsOpen = false
var intOldQID = 0
var strFirstText
var timeout = 200;
var closetimer = 0;
var ddmenuitem = 0
// open hidden layer
function mopen(id) {

    // cancel close timer
    mcancelclosetime();

    // close old layer
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';

    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';
    //ddmenuitem.style.height = 'auto';

}
// close showed layer
function mclose() {
    //if (gbIsRegret == 1) { AlterHeadingText("<" + gstrLastTagName + ">") }
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
function opendate() {
    var strURL = "/applications/calendar.aspx"
    var oReturnProperties = window.showModalDialog(strURL, window.document, "dialogWidth:360px;dialogHeight:270px; status:no;help:no;scroll:no")
    if (oReturnProperties) {
        OnDateSelection(oReturnProperties.strValidFrom, oReturnProperties.strValidTo)
    }
}
function OnDateSelection(strValidFrom, strValidTo) {
    document.formUpdateableSection.srcDate.value = strValidFrom + " " + strValidTo
}

function ajaxFunction(QID) {
    if (!IsOpen) {
    	//No question has been opened
    	strFirstText = document.getElementById(QID).innerHTML
    	document.getElementById(QID).innerHTML = '<img src="/images/indicator_medium.gif" alt="Loading question" />'
        var xmlhttp;
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP! Please upgrade your browser to recieve full functionality");
        }
        xmlhttp.onreadystatechange = function() {
        	if (xmlhttp.readyState == 4) {
        		//Add to div
        		document.getElementById(QID).innerHTML = xmlhttp.responseText;
        		document.getElementById('an' + QID).className = 'question open';
        	}
        }
        xmlhttp.open("GET", "/applications/GetFullQuestion.ashx?qid=" + QID, true);
        xmlhttp.send(null);
        intOldQID = QID;
        IsOpen = true;
    }
    else if (intOldQID == QID) {
        //Clicking the same link = close QID
        document.getElementById(QID).innerHTML = strFirstText;
        document.getElementById('an' + QID).className = 'question';
        IsOpen = false;
    }
    else {
        //Clicking a new one, close previous and open new
        document.getElementById(intOldQID).innerHTML = strFirstText;
        document.getElementById('an' + intOldQID).className = 'question';

        IsOpen = false;
        ajaxFunction(QID);
    }

}
function Submit(oLink) {
    document.getElementById('hdnCategory').value = oLink;
    //alert(oLink)
    //alert(document.getElementById('hdnCategory').value)
    document.getElementById("formUpdateableSection").submit();

}
function Step(oLink) {
    document.getElementById('hdnNumber').value = oLink;
    document.getElementById("formUpdateableSection").submit();
}   
function RewriteLinksForSearch() {
	var tmpobj = document.getElementById('stepbtns');
	
	var oLinks = tmpobj.getElementsByTagName('a');
	
	for (var i = 0; i < oLinks.length; i++) {
		if (oLinks[i].className.toLowerCase() == 'rewritea') {
			oLinks[i].href = 'javascript:Step(' + oLinks[i].innerText + ')';
		}
	}
}
