//preload images
Img_star_on = new Image(12,12);
Img_star_on.src = "images/star_on.gif";

Img_star_off = new Image(12,12);
Img_star_off.src = "images/star_off.gif";

Img_star_half = new Image(12,12);
Img_star_half.src = "images/star_half.gif";

progressingImg = new Image(16,16);
progressingImg.src = "images/circleloader.gif";

function resizeImgObj()
{
  var all = document.all ? document.all :
    document.getElementsByTagName('img');
  
  for (var e = 0; e < all.length; e++)
    if (all[e].className == "pic" && all[e].width > 550)
      all[e].width = 550;  
}

function IsEmpty(aTextField) 
{
   if ((aTextField.value.length==0) ||
   (aTextField.value==null) || (aTextField.value =="http://")) {
      return true;
   }
   else { return false; }
}

function validateCommentSubmitForm()
{
	showCommentSummitting();
	
	if(IsEmpty(document.submitComment.desc))
	{
		hideCommentSummitting();
		alert("Please enter your comment!");
		return false;
	}
	
	if(IsEmpty(document.submitComment.user_code))
	{
		hideCommentSummitting();
		alert("Please enter the verification code!");
		return false;
	}
	
	return true;
}

function validateUrlSubmitForm()
{
	showUrlSummitting();
	if(IsEmpty(document.submitURL.submit_type))
	{
		hideUrlSummitting();
		alert("Please select an url category!");		
		return false;
	}
	
	if(IsEmpty(document.submitURL.url))
	{
		hideUrlSummitting();
		alert("Please enter an url!");
		return false;
	}	
	
	if(IsEmpty(document.submitURL.user_code))
	{
		hideUrlSummitting();
		alert("Please enter the verification code!");
		return false;
	}
	
	return true;
}

function showUrlSummitting()
{
	document.getElementById("UrlSubmmitting").innerHTML = "Submitting...";
}

function hideUrlSummitting()
{
	document.getElementById("UrlSubmmitting").innerHTML = "";
}

function showCommentSummitting()
{
	document.getElementById("CommentSubmmitting").innerHTML = "Submitting...";
}

function hideCommentSummitting()
{
	document.getElementById("CommentSubmmitting").innerHTML = "";
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
////////////////////////
// Product Rating
////////////////////////
var justRated = false;
function rating(RatingScore)
{
	if(!justRated)
	{
		for(i=1; i<=5; i++)
		{		
			imgName = "s"+i;
			if(i<=RatingScore)
			{
				//document.getElementById(i).className = "on";
				document.images[imgName].src = Img_star_on.src;
				document.images[imgName].style.cursor = "pointer";
				document.getElementById("ratingMsg").innerHTML = document.images[imgName].alt;
			}
			else
			{
				document.images[imgName].src = Img_star_off.src;
			}
		}
	}
}

function showProductRatingStars()
{	
	document.images['s1'].src = Img_star_off.src;
	document.images['s2'].src = Img_star_off.src;
	document.images['s3'].src = Img_star_off.src;
	document.images['s4'].src = Img_star_off.src;
	document.images['s5'].src = Img_star_off.src;	
	
	for(i=1; i<=5; i++)
	{		
		imgName = "s" + i;
		if(ratingScore >= i)
			document.images[imgName].src = Img_star_on.src;
		else
		{
			if(ratingScore >= (i-0.5))
				document.images[imgName].src = Img_star_half.src;			
		}
	}	
}

function showProdRatingMsg(Msg)
{
	document.getElementById("ratingMsg").innerHTML = Msg;
}

function off()
{	
	if(!justRated)
	{
		document.getElementById("ratingMsg").innerHTML = document.getElementById("ratingMsg").title;		
		showProductRatingStars();
	}	
}