﻿// JScript File


var xmlHttp;
var rootpath = '';

//rootpath = "http://localhost/FileTrail/";   // be sure to change this to your URL
//rootpath = "";


function viewImage(ID, ImageId)
{
    var popWin;
    popWin = window.open('Image.aspx?Id=' + ID + '&ImageId=' + ImageId, 'Images', 'location=no,scrollbars=yes,resizable=yes,status=yes');
    popWin.focus();    
}

function EmailFriend(ID)
{
    var popWin;
    popWin = window.open('EmailFriend.aspx?Id=' + ID, 'EmailFriend', 'menubar=no,width=600,height=560,location=no,scrollbars=yes,resizable=yes,status=yes');
    popWin.focus();
}

function ContactSeller(ID)
{
    var popWin;
    popWin = window.open('ContactSeller.aspx?Id=' + ID, 'ContactSeller', 'menubar=no,width=600,height=560,location=no,scrollbars=yes,resizable=yes,status=yes');
    popWin.focus();
}

// Conceal the divObject (fade out).
function Conceal (divObject)
{
    var opacity = parseInt(divObject.style.opacity * 100);
    
    if (opacity <= 0)
    {
        return;
    }
    else
    {
        if (opacity <= 60)
            opacity -= 10;    //Fast
        else
            opacity -= 3;   //Slow

        if (opacity < 0)
            opacity = 0;

    }
    divObject.style.filter ='alpha(opacity=' + opacity + ')';
    divObject.style.opacity = (opacity / 100);
    
    var cmd = "Conceal(document.getElementById('" + divObject.id + "'))";
    setTimeout(cmd, 50);
}


function ShowWatchListAnimation(msg)
{

    var width;
    var height;
    var divObj;
    
    //LogMsg('Resizing Window.');
    
    if (window.innerWidth)
    {   
        height = window.innerHeight;
        width = window.innerWidth;
    }
    else if (document.body.clientWidth)
    {
        height = document.body.clientHeight;
        width = document.body.clientWidth;
    }
    else
    {
        height = document.documentElement.clientHeight;
        width = document.documentElement.clientWidth;
    }
    
    
    
    divObj = document.getElementById("WatchListAnimationDiv");
    //alert(width + ' x ' + height + '\n' + parseInt(divObj.style.width) + ' x ' + parseInt(divObj.style.height));        


    divObj.style.left = parseInt(width/2)-parseInt(parseInt(divObj.style.width)/2) + 'px';
    //divObj.style.top = parseInt(height/4)-parseInt(parseInt(divObj.style.height)/2) + 'px';
    //divObj.style.top = '130px';


    divObj.innerHTML =  '<br />' + unescape(msg); //FloorNumber.innerText
    divObj.style.display = 'block';
    //divObj.style.display = 'inline';    
    divObj.style.filter='alpha(opacity=100)';
    divObj.style.opacity= 1; // .25';
    divObj.style.zIndex ="600"

    Conceal(divObj);
}


function AddToWatchList(propertyId)
{
    //Swap button image.
    btn = document.getElementById('watchListImage');

    if (btn.src.indexOf('Remove.gif') >= 0 )
    {
        btn.src = 'Img/Cart_Add.gif';
    } else {
        btn.src = 'Img/Cart_Remove.gif';
    }       

    //Send AJAX call to add/remove property from watchlist.
    xmlHttp=GetXmlHttpObject(ProcessResponse)
    if (xmlHttp == null)
    {
        //Browser doesn't support HTTP requests
        return;
    }    
    var url=rootpath + "AJAX_UpdateWatchList.aspx?ID=" + propertyId;
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
    
}

//Processes the response from the XmlHttpObject request.
function ProcessResponse()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		//alert(xmlHttp.responseText);
		var result = xmlHttp.responseText;
         
        var arr = result.split('|');    //Format: PropertyID|result (1=Add, 2=Remove)		
		
        //Update button image based on result.
        var btn = document.getElementById('watchListImage');
  
        if (arr[1] == '2')
        {
            btn.src = 'Img/Cart_Add.gif';
            ShowWatchListAnimation("<center>- Removed -<br />from Watch List<br /><div style='background-color:white;width:30px;'><img src='Img/Cart_Add.gif'></div></center>");
        } else {
            btn.src = 'Img/Cart_Remove.gif';
            ShowWatchListAnimation("<center>\+ Added \+<br />to Watch List<br /><center><div style='background-color:white;width:30px;'><img src='Img/Cart_Remove.gif'></div></center>");
        }   		       
    }
}


function GetXmlHttpObject(handler)
{
    var objXmlHttp=null;

    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP";
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName);
            objXmlHttp.onreadystatechange=handler;
            return objXmlHttp;
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled");
            return;
        }
    }
    
//    if (navigator.userAgent.indexOf("Opera")>=0)
//    {
//        //alert("Opera not supported...");
//        return;
//    }    
    
    //NOTE: Versions earlier than Opera 8.0 aren't supported and may generate errors.
    if ((navigator.userAgent.indexOf("Mozilla")>=0) || (navigator.userAgent.indexOf("Opera")>=0) )
    {
        objXmlHttp=new XMLHttpRequest();
        objXmlHttp.onload=handler;
        objXmlHttp.onerror=handler;
        return objXmlHttp;
    }
}

