
function destroyWin (where) {
    document.getElementById(where).style.overflow = '';
    document.getElementById(where).removeChild(document.getElementById('qDiv'));
    document.getElementById(where).removeChild(document.getElementById('opacityDiv'));
}

function f_scrollLeft() {
    return f_filterResults (
			    window.pageXOffset ? window.pageXOffset : 0,
			    document.documentElement ? document.documentElement.scrollLeft : 0,
			    document.body ? document.body.scrollLeft : 0
			    );
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
	scrOfY = window.pageYOffset;
	scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	scrOfY = document.body.scrollTop;
	scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function createWin (where,height,width,url) {
    document.getElementById(where).style.overflow = 'hidden';

    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {	
	xScroll = document.body.scrollWidth;
	yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;
    } else {
	xScroll = document.body.offsetWidth;
	yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {
	windowWidth = self.innerWidth;
	windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
    }	
    
    if(yScroll < windowHeight){
	pageHeight = windowHeight;
    } else { 
	pageHeight = yScroll;
    }
   
    if(xScroll < windowWidth){	
	pageWidth = windowWidth;
    } else {
	pageWidth = xScroll;
    }

    var newOLayer = document.createElement("div");
    newOLayer.setAttribute('id','opacityDiv');
    newOLayer.style.position = 'absolute';
    newOLayer.style.top = '-10px';
    newOLayer.style.left = '-10px';
    newOLayer.style.width = (pageWidth + 10);
    newOLayer.style.height = (pageHeight + 10);
    newOLayer.style.background = 'black';
    newOLayer.style.border = 'solid 1px #000000';
    newOLayer.style.zIndex = '100';
    newOLayer.style.filter = 'filter: alpha(opacity=50)';
    newOLayer.style.opacity = '0.5';
    document.getElementById(where).appendChild(newOLayer);
    newOLayer.onclick = function () {destroyWin(where); return false;}
    var newQdiv = document.createElement("div");
    newQdiv.setAttribute('id','qDiv');
    newQdiv.style.position = 'absolute';
    newQdiv.style.background = 'white';
    newQdiv.style.zIndex = '101';
    newQdiv.style.top = (((windowHeight / 2) + scrOfY) - (height / 2));
    newQdiv.style.left =  (((windowWidth / 2) + scrOfX) - (width / 2));   
    newQdiv.style.border = 'solid 4px #444444';
    newQdiv.innerHTML = '<table cellspacing=3 cellpadding=3><tr><td><img src=\"http://images.sortprice.com/is/animated_loading.gif\"> Loading...</td></tr></table>';
    document.getElementById(where).appendChild(newQdiv);
    var xmlhttp;
    xmlhttp = false;
    if (!xmlhttp) {
	if (navigator.appName == "Microsoft Internet Explorer") {
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	    xmlhttp = new XMLHttpRequest();
	}
    }
    xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState==4) {
	    newQdiv.innerHTML = (xmlhttp.responseText);
	    xmlhttp = false;
	}
	
    };
    xmlhttp.open("GET",url);
    xmlhttp.send(null);
    
}

function prWin (pid,type) {
    var bd = 'bd';
    var width = '530';
    var height = '530';
    var url = '/reviews?fr=rfp&type='+type+'&id=' + pid;
    createWin(bd,height,width,url);
}


function rrWin (pid) {
    var bd = 'bd';
    var width = '530';
    var height = '530';
    var url = '/reviews?fr=rf&id=' + pid;
    createWin2('review_w',bd,height,width,url);
}

function qrWin (pid) {
    var bd = 'bd';
    var width = '430';
    var height = '220';
    var url = '/reviews?fr=aq&id=' + pid;
    createWin(bd,height,width,url);
}


function crWin (pid) {
    var bd = 'bd';
    var width = '430';
    var height = '220';
    var url = '/reviews?fr=ef&id=' + pid;
    createWin2('share_w',bd,height,width,url);
}

function emailMyelf_r (pid) {
document.getElementById('emf').innerHTML = "<table style=\"width: 100%\" border=0>  <tr><td width=\"80px\">Your Email:</td>    <td><input class=\"efi\" type=text id=\"e\" value=\"\"></td>    <td><button onClick=\"sef_r('emf', '', document.getElementById('e').value, '', '', '"+pid+"')\">Send</button></td>  </tr> </table>";
    document.getElementById('e').focus();
}

function emailFriend_r (pid) {
  document.getElementById('emf').innerHTML = "<table border=0>  <tr> <td>Your Name:</td>    <td><input type=text class=\"efi\" id=\"n\" name=\"n\"></td>    <td>&nbsp;</td>  </tr>  <tr>  <td>Your Email:</td>    <td><input class=\"efi\" type=text id=e></td>    <td>&nbsp;</td>  </tr>  <tr>  <td>Friends Email:</td>    <td><input class=\"efi\" type=text id=fe></td>    <td> </td> </tr> <tr>  <td valign=\"top\"> Message: </td> <td> <textarea class=\"efi\" id=tm>I found this on Sortprice.com</textarea> </td> <td valign=\"bottom\"> <button onClick=\"sef_r('emf',document.getElementById('n').value,document.getElementById('e').value,document.getElementById('fe').value, document.getElementById('tm').value,'"+pid+"')\">Send</button></td>  </tr>  </table>";
    if (document.getElementById('n')) { document.getElementById('n').focus(); }
}

function ix_call(action,target){
    document.getElementById(target).innerHTML = 'Loading...';
    var xmlhttp;
    xmlhttp = false;
    if (!xmlhttp) {
        if (navigator.appName == "Microsoft Internet Explorer") {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            xmlhttp = new XMLHttpRequest();
        }
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
            if (target != '') {
                if (document.getElementById(target)) {
                    document.getElementById(target).innerHTML = (xmlhttp.responseText);
                }
            }
            xmlhttp = false;
        }

    };
    xmlhttp.open("GET",action);
    xmlhttp.send(null);
}

function sef_r (w,n,e,fe,tm,pid) {
    document.getElementById(w).innerHTML = '<img src=\"http://images.sortprice.com/is/animated_loading.gif\"> Processing...';
    ix_call('/reviews?fr=se&f=e&id='+pid+'&n='+n+'&e='+e+'&fe='+fe+'&tm='+tm, w);
}
