
function show_medium_pic(DivId, medium_file_name, h, w)
	{
	var medPic = '<img src="' + medium_file_name + '" height="' + h + '" width="' + w + '" border="0">';
	document.getElementById(DivId).innerHTML = medPic;
	}


function show_medium_pic_with_lb(DivId, medium_file_name, h, w, lb_file_name)
	{
	var medPic = '<a href="' + lb_file_name + '" class="highslide" onclick="return hs.expand(this)"><img src="' + medium_file_name + '" height="' + h + '" width="' + w + '" border="0"></a><br>';
	medPic = medPic + '<div style="padding:5px;"><a href="' + lb_file_name + '" class="clicktoexpand" onclick="return hs.expand(this)">Larger view  - click to view - click to close</a></div>';
	document.getElementById(DivId).innerHTML = medPic;
	}









function image_reorder(product_id, pic_id, direction)
	{
	xmlhttp=new GetXmlHttpObject();
	xmlhttp.onreadystatechange= function() 
		{ 
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			var return_text = xmlhttp.responseText;

			if (return_text == "REORDER_IMAGE_SUCCESS")
				reload_image_div(product_id);
			else
				alert(return_text);
			}
		}
	var url="ajax_reorder_image.php";
	url=url+"?product_id="+product_id;
	url=url+"&pic_id="+pic_id;
	url=url+"&action="+direction;
	url=url+"&sid="+Math.random();

	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}




function reload_image_div(product_id)
	{
	var DivId = "display_images_div";
	var loading_icon = '<img src="/pics/ajax-loader.gif">'; 
	
	document.getElementById(DivId).innerHTML = loading_icon;



	xmlhttp=new GetXmlHttpObject();
	xmlhttp.onreadystatechange= function() 
		{ 
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById(DivId).innerHTML = xmlhttp.responseText;
			return;
			}
		}
	var url="ajax_get_display_images.php";
	url=url+"?product_id="+product_id;
	url=url+"&sid="+Math.random();

	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	return;
	}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}




function confirm_image_remove(product_id, pic_id)
	{
	if (confirm('Remove this image from this product.\n\nNote, the image itself is not removed.'))
		{
		xmlhttp=new GetXmlHttpObject();
		xmlhttp.onreadystatechange= function() 
			{ 
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				var return_text = xmlhttp.responseText;

				if (return_text == "IMAGE_REMOVE_SUCCESS")
					reload_image_div(product_id);
				else
					alert(return_text);
				}
			}
		var url="ajax_remove_product_image.php";
		url=url+"?product_id="+product_id;
		url=url+"&pic_id="+pic_id;
		url=url+"&sid="+Math.random();

		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		}

	}



function textCounter(field, countfield, maxlimit) 
{
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
else 
	countfield.value = maxlimit - field.value.length + " characters left";
}


function flippopup(){
uploadwin = open('/ecoflip.html', 'upload', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,width=680,height=500')
uploadwin.focus()
}


function showLayer(whichLayer)
	{
	if (document.getElementById)
		{
		var style3 = document.getElementById(whichLayer).style;
		style3.display =  "block";
		}  
	else if (document.all)
		{
		var style3 = document.all[whichLayer].style;
		style3.display =  "block";
		}
	else if (document.layers)
		{
		var style3 = document.layers[whichLayer].style;
		style3.display =  "block";
		}
	}




function hideLayer(whichLayer)
	{
	if (document.getElementById)
		{
		var style3 = document.getElementById(whichLayer).style;
		style3.display =  "none";
		}  
	else if (document.all)
		{
		var style3 = document.all[whichLayer].style;
		style3.display =  "none";
		}
	else if (document.layers)
		{
		var style3 = document.layers[whichLayer].style;
		style3.display =  "none";
		}
	}




function popup(url){
editwin = open(url, "editwin",'height=350,width=400,resizable=no,scrollbars=yes')
editwin.focus()
}


function setLoadingIcon()
	{
	var loading_icon = '<img src="/pics/ajax-loader.gif">'; 
	document.getElementById('wait_div').innerHTML = loading_icon;
//	document.getElementById('wait_div').style.display = 'block';

	}




function confirm_image_delete()
	{
	if (confirm('Do you want to permanently delete this image?'))
		self.document.forms['delete_image_form'].submit();
	else
		self.document.forms['delete_image_form'].reset();
}


/**************************************************************************************/
// tool tip help strings
/**************************************************************************************/


function ttshow(helpitem){
var help_strings = new Array()

// product images
help_strings[100] = 'Up';
help_strings[101] = 'Down';
help_strings[102] = 'Top / primary image';
help_strings[103] = 'Bottom';
help_strings[104] = 'Remove this image from this product<p>Note, image is still available to other products.';

tooltip.show(help_strings[helpitem]);
}

function tth()
{
tooltip.hide();
}




/**************************************************************************************/
// tooltip code
// based on http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/
/**************************************************************************************/




var tooltip=function(){
	var id = 'tt';
	var top = 0;
	var left = 30;
	var maxw = 600;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
			
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				
				tt.appendChild(c);
				
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				tt.style.width = tt.offsetWidth;
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
//			tt.style.top = (u - h) + 'px';
			tt.style.top = (u + top) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();








