﻿// JScript File
function findObj(n, d) {
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
    x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
    x=d.getElementById(n); 
  return x;
}
    
function getObjInnerText (obj) {
    if(!obj)
        return "";
    return (obj.innerText) ? obj.innerText
    : (obj.textContent) ? obj.textContent
    : "";
} 

function adjustHighlight(div,img){
    //var currRating = document.getElementById('rateCurrentRating_9473').innerText;
    var currRating = getObjInnerText(findObj(div,document));
    //currRating = document.getElementById(currRating).innerText;
    currRating = getObjInnerText(findObj(currRating,document));
    	
    var divImages = findObj(div,document);

    if(divImages){
	    var i, foundOver = false, foundCurrent = false;
	    var img_selected = '../assets/purple_star.gif';
	    var img_unselected = '../assets/grey_star.gif';
	    //var img_over = '../assets/orange_star.gif';
	    var img_red = '../assets/orange_star.gif';
	    var img_over = '../assets/purple_star.gif';
    	
	    var img_path = '';
	    var imgs = divImages.getElementsByTagName('input');
	    for(i = 0; i < imgs.length; i++){
		    //get the path from the first image that is found
		    if(img_path == ''){
			    img_path = imgs[i].src.substring(0, imgs[i].src.lastIndexOf('/') + 1);
		    }
    		
		    if(img == null){
			    if(currRating == 0) foundCurrent = true;
			    if(foundCurrent)
				    imgs[i].src = img_path + img_unselected;
			    else{
				    if(i == currRating){
					    foundCurrent = true;
					    imgs[i].src = img_path + img_unselected;
				    }else{
					    imgs[i].src = img_path + img_selected;
				    }
			    }
		    }else{
			    if(imgs[i].id == img.id)
				    imgs[i].src = img_path + img_red;
		    }
	    }
    }
}	

function adjustSmallHighlight(div,img){
	//var currRating = document.getElementById('rateCurrentRating_9473').innerText;
	var currRating = getObjInnerText(findObj(div,document));
	//currRating = document.getElementById(currRating).innerText;
	currRating = getObjInnerText(findObj(currRating,document));
		
	var divImages = findObj(div,document);
	
	if(divImages){
		 var i, foundOver = false, foundCurrent = false;
	    var img_selected = '../assets/purple_star.gif';
	    var img_unselected = '../assets/grey_star.gif';
	    //var img_over = '../assets/orange_star.gif';
	    var img_red = '../assets/orange_star.gif';
	    var img_over = '../assets/purple_star.gif';
		
		var img_path = '';
		var imgs = divImages.getElementsByTagName('input');
		for(i = 0; i < imgs.length; i++){
			//get the path from the first image that is found
			if(img_path == ''){
				img_path = imgs[i].src.substring(0, imgs[i].src.lastIndexOf('/') + 1);
			}
			
			if(img == null){
				if(currRating == 0) foundCurrent = true;
				if(foundCurrent)
					imgs[i].src = img_path + img_unselected;
				else{
					if(i == currRating){
						foundCurrent = true;
						imgs[i].src = img_path + img_unselected;
					}else{
						imgs[i].src = img_path + img_selected;
					}
				}
			}else{
				if(imgs[i].id == img.id)
					imgs[i].src = img_path + img_red;
			}
		}
	}
}