﻿// JScript File

function callback_page_content(result)
{
    var split_array=result.split("~|~");
    for ( var i = 0 ; i < split_array.length ; i++ )
	{
	    theID = "page_content";
	    if (i > 0)
	        theID = theID + i;
	    document.getElementById(theID).innerHTML = split_array[i];
	}
}

function callback_page_content_sc(result)
{
    document.getElementById("page_content").innerHTML = result;
    GetChapterAgain(document.getElementById('selector0').options[document.getElementById('selector0').selectedIndex].value);
}

function errorCallback(result)
{
    alert(result);
}

function downloadFile()
{
	document.getElementById("downloadFile").click();
}

function callback_create_csv(result)
{
    document.getElementById("download_csv").href=result;
    document.getElementById("download_csv").click();
}

function submitASPForm(sNewFormAction)
{
    document.forms[0].action = sNewFormAction;
    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
    document.forms[0].submit();
}

function tagSelect(CollectionVal , Collectiontxt , CollectionTable)
{
    currVal = document.getElementById(CollectionTable+"_coll").value;
    if (currVal.indexOf(Collectiontxt) >= 0)
    {
        //return;
        loc = currVal.indexOf(Collectiontxt);
        len = Collectiontxt.length;
        currVal1 = currVal.substr(0 , loc);
        currVal2 = "";
        if ((loc + len) < currVal.length)
        {
            currVal2 = currVal.substr((loc + len + 1) , currVal.length - (loc + len + 1));
        }
        currVal = currVal1 + currVal2;
        document.getElementById(CollectionTable+"_coll").value = currVal;
        if (window.document.getElementById("tag_" + CollectionVal) != null)
            window.document.getElementById("tag_" + CollectionVal).className = "tags";
        closeCollDiv(CollectionTable+"_coll");
    }
    else
    {
        loc = currVal.lastIndexOf(";");
        len = currVal.length;
        currVal = currVal.substr(0 , loc + 1);
        currVal = currVal + Collectiontxt  + ";";
        document.getElementById(CollectionTable+"_coll").value = currVal;
        if (window.document.getElementById("tag_" + CollectionVal) != null)
            window.document.getElementById("tag_" + CollectionVal).className = "tags_selected";
        closeCollDiv(CollectionTable+"_coll");
    }
    
}

function isLetter(t)
{
    if (t == "T" || t == "C" ||t == "D" ||t == "S" ||t == "V" ||t == "U" ||t == "Z" ||t == "J" ||t == "Y" ||t == "H" ||t == "F" ||t == "K" ||t == "N" ||t == "B" ||t == "X" ||t == "G" ||t == "P" ||t == "M" ||t == "E" ||t == "R" ||t == "A" ||t == "," ||t == "W" ||t == "\"")
        return true;
    return false;
}

function tagKeyPress(CollectionTable , MiddleTable , collectionTextField , CollCss)
{
    if (isLetter(String.fromCharCode(event.keyCode)) == false)
        return;
    var currVal = document.getElementById(MiddleTable+"_coll").value;
    
    loc = currVal.lastIndexOf(";");
    len = currVal.length;
    theString = currVal.substr(loc + 1,len-loc);
    RS.Execute("adm_utils.aspx", "GetCollectionFill" , MiddleTable , CollectionTable , collectionTextField , theString.replace("'" , "''") , CollCss , currVal , callback_coll_fill, errorCallback);       
    return true;
}

function closeCollDiv(focusTo)
{
	oClockDiv = document.getElementById("tag_collections_div");
	oClockDiv.innerHTML="";
	if (focusTo != "")
	    document.getElementById(focusTo).focus();
}

function callback_coll_fill(result)
{
    if (result == "")
    {
        closeCollDiv("");
        return;
    }
    loc = result.indexOf("|");
    
    CollectionTable = result.substr(0 , loc);
    theTable = result.substr(loc + 1 , result.length - loc);
    var coordinates = getAnchorPosition(CollectionTable+"_coll");
   
	oDiv = document.getElementById("tag_collections_div");
	oDiv.style.display = "block";
	oDiv.style.left = coordinates.x + 300;
	oDiv.style.top = coordinates.y + 15;
	oDiv.innerHTML = theTable;
	Drag.init(oDiv);
}

function ShowBanner(path , width , height)
{
    var thePath = "adm_watch_flash.aspx?path=";
    thePath = thePath + path;
    thePath = thePath + "&width="
    thePath = thePath + width;
    thePath = thePath + "&height="
    thePath = thePath + height;
    window.open( thePath, "banner_watcher", 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height ) ;
}
