/* site_functions.js
 * put site specific javascript functions here
 * is already included in header.tpl
 */

function reviewFeedback(helpful,reviewsId) {
	var strURL = rootPath + "actions/review_feedback.php?reviewsId=" + reviewsId + "&helpful=" + helpful;
	var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if(window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
    self.xmlHttpReq.onreadystatechange = function() {
        if(self.xmlHttpReq.readyState == 4) {
        	//document.getElementById("reviewRating_" + reviewsId).innerHTML = self.xmlHttpReq.responseText;
            reviewWasHelpful(helpful,reviewsId);
        }
    }
    
    self.xmlHttpReq.send(strURL);
}

function reviewWasHelpful(helpful,reviewsId){
	note = "You marked this as<br />a";
	if(helpful == 1) note += " Helpful";
	else note += "n Unhelpful";
	note += " review";
	document.getElementById("reviewRating_" + reviewsId).innerHTML = note;
}

function popup(sPicURL,width,height) {
        window.open(sPicURL, "", "resizable=1,HEIGHT=" + height + ",WIDTH=" + width);
}

// new window popup used for opening up artwork and flash projects
function launchwin(uri,name,args){
	windowReference = window.open(uri,name,args);
	if (!windowReference.opener){
		windowReference.opener = self;
	}
	windowReference.focus();
}

function showFullReview(elementId){
	if(document.getElementById(elementId)){
		document.getElementById(elementId).style.height='auto';
		document.getElementById(elementId).style.overflow='auto';
	}
}

function showTellAFriendForm(title, uri, productId){
    launchwin('tellafriend.html?productId='+productId+'&title='+title+'&uri='+uri, 'Tell A Friend', 'width=300,height=275');
}

function showReviewForm(){
	// not using this
	if(document.getElementById("reviewForm")){
		var reviewForm = document.getElementById("reviewForm");
		reviewForm.style.visibility = "visible";
		reviewForm.style.display = "block";
		reviewForm.style.height = "auto";
	}
}

function showSubNav(subNav,toHide){
	if(toHide != 0 && document.getElementById(toHide)){
		document.getElementById(toHide).style.visibility = "hidden";
		
	} else if(subNav != 0 && document.getElementById(subNav)){
		document.getElementById(subNav).style.visibility = "visible";
	}
}

function ShowItem(itemID) {
	var x = document.getElementById(itemID);
	if (x) x.style.visibility = "visible";
	document.getElementById("subNavLink").src = rootPath + "images/buttons/nav_boards_ro.gif";
	return true;
}

function HideItem(itemID) { 
	var x = document.getElementById(itemID);
	if (x) x.style.visibility = "hidden";
	document.getElementById("subNavLink").src = rootPath + "images/buttons/nav_boards_ini.gif";
	return true;
}

function useAddress(count){
    document.getElementById("address").value = document.getElementById(count+"address").innerHTML;
    if ( document.getElementById(count+"address2") ) {
        document.getElementById("address2").value = document.getElementById(count+"address2").innerHTML;
    }
    else {
        document.getElementById("address2").value = '';
    }
    document.getElementById("city").value = document.getElementById(count+"city").innerHTML;
    document.getElementById("state").value = document.getElementById(count+"state").innerHTML;
    document.getElementById("zip").value = document.getElementById(count+"zip").innerHTML;
}

function changeObjectClass(objectId, classTitle){
	if(document.getElementById(objectId)){
		document.getElementById(objectId).className = classTitle;
		//alert(objectId + ", " + classTitle);
	}
}

function focusOnProductBlock(blockNum){
	if(blockNum > 0){
		for(var i=1; i<24; i++){
			if(i != blockNum){
				var blockId = "product_listing_block_" + i;
				if(document.getElementById(blockId)){
					document.getElementById(blockId).className = "semiTransparent";
				}
			}
		}
	} else {
		for(var i=1; i<24; i++){
			if(i != blockNum){
				var blockId = "product_listing_block_" + i;
				if(document.getElementById(blockId)){
					document.getElementById(blockId).className = "";
				}
			}
		}
	}
}

function jumpToAnchor(url) {
	location.href=url;
}

function updateDivContents(sourceDiv, targetDiv, imageIdsInSet){
	var divSrc = document.getElementById(sourceDiv);
	var divTgt = document.getElementById(targetDiv);
	
	divTgt.innerHTML = divSrc.innerHTML;
	
	if(imageIdsInSet){
		var imageArray = imageIdsInSet.split(",");
		//alert(imageArray);
		
		//toggle all other images off
		for(i=0; i<imageArray.length; i++){
			tabImg = targetDiv + "_" + imageArray[i];
			if(document.getElementById(tabImg)){
				var oldSource = document.getElementById(tabImg).src;
				var newSource = oldSource.replace("_sel", "_ini");
				document.getElementById(tabImg).src = newSource;
			}
		}
		
		// toggle the selected image on
		tabImg = targetDiv + "_" + sourceDiv;
		if(document.getElementById(tabImg)){
			var oldSource = document.getElementById(tabImg).src;
			var newSource = oldSource.replace("_ini", "_sel");
			document.getElementById(tabImg).src = newSource;
		}
		
	}
}

function playHomepageVideo(videoFile){
	if(videoFile){
		document.getElementById('player').href = videoFile;
	}

	document.getElementById('homepageImage').className='hidden';
	document.getElementById('homepageVideo').className='';
	
	flowplayer("player", {
				src: 'inc/flowplayer/flowplayer.commercial-3.1.5.swf', 
				wmode: 'transparent'}, { 
				key: '#$1ba1b8328eea14b3e73', 
 				logo: { opacity: 0 },
			    clip: { 
			        autoPlay: true, 
			        autoBuffering: true 
			    }
			});
}

function changeSearchBoxColor(){
	document.getElementById("searchSubmit").className="searchSubmit_focus"; 
	document.getElementById("searchField").className="searchField_focus"; 
	document.getElementById("searchField").value='';
}

function pagingTitle(t,x,y){
	//document.getElementById("pagingTitle").innerHTML = t;
	
	var callOutImage = document.getElementById("callOutImage");
	var callOut = document.getElementById("callOut");
	
	//pointerPoint = 71 / 65
	if(x && y){
		callOutImage.style.top = (y-42)+"px";
		callOutImage.style.left = (x-56)+"px";
		callOut.style.top = (y-42)+"px";
		callOut.style.left = (x-56)+"px";
	}
	
	if(x && y){
		//alert(x+" / "+y);
	}
	
	callOutImage.style.visibility = (t=="" ? "hidden":"visible");
	callOut.innerHTML = t;
	callOut.style.visibility = (t=="" ? "hidden":"visible");
}

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;
  }

