﻿var scrollInt;
function ratingOn(id, rating) {
    //alert(id + " , " + rating)
    var starsID = "starsImg" + String(id)
    
    ratingNum = Math.floor(rating)
    switch(ratingNum) {
        case 0:
        document.getElementById(starsID).style.backgroundPosition = '0px -78px'
        break;
        case 1:
        document.getElementById(starsID).style.backgroundPosition = '0px -65px'
        break;
        case 2:
        document.getElementById(starsID).style.backgroundPosition = '0px -52px'
        break;
        case 3:
        document.getElementById(starsID).style.backgroundPosition = '0px -39px'
        break;
        case 4:
        document.getElementById(starsID).style.backgroundPosition = '0px -13px'
        break;
        case 5:
        document.getElementById(starsID).style.backgroundPosition = '0px 0px'
        break;
    }    
}


function ratingSet(id, rating) {
alert(id + "," + rating)
    var starsID = "starsImg" + String(id)
    var mapID = "starsMap" + String(id)
    document.getElementById(mapID).onmouseout = null;
    ratingOn(id, rating)        
    var ratingString;
    ratingString = "http://www.gienga.com/postRating.aspx?itemid=" + String(id) + "&rating=" + String(rating)
    submitRating(ratingString);
    document.getElementById(starsID).useMap = null;   
    document.getElementById("thx" + id).innerHTML  = "Thank You!"
}

function submitRating(str) {
    frames['postRating'].location.href = str
    //alert(str)
}

function openFrame(title, id, fName, loc) {
    //alert(title + " , " + id + " , " + fName + " , " + loc)
    //alert(mode)
    frames[fName + 'Frame'].location.href = loc + ".aspx?title=" + escape(title) + "&id=" + id   
    //alert('showCenterDiv(\'' + fName + 'Frame\', \'' + fName + 'Div\')')
    setTimeout('showCenterDiv(\'' + fName + 'Frame\', \'' + fName + 'Div\')', 200)
    scrollInt = setInterval("moveDiv(\'" + fName + "\')", 1)
    //addCommentFrame.document.getElementById('fItemID').value=itemID
    //addCommentFrame.document.getElementById('fSubjectItemID').value=subjectID
    urchinTracker('/\'' + loc + '\'')
}


function closeFrame(name, thx) {
    hideElement(name + 'Div')
    clearInterval(scrollInt);
    if (thx == true) {
        frames['addCommentFrame'].location.href = "addComment.aspx"
    }
}

function moveDiv(frameName) {
    document.getElementById(frameName + 'Div').style.top = topPos() + "px";
}

function topPos() {
   if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	
	return pos; 
}



function showCenterDiv(divid, showdiv) {
    // First, determine how much the visitor has scrolled
    showElement(showdiv);
    //var scrolledX, scrolledY;
    //scrolledY = topPos();
    //scrolledX = 0;
    //alert(scrolledX + " , " + scrolledY)

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
    } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
    }
    //alert(centerX + " , " + centerY)

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var Xwidth = getElementWidth(divid)
    var Yheight = getElementHeight(divid)
    //alert(Xwidth + " , " + Yheight)
    var leftoffset = (centerX - Xwidth) / 2;   
    var topoffset = (centerY - Yheight) / 2;
    //alert(topoffset + " , " + scrolledY + " , " + centerY + " , " + Yheight);
    //alert(leftoffset + " , " + topoffset)
    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var o = document.getElementById(divid);
    var r=o.style;
    r.top = topoffset + 'px';
    r.left = leftoffset + 'px';
   
} 

function getElementHeight(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
		xPos = elem.offsetHeight;
	return xPos;
}

function getElementWidth(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
		xPos = elem.offsetWidth;
	return xPos;
}