﻿
// ------------------------------------------------------------------------------
/* Start : Miller site v1 js code */
// ---------------------------------------------

/* RWN helper methods */
function alphaSortAsc(a, b){
    /// <summary>
    /// Sort a clientside Development object array ignoring case alphabetically ascending
    /// </summary>
    ///<param name="a">A clientside development object</param>
    ///<param name="b">A clientside development object</param>
    a = a.Title.toLowerCase(); 
    b = b.Title.toLowerCase();
    if (a > b) 
        return 1;
    if (a < b) 
        return -1;
    return 0; 
}
function alphaSortDesc(a, b) {
    /// <summary>
    /// Sort a clientside Development object array ignoring case alphabetically descending
    /// </summary>
    ///<param name="a">A clientside development object</param>
    ///<param name="b">A clientside development object</param>
    a = a.Title.toLowerCase(); 
    b = b.Title.toLowerCase();
    if (a < b) 
        return 1;
    if (a > b) 
        return -1;
    return 0; 
}


// ---------------------------------------------
// Methods bellow are taken from template pages
// ---------------------------------------------
function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
	    for(var i=0; i < this.q.split("&").length; i++) {
		    this.keyValuePairs[i] = this.q.split("&")[i];
	    }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
	    for(var j=0; j < this.keyValuePairs.length; j++) {
		    if(this.keyValuePairs[j].split("=")[0] == s)
			    return this.keyValuePairs[j].split("=")[1];
	    }
	    return false;
    }
    this.getParameters = function() {
	    var a = new Array(this.getLength());
	    for(var j=0; j < this.keyValuePairs.length; j++) {
		    a[j] = this.keyValuePairs[j].split("=")[0];
	    }
	    return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }	
}
function queryString(key){
        var page = new PageQuery(window.location.search); 
        return unescape(page.getValue(key)); 
}
function redir()
{
    document.location.href='/keepinformed/register.htm?cid='+queryString('cid')+'&v=1';
}
function redirLogin()
{
    document.location.href='/keepinformed/login.htm?cid='+queryString('cid')+'&v=1';
}

// ---------------------------------------------
// Methods bellow are from common.js
// ---------------------------------------------
//if (top != self) {
//    try {
//        top.location.replace(self.location.href);
//    }
//    catch (err) {
//        // ignore
//    }
//}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function mwFix(ll,tt,ww,hh) {
	ow=window.outerWidth - window.innerWidth;
	oh=window.outerHeight - window.innerHeight;
	mw.resizeTo(ww-ow,hh);
	mw.moveTo(ll,tt);
}

// open centered popup
// use like: launch_window('winname', 200,300,'http://path.to.thing.com/stuff','no');
function launch_window(name,x,y,url,scrollbars){
	xresnow = x;
	yresnow = y;
	if (navigator.appVersion.indexOf("Mac")!=-1 && document.all) {
		xresnow-=0;
		yresnow-=0;
	}
	xl = (screen.availWidth/2)-(xresnow/2);
	tt = (screen.availHeight/2)-(yresnow/2);
	if (document.all) {
		mw=window.open(url,name,'scrollbars='+scrollbars+',width='+xresnow+',height='+yresnow+',left='+xl+',top='+tt);
	}
	else
	{
		mw=window.open(url,name,'left='+xl+',top='+tt+',width='+x+',height='+y+',toolbar=0,status=0,location=0');
    }
}

//resizable version of above
function launch_window_rs(name,x,y,url,scrollbars){
	xresnow = x;
	yresnow = y;
	if (navigator.appVersion.indexOf("Mac")!=-1 && document.all) {
		xresnow-=0;
		yresnow-=0;
	}
	xl = (screen.availWidth/2)-(xresnow/2);
	tt = (screen.availHeight/2)-(yresnow/2);
	if (document.all) {
		mw=window.open(url,name,'scrollbars='+scrollbars+',width='+xresnow+',height='+yresnow+',left='+xl+',top='+tt+',resizable=1');
	}
	else
	{
		mw=window.open(url,name,'left='+xl+',top='+tt+',width='+x+',height='+y+',toolbar=0,status=0,location=0,resizable=1');
    }
}
/* End : Miller site v1 js code */
// ------------------------------------------------------------------------------

// ----------------------------------------------------------------------
//      Script for Laura Movies on every page
//
// Methods :
//      playMovie('option') to play a movie
//      closeMovie() to stop and close
//
// Options (case sensative) : // TODO : these need to be documented or specific links given to client
//
//      Registration
//      MiWay
//      HBD
//      PartExchange
//      Movemaker
//
// Links :
//
//      For link examples see documentation on Sharepoint site.
//
//
// Talking head image urls :
//
//      Registration    laura_reg.jpg
//      MiWay           laura_miway.jpg
//      HBD             laura_hbd.jpg
//      PartExchange    laura_px.jpg
//      Movemaker       laura_mm.jpg
//
// Notes :
// 
//      Assumes all movies are in the ~/flash/ directory
//      we should add tracking to movie viewing (including which page it's on)

function closeMovie() {
    ///<summary></summary>

    if ($(pnlFlashPopup) != null) {
        var fm = $get(pnlFlashPopup).firstChild;
        var d = $get(pnlFlashPopup);
        d.removeChild(fm);
        $find("mpe2").hide();

        // if we've shown a movie home page we need to re-show the map
        if ($('mapsearch') != null)
            $('mapsearch').show();
    }
}

function playFlashPopupMovie(fileName) {
    ///<summary></summary>
    
    // if we show a movie home page we need to hide the map
    if ($('mapsearch') != null)
        $('mapsearch').hide();
        
    fileName = "/Miller.HomesWeb/flash/" + fileName;

    if ($(pnlFlashPopup) != null) {
        var so = new SWFObject("/Miller.HomesWeb/flash/laura.swf", pnlFlashPopup, "512", "288", "8", "#FFFFFF");
        so.addVariable("baseUrl", baseUrl);
        so.addVariable("movFile", fileName);
        so.write(pnlFlashPopup);
        var mpe = $find("mpe2");
        mpe.show();
    }
}

function playMovie(lauraType) {
    ///<summary></summary>
    
    var movies = new Array(
        'REGISTRATION.flv',
        'MIWAY_THIS_WEBSITE.flv',
        'HBD.flv',
        'PART_EXCHANGE.flv',
        'MOVEMAKER.flv'
    );

    switch (lauraType) {
        case 'Registration':
            playFlashPopupMovie(movies[0]);
            break;
        case 'MiWay':
            playFlashPopupMovie(movies[1]);
            break;
        case 'HBD':
            playFlashPopupMovie(movies[2]);
            break;
        case 'PartExchange':
            playFlashPopupMovie(movies[3]);
            break;
        case 'Movemaker':
            playFlashPopupMovie(movies[4]);
            break;
            
        // no default : better to do nothing than show the wrong movie?
    }
}


