﻿//------------------------------------------------//
//         PDF Popup Functions                    //
//------------------------------------------------//

// Global Variables
var SmallerDivXDifference;
var SmallerDivYDifference;
var mousex;
var mousey;
var isRegistrant;
var isIe6 = false;

// Div ID/Name variables
var MainDivId;
var ContentDivId;
var OverflowDivId;
var SummaryDivId
var ContentIframeId;
var PdfDivId;
var IframeDivId;
var ResizeDivId;
var ResizeImageId;

// Height and Top Variables
var ContentHeight;
var ResizeHeight;
var PdfHeight;
var ContentTop;

// PDF Source
var PdfSourceFile = "";

// Add to Ebinder Variable
var submitParameters = "";

// Used for PDF Popup
var IE = document.all ? true : false;
if (!IE) {
    window.captureEvents(Event.MOUSEMOVE);
    window.onmousemove = savepos;
    document.onscroll = savepos;
} else {
    document.onmousemove = savepos;
    document.onscroll = savepos;
}

//// Initializes Popup Window settings
function initializePDF(MainDivTemp,ContentDivTemp,OverflowDivTemp,SummaryDivTemp,ContentIframeTemp,PdfDivTemp,IframeDivTemp,ResizeDivTemp,RegistrantUser,OpenPdfFile,LibraryId,DocumentId,ProductName,hqCall,hqClientType)
{

    if (hqCall == ''){
        hqCall = 'False';
        hqClientType = '0';
    }else{
        hqCall = 'True';
    }

    //initialize position cookie if it doesn't exist
    var positionCookieInformation = document.cookie.toString();
    if (positionCookieInformation.indexOf('UserDocumentPlacementInformation') == -1) {
        updatePlacementCookie('10','10','960','260',true)
    }

	MainDivId = document.getElementById(MainDivTemp);
	ContentDivId = document.getElementById(ContentDivTemp);
	OverflowDivId = document.getElementById(OverflowDivTemp);
	ContentIframeId = document.getElementById(ContentIframeTemp);
	PdfDivId = document.getElementById(PdfDivTemp);
	IframeDivId = document.getElementById(IframeDivTemp);
	ResizeDivId = document.getElementById(ResizeDivTemp);
    isRegistrant = RegistrantUser


    ContentIframeId.style.display = "none";
    ContentIframeId.style.position = "absolute";
    


    setWidth(794);

	ContentHeight = 26;
	PdfHeight = 455;
	setHeight(true);
	
	calculateLeft(5);
	calculateTop(5);
	if (!isRegistrant){
	    var pageName = (window.location.toString()).toLowerCase();
	    
	    if (OpenPdfFile == '1')
	    {
            if (pageName.indexOf('ebinder') != -1) {
                if (pageName.indexOf('default') == -1) {
                    //GM eBinder PDF small
                    if (hqCall == 'True' && hqClientType == '0'){
                        parent.openPDF(readPlacementCookie(0),readPlacementCookie(1),readPlacementCookie(2),'156',readPlacementCookie(3),LibraryId,DocumentId,'informationDiv','true','','',RegistrantUser,'','','',ProductName);
                    }else if (hqCall == 'False'){
                        openPDF(readPlacementCookie(0),readPlacementCookie(1),readPlacementCookie(2),'156',readPlacementCookie(3),LibraryId,DocumentId,'informationDiv','true','','',RegistrantUser,'','','',ProductName);
                    }
                }
            }
	    }
    }
}

// This function is called when the PDF icon is clicked.
// Sets the source PDF and calls the top, left, height, 
// and width functions

function openPDF(SetTop,SetLeft,NewWidth,SetContentHeight,SetPdfHeight,LibraryId,ProductId,InformationDivId,Ebinder,AllowAdd,SourceTypeId,RegistrantUser,customerAdministratorId,customerUserId,sourcePageName,productName,hqClientType,msdsonlineDocumentId,passedBrowserName,passedBrowserVersion)
{



    productName = placeSpecialCharacters(productName);
    if ((LibraryId + '') != '') {//if adminid and docid are 'undefined', this function will break
        
        if (typeof passedBrowserName != 'undefined'){
            browserName = passedBrowserName;
            browserVersion = passedBrowserVersion;
        }
        
        IframeDivId.style.display = "block";
        
        updatePlacementCookie(SetTop,SetLeft,NewWidth,SetPdfHeight,true)
        
        //must have this be parent.scroll for hq to work as well.
        parent.scroll(0,0);

        var LibraryDirectory = LibraryId.toString().substring(0,3);
	    PdfSourceFile = httpPath + libraryPath + LibraryDirectory + "/" + LibraryId + ".pdf";
        if (!Ebinder && AllowAdd == true) {
            document.getElementById('SearchAddMsds').style.display = "block";
            submitParameters = "MsdsDocumentId=" + msdsonlineDocumentId;
            var urlParameters = new Array();
            var individualValues = new Array();
            urlParameters = document.location.search.replace('?','').split("&");
            for (i=0;i<=urlParameters.length-1;i++){
                individualValues = urlParameters[i].split("=");
                switch (individualValues[0]){
                    case "PageNumber":
                        submitParameters = submitParameters + '&PageNumber=' + individualValues[1];
                        break;
                    case "Sort":
                        submitParameters = submitParameters + '&Sort=' + individualValues[1];
                        break;
                    case "SortDirection":
                        submitParameters = submitParameters + '&SortDirection=' + individualValues[1];
                        break;
                    case "FolderName":
                        submitParameters = submitParameters + '&FolderName=' + individualValues[1];
                        break;
                    case "PageName":
                        submitParameters = submitParameters + '&PageName=' + individualValues[1];
                        break;
                }
            }
        }else{
            document.getElementById('SearchAddMsds').style.display = "none";
        }
        if(LibraryId.length > 6){
            PdfSourceFile = UserUploadsDirectory + LibraryId + ".pdf";
        }
        
	    // IE6 hack
	    if (browserName == "IE" && browserVersion < 7) {
	        isIe6 = true;
	        ContentIframeId.style.display = "block";
            // set z-index to fix a bug in IE 6 where select menus are rendered on top of divs that are supposed to be in front
	        ContentIframeId.style.display = "block";
	        MainDivId.style.zIndex = "+2";
            ContentDivId.style.zIndex = "+2";
            OverflowDivId.style.zIndex = "+2";
            ContentIframeId.style.zIndex = "+1";
            PdfDivId.style.zIndex = "+2";
            IframeDivId.style.zIndex = "+2";
            ResizeDivId.style.zIndex = "+2";
            ContentIframeId.style.border = "0px white solid";
            ContentIframeId.style.marginTop = "-0px"
            ContentIframeId.style.marginLeft = "-0px"
	    }

	    setWidth(NewWidth);
    	
	    ContentHeight = 26;
	    PdfHeight = SetPdfHeight;
	    setHeight(true);
    	
	    calculateLeft(SetLeft);
	    if (isIe6) {
	        SetTop = parseInt(SetTop) + 3;
	    }
	    ContentTop = SetTop;
	    calculateTop(SetTop);

	    MainDivId.style.visibility = "visible";
	    IframeDivId.src = PdfSourceFile;
        
        //Used for inserting the "open pdf" event (function recordPDFOpenEvent)
        if (customerAdministratorId > 0) {openPDFCustAdminId = customerAdministratorId;} else {openPDFCustAdminId = 0;}
        openPDFCustUserId = customerUserId;
        openPDFSourceId = sourcePageName;
        openPDFDocumentId = ProductId;
        
        //set the productname
        document.getElementById('PdfProductNameDisplay').innerHTML = productName;
        
        ContentDivId.style.height = ContentHeight + "px";
        OverflowDivId.style.height = ContentHeight + "px";
        oldContentHeight = "140";
        
        var pageName = (window.location.toString()).toLowerCase();
        if (pageName.indexOf('search') != -1 || pageName.indexOf('findmsds') != -1) {
                oldContentHeight = "110";
        }else if (pageName.indexOf('ebinder') != -1) {
            if (pageName.indexOf('default') == -1) {
                //GM eBinder PDF small
                oldContentHeight = "156";
            }
        }
        
        heightDifference = oldContentHeight - ContentHeight;
        MainDivId.style.height = (parseInt(MainDivId.style.height) - heightDifference) + "px";  
        
        //insert the "open pdf" event
        if (pageName.indexOf('findmsds') > -1) {
            recordPDFOpenEventRegistrant(openPDFCustAdminId, openPDFCustUserId, openPDFDocumentId, openPDFSourceId);
        } else if (pageName.indexOf('ebinder') > -1 || pageName.indexOf('search') > -1 || pageName.indexOf('queue') > -1 || pageName.indexOf('approvalmanager') > -1) {
            recordPDFOpenEvent(openPDFCustAdminId, openPDFCustUserId, openPDFDocumentId, openPDFSourceId);
        }
         
    }
}

// Sets the width of the divs
function setWidth(NewWidth)
{
    if (NewWidth < 450){
        NewWidth = 450;
    }
	MainDivId.style.width = NewWidth + "px";
	ContentDivId.style.width = NewWidth + "px";
	OverflowDivId.style.width = NewWidth + "px";
	// IE6 hack
    if (isIe6) {
        if ((parseInt(ContentIframeId.style.width) + 4) == parseInt(NewWidth)) {
	        ContentIframeId.style.width = NewWidth + "px";
	        ContentIframeId.width = NewWidth + "px";
	    }else {
	        ContentIframeId.style.width = (parseInt(NewWidth) + 4) + "px";
	        ContentIframeId.width = (parseInt(NewWidth) + 4) + "px";
	    }
	}else{
	    ContentIframeId.style.width = NewWidth + "px";
	    ContentIframeId.width = NewWidth + "px";
	}


	PdfDivId.style.width = NewWidth + "px";
	IframeDivId.style.width = NewWidth + "px";
	ResizeDivId.style.width = NewWidth + "px";
	document.getElementById('SearchTextDiv').style.width = (NewWidth - 30) + "px";
	document.getElementById('HeaderTextDiv').style.width = (NewWidth - 8) + "px";
	if (document.getElementById('AddMsdsButtonContainer')){
	    document.getElementById('PdfProductNameDisplay').style.width = (NewWidth - 97) + "px";
	}else{
	    document.getElementById('PdfProductNameDisplay').style.width = (NewWidth - 51) + "px";
	}
}

// Sets the height for all the divs
function setHeight(adjustHeight)
{
	ResizeHeight = 26;
	HeightAdjustment = 114;
	ContentDivId.style.height = ContentHeight + "px";
	OverflowDivId.style.height = 26;

	PdfDivId.style.height = PdfHeight + "px";
    IframeDivId.style.height = PdfHeight + "px";
	ResizeDivId.style.height = ResizeHeight + "px";
	
	
	// IE6 hack
	if (isIe6) {
	    ContentIframeId.style.height = "0px";
	    //use the content iframe to block out select boxes and remove the PDF window while dragging
        //additionally, fixes for a div/select menu bug in IE 6    
        ContentIframeId.style.height = (parseInt(PdfDivId.style.height) + parseInt(ResizeDivId.style.height) + 30 ) + "px";
    }else{
        ContentIframeId.style.height = (parseInt(ContentHeight) + 5) + "px";
	    ContentIframeId.height = (parseInt(ContentHeight) + 5) + "px";
    }
    
    
	var MainDivHeight = 0;
    MainDivHeight = parseInt(ContentHeight) + parseInt(PdfHeight) + parseInt(ResizeHeight);
    if (adjustHeight){
        MainDivHeight = MainDivHeight + HeightAdjustment;
        var pageName = (window.location.toString()).toLowerCase();
        if (pageName.indexOf('ebinder') != -1 && pageName.indexOf('default') != -1) {
           //MainDivHeight = MainDivHeight; // Do nothing
        }else if (pageName.indexOf('ebinder') != -1) {
            MainDivHeight = MainDivHeight + 16;
        }else if(pageName.indexOf('search') != -1){
            MainDivHeight = MainDivHeight - 30;
        }else if(pageName.indexOf('findmsds') != -1){
            MainDivHeight = MainDivHeight - 30;
        }
    }
	MainDivId.style.height = MainDivHeight + "px";

}

// Sets the Top for the 4 main divs used in the PDF Popup
function calculateTop(MovableDefault)
{
	var CalculateTop = MovableDefault;
	MainDivId.style.top = MovableDefault + "px";
	var temp = 0;

	if (browserName != "IE") {
	    temp = MovableDefault;
	} else {
	    if (browserVersion >= 7) {
	        temp = MovableDefault;
	    }
	}

	ContentDivId.style.top = (CalculateTop - temp) + "px";
	OverflowDivId.style.top = (CalculateTop - temp) + "px";
	ContentIframeId.style.top = (CalculateTop - temp) + "px";
	ContentIframeId.top = (CalculateTop - temp) + "px";
	PdfDivId.style.top = (CalculateTop - temp) + "px";
	ResizeDivId.style.top = (CalculateTop - temp) + "px";
}

// Sets the Left for the 4 main divs used in the PDF Popup
function calculateLeft(LeftDefault)
{
	MainDivId.style.left = LeftDefault + "px";
	var temp = 0;

	if (browserName != "IE") {
	    temp = LeftDefault;
	} else if (browserVersion >= 7) {
	    temp = LeftDefault;
	}
	
	ContentDivId.style.left = (LeftDefault - temp) + "px";
	OverflowDivId.style.left = (LeftDefault - temp) + "px";
	ContentIframeId.style.left = (LeftDefault - temp) + "px";
	ContentIframeId.left = (LeftDefault - temp) + "px";
	PdfDivId.style.left = (LeftDefault - temp) + "px";
	ResizeDivId.style.left = (LeftDefault - temp) + "px";
}

// Sets up the variables for the drag and drop 
// and calls the function to watch the mouse movements.
function startDivDrag()
{
    if (document.documentElement.scrollTop == 0 && document.documentElement.scrollLeft == 0){

        // IE6 hack
        if (! (isIe6) ) {
            ContentIframeId.style.height = parseInt(ContentIframeId.style.height) + parseInt(PdfDivId.style.height);
        }
        
        PdfDivId.innerHTML = '<div class="ts7" style="text-align:center;padding-top:100px;" >Moving Window...<div class="ts2" style="font-weight:normal;padding-top:20px;">Click and drag the title bar of the PDF view window to the desired location. <br /> When finished, release the mouse button to apply your change.</div></div>';

        if (browserName != "IE") {
            window.captureEvents(Event.MOUSEMOVE);
            window.onmousemove = moveMouse;
            document.onscroll = moveMouse;
        } else {
            document.onmousemove = moveMouse;
            document.onscroll = moveMouse;
            document.onselectstart = function () { return false; };
        }
        SmallerDivXDifference=mousex-parseInt(MainDivId.style.left);
        SmallerDivYDifference=mousey-parseInt(MainDivId.style.top);
    }
}

// Sets up the variables for the resize 
// and calls the function to watch the mouse movements.
function startResize()
{
    if (document.documentElement.scrollTop == 0 && document.documentElement.scrollLeft == 0){
                

        // IE6 hack
        if (! (isIe6) ) {
            ContentIframeId.style.height = parseInt(ContentIframeId.style.height) + parseInt(PdfDivId.style.height) + parseInt(ResizeDivId.style.height);
        }

        PdfDivId.innerHTML = '<div class="ts7" style="text-align:center;padding-top:100px;" >Resizing Window...<div class="ts2" style="font-weight:normal;padding-top:20px;">Move your mouse to set the PDF view window to the desired size.<br /> When finished, click the resize icon again to apply your change.</div></div>';
        
        if (browserName != "IE") {
            window.captureEvents(Event.MOUSEMOVE);
            window.onmousemove = divResize;
            document.onscroll = divResize;
        } else {
            document.onmousemove = divResize;
            document.onscroll = divResize;
            document.onselectstart = function () { return false; };
        }
        SmallerDivXDifference=mousex-parseInt(MainDivId.style.left);
        SmallerDivYDifference=mousey-parseInt(MainDivId.style.top);
        IframeDivId.src =  currentServerUrl + 'Images/Spacer.gif';
    }
}

// Saves the location for both the drag and drop and the resize
function endDivDrag()
{
    if (browserName != "IE") {
        window.captureEvents(Event.MOUSEMOVE);
        window.onmousemove = savepos;
        document.onscroll = savepos;
    } else {
        document.onmousemove = savepos;
        document.onscroll = savepos;
        document.onselectstart = null;
    }
    
    mousex=tempX;
    mousey=tempY;

    PdfDivId.innerHTML = '<iframe frameborder="0" id="SearchShowPDF" src="' + currentServerUrl + '"Images/Spacer.gif" style="padding:0;margin:0;"></iframe>';
    IframeDivId = document.getElementById('SearchShowPDF');
    IframeDivId.src = PdfSourceFile;
    setHeight(false);

    // IE6 hack
    if (isIe6) {
        setWidth(parseInt(ContentIframeId.style.width) - 4);
    }else{
        setWidth(parseInt(ContentIframeId.style.width));
    }
    
    //update placement cookie
    updatePlacementCookie(parseInt(MainDivId.style.top),parseInt(MainDivId.style.left),parseInt(MainDivId.style.width),parseInt(IframeDivId.style.height),true);
}

// Tracks the mouse movement for the drag and drop 
// and calls the function to set the Top and Left
function moveMouse(NewEvent)
{
    //var IE = document.all ? true : false;
    if (browserName == "IE")
    {
        tempX = event.clientX;
        tempY = event.clientY;
        scrollposY=document.documentElement.scrollTop
        scrollposX=document.documentElement.scrollLeft
    }
    else
    {
        tempX = NewEvent.pageX;
        tempY = NewEvent.pageY;
        scrollposY=0;//window.pageYOffset;
        scrollposX=0;
    }
    mousex=tempX;
    mousey=tempY;

    var NewXPosition = tempX-SmallerDivXDifference+scrollposX
    var NewYPosition = tempY-SmallerDivYDifference+scrollposY

    calculateLeft(NewXPosition);
    calculateTop(NewYPosition);
}

// Tracks the mouse movement for the resize
// and sets the new width and height of the divs
function divResize(NewEvent)
{
    if (browserName == "IE")
    {
        tempX = event.clientX;
        tempY = event.clientY;
        scrollposY=document.documentElement.scrollTop
        scrollposX=document.documentElement.scrollLeft
    }
    else
    {
        tempX = NewEvent.pageX;
        tempY = NewEvent.pageY;
        scrollposY=0;
        scrollposX=0;
    }
    mousex=tempX;
    mousey=tempY;

    var newWidth = 0;
    newWidth = mousex - parseInt(MainDivId.style.left) + 10;
    
    setWidth(newWidth);
    
    var NewYPosition = 0;
    var DivTop = 0;
    
    var NewHeight = 0;
    NewHeight = mousey - parseInt(MainDivId.style.top) + 10;
    
    if (NewHeight < 260){
        NewHeight = 260;
    }

   	var ResizeDifference =  NewHeight - parseInt(MainDivId.style.height);
   	
   	// IE6 hack
    if (isIe6) {
        ContentIframeId.style.height = (NewHeight + 4) + "px";
    }else{
        ContentIframeId.style.height = NewHeight + "px";
    }
    
   	var PDFDivHeight = (NewHeight - ContentHeight - 26);
   	PdfHeight = PDFDivHeight;
   	PdfDivId.style.height = PDFDivHeight + "px";

 	var temp = parseInt(MainDivId.style.height) + ResizeDifference;

 	if (temp < 260){
 	    temp = 260;
 	} 	    
   	MainDivId.style.height = temp + "px";
}

// Saves the end location of the divs
function savepos(NewEvent)
{
    var IE = document.all ? true : false;
    if (IE)
    {
        tempX = event.clientX;
        tempY = event.clientY;
        scrollposY=document.documentElement.scrollTop;
        scrollposX=document.documentElement.scrollLeft;
    }
    else
    {
        tempX = NewEvent.pageX;
        tempY = NewEvent.pageY;
        scrollposY=0;
        scrollposX=0;
    }
    mousex=tempX;
    mousey=tempY;
}

// Hides the PDF
function closePdf(DivId,IFrameId)
{
    OverflowDivId.style.overflow = "hidden";
    document.getElementById(DivId).style.visibility = "hidden";
    document.getElementById(IFrameId).style.display = "none";
    document.getElementById(IFrameId).src = currentServerUrl + "Images/Spacer.gif";
    IframeDivId.style.display = "none";
    // to fix error in Safari for Windows, where PDF does not disappear when pop-up is closed.
    IframeDivId.src =  currentServerUrl + "Images/Spacer.gif";
}

function updatePlacementCookie(SetTop,SetLeft,SetWidth,SetHeight,Reset) {
        if (Reset){
            var ebinderTop = SetTop;
            var ebinderLeft = SetLeft;
            var ebinderWidth = SetWidth;
            var ebinderHeight = SetHeight;
        }else{
            var cookieInformation = document.cookie.toString();
            var ebinderTop = readPlacementCookie(0);
            var ebinderLeft = readPlacementCookie(1);
            var ebinderWidth = readPlacementCookie(2);
            var ebinderHeight = readPlacementCookie(3);
        }
        resetCookie("UserDocumentPlacementInformation=Top=&Left=&Width=&Height=&PositionInformationEnd=",-1);
        document.cookie = "UserDocumentPlacementInformation=Top=" + ebinderTop + "&Left="+ebinderLeft+"&Width=" + ebinderWidth + "&Height=" + ebinderHeight + "&PositionInformationEnd=1;EXPIRES=" + getCookieExpirationDate(30) + ";Path=/";
}

function manageResize(resizeStatus){
    var resizeImage = document.getElementById('ResizeImage');
    if (resizeStatus){
        resizeOn = false;
        resizeImage.src = resizeImage.src.replace('PdfResizeDown.gif','PdfResize.gif')
        endDivDrag();
    }else{
        resizeOn = true;
        resizeImage.src = resizeImage.src.replace('PdfResize.gif','PdfResizeDown.gif')
        startResize();
    }
}

function readPlacementCookie(arrayValue){
    var returnValue;
    var cookieInformation = document.cookie.toString();
    if (cookieInformation.indexOf('UserDocumentPlacementInformation') != -1) {
        if (arrayValue == 0) {
            var setTop = cookieInformation.substring(cookieInformation.indexOf('Top=') + 4,cookieInformation.indexOf('&Left='));
            returnValue = setTop;
        }else if(arrayValue == 1){
            var setLeft = cookieInformation.substring(cookieInformation.indexOf('Left=') + 5,cookieInformation.indexOf('&Width='));
            returnValue = setLeft;
        }else if(arrayValue == 2){
            var setWidth = cookieInformation.substring(cookieInformation.indexOf('Width=') + 6,cookieInformation.indexOf('&Height='));
            returnValue = setWidth;
        }else if(arrayValue == 3){
            var setHeight = cookieInformation.substring(cookieInformation.indexOf('Height=') + 7,cookieInformation.indexOf('&PositionInformationEnd='));
            returnValue = setHeight;
        }
    }
    return returnValue;
}



function recordPDFOpenEvent(customerAdministratorId, customerUserId, documentId, searchSourceId) {
    var projectPathVariable = projectPath()
    var shortProjectPath = projectPathVariable.split("/")
    var fullProjectPath = cometBaseUrl + '/InsertDocumentOpenEvent';

    sendCometRequest('processInsertDocumentOpenEvent',shortProjectPath[2],fullProjectPath,'CustomerAdministratorId,' + customerAdministratorId + ';CustomerUserId,' + customerUserId + ';DocumentId,' + documentId + ';SearchSourceId,' + searchSourceId);
}

function sendCometRequest(responseHandler,host,fullURL,parameters){
    if (useComet){
        if (browserName == 'IE') {
            //code for IE
            comet = new ActiveXObject('Microsoft.XMLHTTP'); 
        }else{
            //code for non-IE browsers
            comet = new XMLHttpRequest();
        }
        
        //if this page was accessed with http, switch the comet URL to be HTTP instead of HTTPs
        if (location.protocol == 'http:'){
            fullURL = fullURL.replace(/https/, "http");
        }
                
        //build parameters from list
        //expected format is: parametername,value;parametername,value...
        var parametersToSend = "";
        var innerList;
        if (parameters.length > 0){
            if (parameters.indexOf(';') >= 0){
                var masterList = parameters.split(';');
                var upperBound = masterList.length - 1
                var i;
                for (i=0;i<=upperBound;i++){
                    innerList = masterList[i].split(',');
                    var innerListItem = reverseConvertCharacters(innerList[1]).replace('&','^a^m^p^');
                    parametersToSend = parametersToSend + innerList[0] + '=' + innerListItem;
                    if (i != upperBound){
                        parametersToSend = parametersToSend + '&';
                    }
                }
            }else{
                innerList = parameters.split(',');
                var innerListItem = reverseConvertCharacters(innerList[1]).replace('&','^a^m^p^');
                parametersToSend = parametersToSend + innerList[0] + '=' + innerListItem;
            }
        }    

        comet.onreadystatechange = eval(responseHandler);
        comet.open("POST", fullURL);
        comet.setRequestHeader("Host",host);
        comet.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        comet.setRequestHeader("Content-Length",parametersToSend.length);
        
        comet.send(parametersToSend);   
    }else{
        alert("Your browser does not current support this functionality. Browsers that support this functionality include: Internet Explorer, Firefox, Opera and Safari.");
    }
}



    function reverseConvertCharacters(textToConvert)
    {
        while (textToConvert.indexOf('&quot;') > -1) {textToConvert = textToConvert.replace('&quot;','"');}
        while (textToConvert.indexOf('&amp;') > -1) {textToConvert = textToConvert.replace('&amp;','&');}
        while (textToConvert.indexOf('^a^m^p^amp^s^e^m^i^c^o^l^o^n^') > -1) {textToConvert = textToConvert.replace('^a^m^p^amp^s^e^m^i^c^o^l^o^n^','&');}
        while (textToConvert.indexOf('^s^e^m^i^c^o^l^o^n^') > -1) {textToConvert = textToConvert.replace('^s^e^m^i^c^o^l^o^n^',';');}
        while (textToConvert.indexOf('^q^u^o^t^e^') > -1) {textToConvert = textToConvert.replace('^q^u^o^t^e^','&quot;');}
        while (textToConvert.indexOf('^q^u^o^t^e^') > -1) {textToConvert = textToConvert.replace('^q^u^o^t^e^','"');}
        while (textToConvert.indexOf('^a^m^p^') > -1) {textToConvert = textToConvert.replace('^a^m^p^','&');}
        while (textToConvert.indexOf('^c^o^m^m^a^') > -1) {textToConvert = textToConvert.replace('^c^o^m^m^a^',',');}
        while (textToConvert.indexOf('^a^p^o^s^') > -1) {textToConvert = textToConvert.replace('^a^p^o^s^','\'');}
        //while (textToConvert.indexOf('^b^a^c^k^s^l^a^s^h^') > -1) {textToConvert = textToConvert.replace('^b^a^c^k^s^l^a^s^h^','\\');}
        return textToConvert;
    }
    

function processInsertDocumentOpenEvent() {}