//////////////////////////////////////////
function sendCommitOptions(rbLendID, chkWantBack) 
{
	var rbLnd = document.getElementById(rbLendID); 
	var chkWB = document.getElementById(chkWantBack); 
	var elms = document.Form1.elements;

	if (rbLnd.checked) //Lending to a Friend
	{
		chkWB.disabled = true;
		chkWB.checked = true;
		chkWB.nextSibling.innerHTML = '&nbsp;I would like my friend to return this DVD to me.';
		chkWB.nextSibling.disabled = true;
		elms[3].disabled = true; //Should be send to first available
		elms[4].checked = true; //should be next friend in line
		for (var i=0;i<elms.length;i++)
		{
			if (elms[i].type=='radio')
			{
				elms[i].disabled = false;
				if (elms[i].nextSibling != null)
				{
				if (elms[i].nextSibling.type=='label')
				{
				elms[i].nextSibling = false;
				}
				
				}
			}
		}
	}
	else //Selling
	{
		chkWB.disabled = false;
		chkWB.checked = false;
		chkWB.nextSibling.innerHTML = '&nbsp;I would like the next available copy of this DVD returned to me.';
		chkWB.nextSibling.disabled = false;
		elms[3].disabled = false; //Should be send to first available
		elms[3].checked = true; 
		for (var i=3;i<elms.length;i++)
		{
			if (elms[i].type=='radio')
			{		
				//elms[i].disabled = false; //back to orginal state.  how do i detect it?
			}
		}
	}

}
/*
	for (var i=2;i<elms.length;i++)
	{
		if (elms[i].type=='radio') //&&  elms[i].id.indexof(rblClientId.id) 
		{
			if (elms[i].value=='-1') //send to anyone
			{
				cNo.disabled = true;
				cNo.nextSibling.disabled = true;
				cNo.parentElement.disabled = true;
				cNo.checked = false;
				cR.checked = false;
				cNo.nextSibling.innerHTML = 'I will send this DVD to my friend for 0 Peerbux.';
				cR.nextSibling.innerHTML = 'I would like a copy of this DVD back.';
			}
			else//send to peer
			{
			
				cNo.disabled = false;
				cNo.nextSibling.disabled = false;
				cNo.parentElement.disabled = false;
				cNo.checked = false;
				cR.checked = true;
				cNo.nextSibling.innerHTML = 'I will send this DVD to <b>' + elms[i].value.split(',')[1] + '</b> for 0 Peerbux.';
				cR.nextSibling.innerHTML = 'I would like <b>' + elms[i].value.split(',')[1] + '</b> to return this DVD to me.';
			}
		}
	}
}

//////////////////////////////////////////
*/

//////////////////////////////////////////
//rblClientId is also each listItems name value
function openPFLabelcheck(chkIAgreeId,chkNoPbId,theURL)
{
	var isForZeroPb = Number(document.getElementById(chkNoPbId).checked)
	if (document.getElementById(chkIAgreeId).checked) //validate chk
	{
		var elms = document.Form1.elements;
		for (var i=0;i<elms.length;i++)
		{
			if (elms[i].type=='radio' && elms[i].checked) //&&  elms[i].id.indexof(rblClientId.id) 
			{

				var newURL = theURL + '&peerId=' + elms[i].value.split(',')[0]//get id
				newURL += '&isForZeroPb=' + isForZeroPb
				window.open(newURL,'PeerflixLabel','width=690,height=500,resizable=no,scrollbars=yes,menubar=yes,toolbar=no,location=no,directories=no,status=no');
				return true;
			}
		}
	}
	return true;
}


function openPFLabel(theURL)
{
	window.open(theURL,'PeerflixLabel','width=690,height=500,resizable=no,scrollbars=yes,menubar=yes,toolbar=no,location=no,directories=no,status=no');
	return true;
}
//////////////////////////////////////////

//////////////////////////////////////////

function ToggleTheColorOfTheTR(row, box) 
{
	var r = document.getElementById(row); 
	var b = document.getElementById(box); 
	if (b.checked == false) 
	{
		rowSelect(r, b);
	} 
	else 
	{
		rowUnselect(r, b);
	}
}
    
   
function rowSelect(row, box) 
{
	box.checked = true;
	if(row) 
	{ 
		rowRollover(row, box, true); 
	}
}

function rowUnselect(row, box) 
{
	box.checked = false;
	if(row) 
	{ 
		rowRollover(row, box, true);
	}
}

function rowRollover(row, box, isInRow) 
{
	var r = document.getElementById(row); 
	var b = document.getElementById(box); 
	if (r)
	{
		//alert('r found');
		if (b && b.checked) 
		{
			r.className = "PeerFlixTRSelected";
		} 
		else 
		{
			//row.className = (row == rowWithMouse) ? 'PeerFlixTROver' : 'PeerFlixTROut';
			r.className = (isInRow) ? 'PeerFlixTROver' : 'PeerFlixTROut';
		}
	}
	else
	{
		//alert('NO r found');
	}
	
}


function verify_this_image(imagehandle) {
        if (imagehandle.src.indexOf('MZZZZZZZ') >= 0) {
            w = imagehandle.width;
            h = imagehandle.height;
            if ((w < 10) || (h < 10)) {
                imagehandle.src = 'no_art_me.gif';
            } 
            if (w > 105)  {
            	imagehandle.width = 105;}
        }
        if (imagehandle.src.indexOf('THUMBZZZ') >= 0) {
            w = imagehandle.width;
            h = imagehandle.height;
            if ((w < 10) || (h < 10)) {
                imagehandle.src = 'no_art_sm.gif';
            } 
        }
        if (imagehandle.src.indexOf('LZZZZZZZ') >= 0) {
            w = imagehandle.width;
            h = imagehandle.height;
            if ((w < 10) || (h < 10)) {
                imagehandle.src = 'no_art_big.gif';
            } 
            if (w > 330)  {
            	imagehandle.width = 330;}
        }
    } 
    
   
   function verify_this_image_by_size(imagehandle) {
        if (imagehandle.src.indexOf('MZZZZZZZ') >= 0) {
			if (imagehandle.fileSize < 1000)
			{
                imagehandle.onload = null;
                imagehandle.src = 'no_art_me.gif';
			}
        }
        if (imagehandle.src.indexOf('THUMBZZZ') >= 0) {
   			if (imagehandle.fileSize < 1000)
			{
                imagehandle.onload = null;
                imagehandle.src = 'no_art_sm.gif';
			}
        }
        if (imagehandle.src.indexOf('LZZZZZZZ') >= 0) {
   			if (imagehandle.fileSize < 1000)
			{
                imagehandle.onload = null;
                imagehandle.src = 'no_art_big.gif';
			}
            w = imagehandle.width;
            if (w > 330)  {
            	imagehandle.width = 330;}
        }
    } 
    



function PopupAmazon(asin)
{
	theURL = 'http://buybox.amazon.com/exec/obidos/redirect?tag=peerflix-20&link_code=qcb&creative=23424&camp=2025&path=/dt/assoc/tg/aa/xml/assoc/-/' + asin + '/peerflix-20/ref%3Dac_bb3_';
	winName = "_amazon";
	amznwin = window.open(theURL,winName,'menubar=yes,location=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,width=380,height=450,screenX=10,screenY=10,top=10,left=10');
	amznwin.focus();
}


function popupMsg() 
{ 
    if (navigator.appName.indexOf("Netscape") != -1 && navigator.appVersion.indexOf("Mac") != -1)
    {
        alert('Print this page using your browser\'s print function\n\n You can close the popup browser window once you are finished printing.\n\nIf your printout does not fit on one page, set your print scale to 90 percent.');
    } else {
        alert('Print this page using your browser\'s print function\n\n You can close the popup browser window once you are finished printing.');
    }
    window.print();//brings up the IE print dialog.
}



function IfEnterPressedPostbackButton_OnKeyPress(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13)// process only the Enter key
                  { 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13)
                  { 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
} 

//////////////////////////////////////////
function writit(text,pid)
{
	if (document.getElementById)
	{
		var x = document.getElementById(pid);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		var x = document.all[pid];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		var x = document.layers[pid];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}


//////////////////////////////////////////

arrstars = new Array();
var niout = "stars/star-ni-out.gif"
var niover = "stars/star-ni-over.gif"
var starlight = "stars/starlight.gif";
var staryellow = "stars/staryellow.gif";
var starpurple = "stars/starpurple.gif";
var starred = "stars/starred.gif";
var starred1 = "stars/starred-f1.gif";
var starred2 = "stars/starred-f2.gif";
var starred3 = "stars/starred-f3.gif";
var starred4 = "stars/starred-f4.gif";
var starred5 = "stars/starred-f5.gif";
var thisaspect = "horizontal";
var stringbuilder = "";
var imagename = "";
var i = 0;
var halfstar = false;
var ar1 = 0;
var star_count = -1;
var star_rows = -1;
var starnumber = 0;
var user_rated = 4;
var avg_rated = 3.5;
var productid = 15;
var average_movie_rating = 3;
var star_width = 20;
var star_height = 19;
var star_border = 0;
var star_comment = "Give this DVD a star rating of ";
var StarofChoice;


function setimagename(numImage){
      imagename = "s"+numImage;
}

function colorStars(numRow, numImage, starcolor, starcount){
var parstar = 0;
var orgni = numImage
if (starcount == -1){
	mkbold(numRow);
}
if (starcount > -1){
	mkregular(numRow);
}
   for (i=0; i<5; i++){
      setimagename(numImage);
      if (i <= starcount-1){
         document.images[imagename].src = starcolor;
         }
      else{
   parstar = Math.round((starcount - Math.floor(starcount))*10);
      switch (parstar){
      case 0:
         document.images[imagename].src = starlight;
      break;
      case 1:
         document.images[imagename].src = starred1;
      break;   
      case 2:
         document.images[imagename].src = starred1;
      break;
      case 3:
         document.images[imagename].src = starred2;
      break;
      case 4:
         document.images[imagename].src = starred2;
      break;
      case 5:
         document.images[imagename].src = starred3;
      break;
      case 6:
         document.images[imagename].src = starred3;
      break;
      case 7:
         document.images[imagename].src = starred4;
      break;
      case 8:
         document.images[imagename].src = starred4;
      break;
      case 9:
         document.images[imagename].src = starred5;
      break;
      case 10:
         document.images[imagename].src = starred1;
      break;
      }
      if (i>= Math.ceil(starcount)){document.images[imagename].src = starlight;}        
        }

      numImage++;
   }


}


function mouseOffStar(numRow, numImage){
window.status = "";
   var starOfChoice = arrstars[numRow][0]; 
   var newcolor;
if (arrstars[numRow][0] > 0) {
	newcolor = staryellow;
	StarofChoice = arrstars[numRow][0];
	}
	else if (arrstars[numRow][0] == 0){ 
	newcolor = arrstars[numRow][1];
	StarofChoice = arrstars[numRow][2];
	mkregular(numRow);//INVOKE
	}
	else if (arrstars[numRow][0] == -1){ 
	newcolor = starlight;
	StarofChoice = arrstars[numRow][0];
	mkbold(numRow);
	}
         colorStars(numRow, numImage, newcolor, StarofChoice);
}

function mouseOffStarFriends(numRow, numImage){
window.status = "";
   var starOfChoice = arrstars[numRow][0]; 
   var newcolor;
if (arrstars[numRow][0] > 0) {
	newcolor = starpurple;
	StarofChoice = arrstars[numRow][0];
	}
	else if (arrstars[numRow][0] == 0){ 
	newcolor = arrstars[numRow][1];
	StarofChoice = arrstars[numRow][2];
	mkregular(numRow);//INVOKE
	}
	else if (arrstars[numRow][0] == -1){ 
	newcolor = starlight;
	StarofChoice = arrstars[numRow][0];
	mkbold(numRow);
	}
         colorStars(numRow, numImage, newcolor, StarofChoice);
}


function setstar(numRow, numImage, starnumber){
var starOfChoice = starnumber
   arrstars[numRow][0] = starnumber;
   arrstars[numRow][1] = staryellow;
   if (arrstars[numRow][0] == -1){ 
	newcolor = starlight;
	StarofChoice = arrstars[numRow][0];
	mkbold(numRow);
	}
   colorStars(numRow, numImage, staryellow, starOfChoice);
}


function setstarr(numRow, numImage, starnumber){
   arrstars[numRow][0] = starnumber;
   arrstars[numRow][1] = starred;
   colorStars(numRow, numImage, starred, starnumber);
}
function setstarni(numRow, numImage, starnumber){

   arrstars[numRow][0] = starnumber;
   arrstars[numRow][1] = starred;
   colorStars(numRow, numImage, starred, starnumber);
}

function injectstars(pid, userrated, avgrating, aspect){
   thisaspect = aspect;
   user_rated = userrated; //Store the user rating in a public variable
   avg_rated = avgrating;
   stararray();//This populates the array with the user rating for each set of stars that is spawned by this function.
   starrows(); //This line keeps track of how many rows of stars we have
   document.write('<table border="0" cellspacing="0" cellpadding="0" width="100">');
   document.write('<tr>');
if (aspect == 'horizontal') {
//				document.write('<td align=right>');
//				document.write('<a class=\'PFDataLinkSub\' HREF=\"javascript:submitRating('+pid+',-1);\">');
//				document.write('<img name="nitext'+star_rows+'" src="stars/star-ni-out.gif" alt="NI" width="'+ star_width +'" height="'+ star_height +'" border="' + star_border + '" ');
//				document.write('onClick="mkbold('+star_rows+');setstarr('+star_rows+','+starnumber+',-1);\"')
//				document.write(' onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, -1);window.status=\'Not interested in this DVD. \';return true;"')
//				document.write(' onMouseOut=\"mouseOffStar('+star_rows+','+starnumber+');\">');
//				document.write('</a>');
//				document.write('</td>');
}
for (i=1; i<6; i++){
	document.write('<td valign=top>')
		document.write('<a href=\"javascript:submitRating('+pid+','+i+');\">');
		document.write('<img name="s'+ starcount() +'" src="stars/starlight.gif" alt="'+i+'" width="'+ star_width +'" height="'+ star_height +'" border="' + star_border + '" '
			+ 'onClick="setstar('+star_rows+','+starnumber+','+i+')" '
			+ 'onMouseOver="mkregular('+star_rows+');colorStars('+star_rows+','+starnumber+', staryellow, '+i+'); window.status=\'Give this DVD a '+i+' star rating. \';return true;"'
			+ 'onMouseOut="mouseOffStar('+star_rows+', '+starnumber+')">');
		document.write('</a>');
   document.write('</td>');
}

if (aspect == 'vertical') {
     document.write('</tr><tr><td align=left colspan=3><A class=\'PFDataLinkSub\' '
  + 'onClick="mkbold('+star_rows+');setstarr('+star_rows+','+starnumber+',-1)" '
   + 'onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, -1); window.status=\'Not interested in this DVD. \';return true;"'
   + 'onMouseOut="mouseOffStar('+star_rows+', '+starnumber+')" HREF=\"javascript:submitRating('+pid+',-1)\"><div id="nitext'+star_rows+'"> No Interest</div></a></td>');
     document.write('<td align=right colspan=2><A class=\'PFDataLinkSub\' ' 
   + 'onClick="setstarr('+star_rows+','+starnumber+',0)" '
   + 'onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, 0); window.status=\'Clear your rating for this DVD. \';return true;"'
   + 'onMouseOut="mouseOffStar('+star_rows+', '+starnumber+')" HREF=\"javascript:submitRating('+pid+',0)\">Clear</a></td>');
}

   document.write('</tr></table>');
   mouseOffStar(star_rows, starnumber);
   starnumber = starnumber + 5; 
}

function InjectFriendsStars(pid, userrated, avgrating, aspect){
   thisaspect = aspect;
   user_rated = userrated; //Store the user rating in a public variable
   avg_rated = avgrating;
   stararray();//This populates the array with the user rating for each set of stars that is spawned by this function.
   starrows(); //This line keeps track of how many rows of stars we have
   document.write('<table border="0" cellspacing="0" cellpadding="0" width="100">');
   document.write('<tr>');
if (aspect == 'horizontal') {
//				document.write('<td align=right>');
//				document.write('<a class=\'PFDataLinkSub\' HREF=\"javascript:submitRating('+pid+',-1);\">');
//				document.write('<img name="nitext'+star_rows+'" src="stars/star-ni-out.gif" alt="NI" width="'+ star_width +'" height="'+ star_height +'" border="' + star_border + '" ');
//				document.write('onClick="mkbold('+star_rows+');setstarr('+star_rows+','+starnumber+',-1);\"')
//				document.write(' onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, -1);window.status=\'Not interested in this DVD. \';return true;"')
//				document.write(' onMouseOut=\"mouseOffStar('+star_rows+','+starnumber+');\">');
//				document.write('</a>');
//				document.write('</td>');
}
for (i=1; i<6; i++){
	document.write('<td valign=top>')
		document.write('<a href=\"javascript:submitRating('+pid+','+i+');\">');
		document.write('<img name="s'+ starcount() +'" src="stars/starlight.gif" alt="'+i+'" width="'+ star_width +'" height="'+ star_height +'" border="' + star_border + '" '
			+ 'onClick="setstar('+star_rows+','+starnumber+','+i+')" '
			+ 'onMouseOver="mkregular('+star_rows+');colorStars('+star_rows+','+starnumber+', staryellow, '+i+'); window.status=\'Give this DVD a '+i+' star rating. \';return true;"'
			+ 'onMouseOut="mouseOffStarFriends('+star_rows+', '+starnumber+')">');
		document.write('</a>');
   document.write('</td>');
}

if (aspect == 'vertical') {
     document.write('</tr><tr><td align=left colspan=3><A class=\'PFDataLinkSub\' '
  + 'onClick="mkbold('+star_rows+');setstarr('+star_rows+','+starnumber+',-1)" '
   + 'onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, -1); window.status=\'Not interested in this DVD. \';return true;"'
   + 'onMouseOut="mouseOffStar('+star_rows+', '+starnumber+')" HREF=\"javascript:submitRating('+pid+',-1)\"><div id="nitext'+star_rows+'"> No Interest</div></a></td>');
     document.write('<td align=right colspan=2><A class=\'PFDataLinkSub\' ' 
   + 'onClick="setstarr('+star_rows+','+starnumber+',0)" '
   + 'onMouseOver="colorStars('+star_rows+','+starnumber+', staryellow, 0); window.status=\'Clear your rating for this DVD. \';return true;"'
   + 'onMouseOut="mouseOffStarFriends('+star_rows+', '+starnumber+')" HREF=\"javascript:submitRating('+pid+',0)\">Clear</a></td>');
}

   document.write('</tr></table>');
   mouseOffStarFriends(star_rows, starnumber);
   starnumber = starnumber + 5; 
}

function documentwrite(string){
stringbuilder += string;
}

function stararray(){
   arrstars[ar1] = new Array(3);
   arrstars[ar1][0] = user_rated;
   arrstars[ar1][1] = starred;
   arrstars[ar1][2] = avg_rated;
   ar1++;
}

//
function starrows(){
   star_rows++;
   return star_rows;
}


//
function starcount(){
   star_count++;
   return star_count;
}


function submitRating(pid, rating)
{
	//document.location.href = 'setkarakter.php?f=karakter&pid='+pid+'&DVDRatingByUser='+rating; 
	document.location.href = 'setkarakter.php?f=karakter&vare_varenummer='+pid+'&stjerner='+rating; 
}

function mkbold(numRow){
	idname = "nitext"+numRow;
		switch (thisaspect){
			case "horizontal":
				document.images[idname].src = niover;
			break;
			case "vertical":
				elm = document.getElementById(idname);
				elm.className="nibold";
			break;
		}
}


function mkregular(numRow){
	idname = "nitext"+numRow;
		switch (thisaspect){
		case "horizontal":
//			document.images[idname].src = niout;
		break;
		case "vertical":
			elm = document.getElementById(idname);
			elm.className="niregular";
		break;
		}
}
