﻿var aspnetform = "ContentPlaceHolder1_";
var geocoder, location1, location2, gDir;

function ScheduleDetails(ddate) {
    window.location = "BookingStatus.aspx?d=" + ddate;
}

function changecrew(crew, bookid) {
    window.location = "BookingStatus.aspx?chcrew=" + crew + "&bookid=" + bookid;
}

function goEditParty(partyid) {
    window.location = "EditParty.aspx?bookid=" + partyid;
}

function goDeleteParty(partyid) {
    var conf = confirm("Are you sure deleting this party?");
    if (conf) {
        window.location = "BookingStatus.aspx?delpartyid=" + partyid;
    }

}

function refreshParent() {
    window.opener.location.href = window.opener.location.href;

    if (window.opener.progressWindow) {
        window.opener.progressWindow.close()
    }
    window.close();
}


function GetMap(url) {
    window.open(url, "map", "width=800,height=650,scrollbars=1,toolbars=0,resizable=1");

}
function openWin(url,  height, width) {
    window.open(url, "sch", "width=" + width + ",height=" + height + ",scrollbars=1,toolbars=0,resizable=1");
}

function printparty(bookid) {
    window.location = "../Print.aspx?ordernum=" + bookid;
}

function confirmparty(bookid) {
    window.location = "BookingStatus.aspx?confirmpartyid=" + bookid;
}

function Send_Email_Message(action, bookid) {
    alert("This feature is not yet available");
}


function showdiv(divid) {
    var d = document.getElementById(divid);
    if (d != null) {
        if (d.style.display == '' || d.style.display == 'block')
            d.style.display = 'none';
        else
            d.style.display = 'block';
    }
}
function showdivtext(divid,txt) {
    var d = document.getElementById(divid);
    if (d != null) {
        if (d.style.display == '' || d.style.display == 'block')
            d.style.display = 'none';
        else
            d.style.display = 'block';

        ShowContent(divid);

        d.innerHTML = 'Parties assigned: <hr/>' + txt + '<a style="color:white" href="javascript:showdiv(\'' + divid + '\')">close</a>';
    }
    
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e) { cX = e.pageX; cY = e.pageY; }
function UpdateCursorPositionDocAll(e) { cX = event.clientX; cY = event.clientY; }
if (document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    
    d.style.left = (cX - 125) + "px";
    d.style.top = (cY + 10) + "px";
}
function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}
function ReverseContentDisplay(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    if (dd.style.display == "none") { dd.style.display = "block"; }
    else { dd.style.display = "none"; }
}


function checkDist() {
    checkdistance('txtStreet', 'txtCity', 'txtState', 'txtPartyZipCode')
}

function initialize() {
    geocoder = new GClientGeocoder();
    gDir = new GDirections();
    GEvent.addListener(gDir, "load", function() {
        var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
        document.getElementById(aspnetform + "txtDrivingDistance").value = drivingDistanceMiles;
                //createCookie("drivingdistance", drivingDistanceMiles, 1);
    });
}

function checkdistance(street, city, state, zip) {

    var pstreet = document.getElementById(aspnetform + street).value;
    var pcity = document.getElementById(aspnetform + city).value;
    var pstate = document.getElementById(aspnetform + state).value;
    var pzip = document.getElementById(aspnetform + zip).value;
    var address1 = pstreet + ", " + pcity + ", " + pstate + " " + pzip;
    var address2 = "18822 Brookhurst Street, Fountain Valley, CA 92708";
    getdistance(address1, address2);
}
function getdistance(address1, address2) {
    geocoder.getLocations(address1, function(response) {
        if (!response || response.Status.code != 200) {
            
        }
        else {
            location1 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
            geocoder.getLocations(address2, function(response) {
                if (!response || response.Status.code != 200) {
                }
                else {
                    location2 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
                    gDir.load('from: ' + location1.address + ' to: ' + location2.address);
                }
            });
        }
    });
}

function GoEmail(sendmethod, bookid) {
    window.location = "SendEmail.aspx?sendmethod=" + sendmethod + "&bookid=" + bookid;
}

function goOrderProcess(obj) {
    window.location = "OrderProcess.aspx";
    obj.disabled = true;
}

function LoadParties(date) {
    WebService.LoadParties(date, OnCompleteDisplayResult);
}
function OnCompleteDisplayResult(arg) {
    document.getElementById("ASyncParties").innerHTML = arg;
}

function PreviewContent() {
    
    var myOldString = document.getElementById(aspnetform + "txtHTML").value;
    var myNewString = myOldString.replace('src="images', 'src="../images');
    myNewString = myNewString.replace("src='images", "src='../images");
    for (i = 0; i < 100; i++) {
        myNewString = myNewString.replace('src="images', 'src="../images');
        myNewString = myNewString.replace("src='images", "src='../images");
    }
    
    document.getElementById("preview").innerHTML = myNewString;
}
function PreviewEmailContent() {
    var myOldString = document.getElementById(aspnetform + "txtBody").value;
    var myNewString = myOldString.replace('src="images', 'src="../images');
    myNewString = myNewString.replace("src='images", "src='../images");
    for (i = 0; i < 100; i++) {
        myNewString = myNewString.replace('src="images', 'src="../images');
        myNewString = myNewString.replace("src='images", "src='../images");
    }

    document.getElementById("preview").innerHTML = myNewString;
}
