function iLike(id) {
    ix_call('/search?vote='+id, 'vt_'+id);
}

function up_login() {
    var bd = 'bd';
    var width = '300';
    var height = '150';
    var url = '/up/up_login.php';
    createWin2('login_w', bd,height,width,url);
}

function pWin (pid,type) {
    var bd = 'bd';
    var width = '530';
    var height = '530';
    var url = '/search?a=grf&p=' + pid;
    createWin2('review_w',bd,height,width,url);
}

function addF (title) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, window.location,"");
    } else if( window.external ) {
        window.external.AddFavorite( window.location, title); }
    else if(window.opera && window.print) {
        return true; }
}

function destroyWin2 (where,name) {
    document.getElementById(where).style.overflow = '';
    if (document.getElementById(name)) {
        document.getElementById(where).removeChild(document.getElementById(name));
    }
    if (document.getElementById('opacityDiv')) {
        document.getElementById(where).removeChild(document.getElementById('opacityDiv'));
    }
}

function destroyWin (where) {
    document.getElementById(where).style.overflow = '';
    if (document.getElementById('qDiv')) {
	document.getElementById(where).removeChild(document.getElementById('qDiv'));
    }
    if (document.getElementById('opacityDiv')) {
	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 1px #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 fbcReg(uid) {
    var bd = 'bd';
    var width = '300';
    var height = '150';
    var url = '/fb_connect/fb_connect_main.php?a=reg';
    createWin2('fbc_login','bd',height,width,url,'1');
}

function sWin (pid) {
    var bd = 'bd';
    var width = '300';
    var height = '150';
    var url = '?fr=sl&id=' + pid;
    createWin(bd,height,width,url);
}

function lWin (pid) {
    var bd = 'bd';
    var width = '400';
    var height = '150';
    var url = '?fr=ll&id=' + pid;
    createWin(bd,height,width,url);
}

function loginWin() {
    var bd = 'bd';
    var width = '400';
    var height = '150';
    var unique_date = new Date().getTime();
    var url = '/login?s=f&r='+unique_date;
    createWin(bd,height,width,url);
}

function rWin (pid) {
    var bd = 'bd';
    var width = '530';
    var height = '340';
    var url = '?fr=rf&id=' + pid;
    createWin(bd,height,width,url);
}


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

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

function emailMyelf (pid) {
    if (document.getElementById('e')) {
        var email = document.getElementById('e').value;
    } else {
        var email = '';
    }

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

function emailFriend (pid) {
    if (document.getElementById('e')) {
	var email = document.getElementById('e').value;
    } else {
	var email = '';
    }
  document.getElementById('frmBody').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 value=\""+email+"\"></td>    <td>&nbsp;</td>  </tr>  <tr>  <td>Send To:</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('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){
    if (target != 'null') {
	document.getElementById(target).innerHTML = '<img src="http://images.sortprice.com/is/animated_loading.gif"> 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 != 'null') {
                if (document.getElementById(target)) {
		    document.getElementById(target).innerHTML = (xmlhttp.responseText);
                }
            }
            xmlhttp = false;
        }

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

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

function smq (w,fn,fe,fq,pid) {
  document.getElementById(w).innerHTML = '<img src=\"http://images.sortprice.com/is/animated_loading.gif\"> Processing...';
  ix_call('?fr=aqs&id='+pid+'&fn='+fn+'&fe='+fe+'&fq='+fq, w);
}

function rate (score,save) {
  off = new Image();
  on = new Image();
  off.src = 'http://www.sortprice.com/images/star_rate_0.gif';
  if (save == '1') {
    on.src = 'http://www.sortprice.com/images/star_rate_1.gif';
  } else {
    on.src = 'http://www.sortprice.com/images/star_rate_2.gif';
  }
  if (score == 1) {
    document.getElementById('a1').src = on.src;
    document.getElementById('a2').src = off.src;
    document.getElementById('a3').src = off.src;
    document.getElementById('a4').src = off.src;
    document.getElementById('a5').src = off.src;
  }
  if (score == 2) {
    document.getElementById('a1').src = on.src;
    document.getElementById('a2').src = on.src;
    document.getElementById('a3').src = off.src;
    document.getElementById('a4').src = off.src;
    document.getElementById('a5').src = off.src;
  }
  if (score == 3) {
    document.getElementById('a1').src = on.src;
    document.getElementById('a2').src = on.src;
    document.getElementById('a3').src = on.src;
    document.getElementById('a4').src = off.src;
    document.getElementById('a5').src = off.src;
  }
  if (score == 4) {
    document.getElementById('a1').src = on.src;
    document.getElementById('a2').src = on.src;
    document.getElementById('a3').src = on.src;
    document.getElementById('a4').src = on.src;
    document.getElementById('a5').src = off.src;
  }
  if (score == 5) {
    document.getElementById('a1').src = on.src;
    document.getElementById('a2').src = on.src;
    document.getElementById('a3').src = on.src;
    document.getElementById('a4').src = on.src;
    document.getElementById('a5').src = on.src;
  }
  if (save == '1') {
    document.getElementById('p_rating').innerHTML = '<img src=\"http://www.sortprice.com/images/rate_'+score+'.gif\">';
    document.getElementById('p_rate').value = score;
  }
}

function createWin2 (name,where,height,width,url,showLoader) {
    //alert(url);
    //document.getElementById(where).style.overflow = 'hidden';
    if (document.getElementById(name)) {
	return '';
    }
    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',name);
    newQdiv.style.position = 'absolute';
    newQdiv.style.background = 'transparent';
    newQdiv.style.zIndex = '101';
    newQdiv.style.top = (((windowHeight / 2) + scrOfY) - (height / 2));
    newQdiv.style.left =  (((windowWidth / 2) + scrOfX) - (width / 2));
    newQdiv.style.border = 'solid 0px #444444';
    document.getElementById(where).appendChild(newQdiv)
    if ((i = navigator.userAgent.indexOf("MSIE")) >= 0) {
      //newQdiv.style.filter = "alpha(opacity=50)";
    } else {
      //newQdiv.style.opacity = "0.5";
    }
    var unique_date = new Date().getTime();
    if (showLoader) {
	content = "<table width=\"230\" cellspacing=\"12\" cellpadding=\"12\"><tr> <td align=\"center\" id=\"progressDiv\">Loading, please wait...<br><br><img src=\"http://images.sortprice.com/is/scd_msn_loader.gif\" onLoad=\"get_url_to_field(url,'progressDiv', '0')\"></td> </tr> </table>";
    } else {
	content = "&nbsp;";
    }
    newQdiv.innerHTML = get_round_corners(unique_date,'10',content);
    ix_call(url,unique_date);

}

function get_round_corners(cntId,width,content) {
    return "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse;\"><tr><td valign=\"top\"><img style=\"filter:alpha(opacity=50);-moz-opacity:.6;\" src=\"http://images.sortprice.com/is/lb_tl.gif\" width=\""+width+"\" height=\""+width+"\"></td><td style=\"background-image: url('http://images.sortprice.com/is/lb_bg.gif');filter:alpha(opacity=50);-moz-opacity:.6;\"></td><td valign=\"top\"><img style=\"filter:alpha(opacity=50);-moz-opacity:.6;\" src=\"http://images.sortprice.com/is/lb_tr.gif\" width=\""+width+"\" height=\""+width+"\"></td></tr><tr><td style=\"background-image: url('http://images.sortprice.com/is/lb_bg.gif');filter:alpha(opacity=50);-moz-opacity:.6;\"></td><td style=\"background-color: #FFFFFF\" id=\""+cntId+"\">"+content+"</td><td style=\"background-image: url('http://images.sortprice.com/is/lb_bg.gif');filter:alpha(opacity=50);-moz-opacity:.6;\"></td></tr><tr><td valign=\"bottom\"><img style=\"filter:alpha(opacity=50);-moz-opacity:.6;\" src=\"http://images.sortprice.com/is/lb_bl.gif\" width=\""+width+"\" height=\""+width+"\"></td><td style=\"background-image: url('http://images.sortprice.com/is/lb_bg.gif');filter:alpha(opacity=50);-moz-opacity:.6;\"></td><td valign=\"bottom\"><img style=\"filter:alpha(opacity=50);-moz-opacity:.6;\" src=\"http://images.sortprice.com/is/lb_br.gif\" width=\""+width+"\" height=\""+width+"\"></td></tr></table>";
}

function hideThumb (productID) {
    document.getElementById(productID).style.display = 'none';
}

function hideEmailProduct (productID) {
    document.getElementById(productID).style.display = 'none';
}


function showEmailProduct (productID) {
    document.getElementById(productID).style.display = '';
    document.getElementById(productID).innerHTML = '<table bgcolor="#EDF0FF" border=0 style="border-style: solid; border-color: #444444;border-width: 1px;position:absolute;top: 160;left: -100;"><tr><td>To Email:</td><td><input type=text name=toEmail style="width: 120px;"></td></tr><tr><td>Comment:</td><td><textarea style="width: 120px;" name=emailComment></textarea></td></tr><td></td><td align=right><a href="javascript:;" onClick="javascript:(this.div.style.display=\'none\');">Cancel</a>  &nbsp;&nbsp; <a href="javascript:;">Send</a></td></tr></table>';
    document.getElementById(productID).style.top = event.clientY + document.body.scrollTop - 175;
    document.getElementById(productID).style.left = (event.clientX + document.body.scrollLeft) - 10;
    document.getElementById(productID).style.position = 'absolute';
    document.getElementById(productID).style.zIndex = 100;
}

function pause(ms) {
    date = new Date();
    var curDate = null;
    do { var curDate = new Date(); }
    while(curDate-date < ms);
}


function showThumb (event,thumbImage,productID) {

    image1 = new Image();
    image1.src = 'http://images5.sortprice.com/' + thumbImage;

    var toolTipImage = '';
    document.getElementById(productID).style.display = '';
    document.getElementById(productID).style.height = '350';
    document.getElementById(productID).style.width = '400';
    if (((event.clientY + document.body.scrollTop) - document.body.scrollTop) > 250) {
        toolTipImage = 'http://images.sortprice.com/is/tooltip.png';
    } else {
        toolTipImage = 'http://images.sortprice.com/is/tooltip2.png';
    }
    document.getElementById(productID).style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+toolTipImage+', sizingMethod="scale");';

    document.getElementById(productID).style.position = 'absolute';
    var tempX = event.clientX + document.body.scrollLeft - 480;
    if (((event.clientY + document.body.scrollTop) - document.body.scrollTop) > 250) {
        var tempY = event.clientY + document.body.scrollTop - 340;
    } else {
        var tempY = event.clientY + document.body.scrollTop - 130;
    }
    document.getElementById(productID).style.top = tempY;
    document.getElementById(productID).style.left = (event.clientX + document.body.scrollLeft) + 2;

    if (((event.clientY + document.body.scrollTop) - document.body.scrollTop) > 250) {
        if ((i = navigator.userAgent.indexOf("MSIE")) >= 0) {
            document.getElementById(productID).innerHTML = '<img alt="Thumb" src="http://images5.sortprice.com/' + thumbImage + '" style="position:absolute;top: 127;left: 15;">';
        } else {
            document.getElementById(productID).innerHTML = '<img alt="Thumb" src="'+toolTipImage+'"><img alt="Thumb" src="http://images5.sortprice.com/' + thumbImage + '" style="position:absolute;top: 130;left: 18;">';
        }
    } else {
        if ((i = navigator.userAgent.indexOf("MSIE")) >= 0) {
            document.getElementById(productID).innerHTML = '<img src="http://images5.sortprice.com/' + thumbImage + '" style="position:absolute;top: 160;left: 15;">';
        } else {
            document.getElementById(productID).innerHTML = '<img src="'+toolTipImage+'"><img src="http://images5.sortprice.com/' + thumbImage + '" style="position:absolute;top: 163;left: 18;">';
        }
    }
    document.getElementById(productID).style.zIndex = 100;
}

