﻿// JScript File


function handleResponse(xml){
	XML = xml.getElementsByTagName("Work");
	populatePageData();	
}

function _getElementByTagName(workElement, nodeName){
    var ret = null;
    try {
       var length = workElement.childNodes.length;
        nodeName = nodeName.toLowerCase();                        
        for (var i=0; i<length; i++){
            if (workElement.childNodes[i].nodeName.toLowerCase() == nodeName){
                ret = workElement.childNodes[i];
                break;
            }
        }
    } catch(e) {
        ret = null;
    }
    return ret;
}

function getValue(num, att, theXML, add){
    //if(att=="time") alert('1');
    var workElement = theXML[num];
    var node = _getElementByTagName(workElement, att); 
    //if(att=="time") alert('2');
    var value = "";
    if (node.nodeType == 3){ //if it's a text node
            try{
                value = node.nodeValue;
                }
                catch(e){
                    value = " ";
                }
    } else {
        if (node.childNodes){
            try{
                value = node.childNodes[0].nodeValue;
            }
            catch(e){
                value = " ";
            }
        }
    }
    //if(att=="time") alert('3');
    if(add != null && add != undefined && add != "undefined" && value != " ") {
     return value+add;
        }
    else return value;
}

function getValueXml(num, att, theXML){
    var workElement = theXML[num];
    var node = _getElementByTagName(workElement, att); 
    var value = "";
    if (node.nodeType == 3){ //if it's a text node
            value = node.nodeValue;
    } else {
        if (node.childNodes){
            value = node.childNodes[0].nodeValue;
        }
    }
    return value;
}


function getData(page){
        ajax.sendRequest("GET", "phrase/"+page+"?id=3", true, "");
}


