// Begin Rolls
function ImageHolderClass(){
	this.over=new Array();
	this.down=new Array();
	this.src=new Array();
	this.store=store;
	this.mouseisdown = 0;
    this.preloader = preloader;
    this.mouseup = mouseup;
    this.mouseup2 = mouseup2;
    this.mousedown = mousedown;
    this.mouseover = mouseover;
    this.mouseout = mouseout;
    this.storeimages = storeimages;
    this.preloadimgsrc = preloadimgsrc;
    
	function store(src, down, over){
		var AL=this.src.length;
		this.src[AL]=new Image(); if(src != '') this.src[AL].src=src;
		this.over[AL]=new Image(); if(over != '') this.over[AL].src=over;
		this.down[AL]=new Image(); if(down != '') this.down[AL].src=down;
	}
	
	function preloader(t){
	    for(i=0;i<t.length;i++){
		    if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
    			
			    storeimages(t[i]);
			    var checker='';
			    checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
			    checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
    			
			    switch(checker){
			    case 'A' : mouseover(t[i]);mouseout(t[i]); break;
			    case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
			    case 'AB' : mouseover(t[i]);mouseout(t[i]); mousedown(t[i]); mouseup(t[i]); break;
			    default : return;			
			    }
    			
			    if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
		    }
	    }
    }
    
    function mouseup(t){
	    var newmouseup;
	    if(t.onmouseup){
		    t.oldmouseup=t.onmouseup;
		    newmouseup=function(){FCHelper.ImageHolderClass.mouseisdown=0;this.src=this.getAttribute("srcover");this.oldmouseup();}

	    }
	    else{newmouseup=function(){FCHelper.ImageHolderClass.mouseisdown=0;this.src=this.getAttribute("srcover");}}
	    t.onmouseup=newmouseup;
    }

    function mouseup2(t){
	    var newmouseup;
	    if(t.onmouseup){
		    t.oldmouseup=t.onmouseup;
		    newmouseup=function(){FCHelper.ImageHolderClass.mouseisdown=0;this.src=this.getAttribute("oldsrc");this.oldmouseup();}
		    }
	    else{newmouseup=function(){FCHelper.ImageHolderClass.mouseisdown=0;this.src=this.getAttribute("oldsrc");}}
	    t.onmouseup = newmouseup;
    }

    function mousedown(t){
	    var newmousedown;
	    if(t.onmousedown){
		    t.oldmousedown=t.onmousedown;
		    newmousedown=function(){if(FCHelper.ImageHolderClass.mouseisdown==0){this.src=this.getAttribute("srcdown");this.oldmousedown();}}
	    }
	    else{newmousedown=function(){if(FCHelper.ImageHolderClass.mouseisdown==0){this.src=this.getAttribute("srcdown");}}}
	    t.onmousedown=newmousedown;
    }

    function mouseover(t){
	    var newmouseover;
	    if(t.onmouseover){
		    t.oldmouseover=t.onmouseover;
		    newmouseover=function(){this.src=this.getAttribute("srcover");this.oldmouseover();}
	    }
	    else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
	    t.onmouseover=newmouseover;
    }

    function mouseout(t){
	    var newmouseout;
	    if(t.onmouseout){
		    t.oldmouseout=t.onmouseout;
		    newmouseout=function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
	    }
	    else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
	    t.onmouseout=newmouseout;
    }

    function storeimages(t){
	    var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
	    var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
	    var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
	    FCHelper.ImageHolderClass.store(s,d,o);
    }

    function preloadimgsrc(){
	    if(!document.getElementById) return;
	    var it=document.getElementsByTagName('IMG');
	    var it2=document.getElementsByTagName('INPUT');
	    preloader(it);
	    preloader(it2);
    }
}


function FCjsHelper() {
    this.ImageHolderClass = new ImageHolderClass();
}

FCjsHelper.prototype.BodyOnLoad = function() {
  var jsEnabledCookie = this.GetCookie("jsEnabled");
  if(jsEnabledCookie == null) {
    this.SetCookie("jsEnabled", "true", 3, "/", "", "");
  }
}

FCjsHelper.prototype.SetCookie = function( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

FCjsHelper.prototype.GetCookie = function( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; 

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

FCjsHelper.prototype.AjaxCall = function(dId, targetUrl) {
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
        xmlhttp = false;
    }
    }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    xmlhttp.open("GET", targetUrl,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            document.getElementById(dId).innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
    return false;
}

FCjsHelper.prototype.PMOver = function(id) {document.getElementById(id).style.backgroundColor='#F1F1F1';}
FCjsHelper.prototype.PMOut = function(id){document.getElementById(id).style.backgroundColor='white';}

FCjsHelper.prototype.openToUrl = function(evt, pInfoId, url) {
    var e=(evt)?evt:window.event;
    var clickTag;
    if (e.target) {
        clickTag=e.target;
    }else if (e.srcElement) {
        clickTag=e.srcElement;
    }
    if (clickTag.nodeType==3){ // defeat Safari bug
        clickTag = targ.parentNode;
    }
    if(clickTag.tagName.toLowerCase() == "a") { return true; } // Let anchor clicks do their thing.
    
   if (window.event) {e.cancelBubble=true;} else {e.stopPropagation();}
    
    if(document.getElementById(pInfoId).click) {
        document.getElementById(pInfoId).click(); // click anchor to send referrer
    }else {
        var w = window.open(url, '_blank');
        w.focus();
    }
    return false;
}
FCjsHelper.prototype.redirectToUrl = function (evt, url) { 
    var e=(evt)?evt:window.event;
    if (window.event) {e.cancelBubble=true;} else {e.stopPropagation();}

    window.location.href = url; 
    return false;
}

FCjsHelper.prototype.specialOfferWin = function(evt, offerId) {
  var e=(evt)?evt:window.event;
  if (window.event) {e.cancelBubble=true;} else {e.stopPropagation();}
  var soUrl = "/OfferInfo/OfferInformation.aspx?offerId="+offerId;
  this.helpInfo(soUrl, 400, 275);
  return false;
}

FCjsHelper.prototype.sharepage = function() {
    var spUrl = "/share/SharePage.aspx?sp=" + encodeURIComponent(window.location.href);
	var spW = window.open(spUrl, "SharePage", "width=462,height=600,menubar=no,directories=0,status=yes,location=no,toolbar=no,scrollbars=no,resizable=yes,copyhistory=yes");
	spW.focus();
	return false;
}

FCjsHelper.prototype.helpInfo = function(url, width, height) {
	var helpW = window.open(url, "HelpInfo"+width+height, "width=" + width + ",height=" + height + ",menubar=no,directories=0,status=yes,location=no,toolbar=no,scrollbars=no,resizable=yes,copyhistory=yes");
	helpW.focus();
	return false;
}

FCjsHelper.prototype.addListeners = function() {
    if(window.addEventListener){window.addEventListener("load", FCHelper.ImageHolderClass.preloadimgsrc, false);} 
    else{
	    if(window.attachEvent){window.attachEvent("onload", FCHelper.ImageHolderClass.preloadimgsrc);}
	    else{if(document.getElementById){window.onload=FCHelper.ImageHolderClass.preloadimgsrc;}}
    }
}

FCjsHelper.prototype.ratingClick = function(idx) {
    document.getElementById("reviewRating").value = idx;
    FCHelper.ratingFill(idx);
}

FCjsHelper.prototype.filterExp = function(divId, imgId) {
    var div = document.getElementById(divId);
    if(div.style.display == 'block') {
        div.style.display = 'none';
        document.getElementById(imgId).src  = '/img/arrow_closed.gif';
    }else {
        div.style.display = 'block';
        document.getElementById(imgId).src  = '/img/arrow_open.gif';
    }
}

FCjsHelper.prototype.ratingFill = function(idx) {
    var strs = document.getElementsByName("rst");
    var selIdx = parseInt(document.getElementById("reviewRating").value);
    if (idx < 0 && selIdx >= 0) idx = selIdx;
    for(i=1; i <= strs.length; i++) {
        if (idx > 0 && i <= idx) {
            strs[i-1].src = "/img/StarOn.gif";
        }else {
            strs[i-1].src = "/img/StarOff.gif";
        }
    }
   var lbl = document.getElementById("ratingText");
   switch (idx) {
        case 1: lbl.innerHTML = "The Worst"; break;
        case 2: lbl.innerHTML = "Not Great"; break;
        case 3: lbl.innerHTML = "It's Ok"; break;
        case 4: lbl.innerHTML = "Good"; break;            
        case 5: lbl.innerHTML = "Excellent"; break;
        default: lbl.innerHTML = "Not Rated";
    }
}

FCjsHelper.prototype.priceRangeClick = function() {
     var qp = this.querySplit();
     var query = null;
     for (var strKey in qp) {
        if(strKey =="3032") continue;
        if(query == null){ query = "?"; } else { query += "&"; }
        query += strKey + "=" + qp[strKey];
     }
     window.location.href =  "http://" + window.location.hostname + window.location.pathname + query +
         "&3032=" + 
    document.getElementById("slide_from").value + "-" +
    document.getElementById("slide_to").value + "-" +
    document.getElementById("slide_from_raw").value + "-" +
    document.getElementById("slide_to_raw").value + "-" +
    document.getElementById("max_price").value;
}

FCjsHelper.prototype.querySplit = function() {
var urlObj = new Object();

window.location.search.replace(
new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
function( $0, $1, $2, $3 ){
urlObj[ $1 ] = $3;
}
);
return urlObj;
}

var FCHelper = new FCjsHelper();
FCHelper.addListeners();



