var prev_data = ""

function StoreNameUrlFriendly (source, target)
{
	var result = new String (source)
	result = result.toLowerCase();
	result = result.replace(/[^a-z0-9]+/g,'');

	
	var tmp = document.getElementById(target).innerHTML;
	if (prev_data)
		tmp	= prev_data;		
	else
		prev_data = tmp;
	
	tmp = tmp.replace ("http://www.pedrosplaza.com/store_index.php?n=","http://www.pedrosplaza.com/store.php?n="+result);
	tmp = tmp.replace ("http://www.pedrosplaza.com/tienda_index.php?n=","http://www.pedrosplaza.com/tienda.php?n="+result);	
	tmp = tmp.replace ("http://www.pedrosplaza.com/store/","http://www.pedrosplaza.com/store/"+result);
	tmp = tmp.replace ("http://www.pedrosplaza.com/tienda/","http://www.pedrosplaza.com/tienda/"+result);	

	
	document.getElementById(target).innerHTML = tmp;			

}

function ClearSearch (field)
{
	if (field.value == "")
		field.value = search_field
	else if (field.value == search_field)
		field.value = ""
}


function ConfirmDeletion (formName,fieldname,error_msg)
{
	var myForm = eval ('document.'+formName);

	var status               = confirm (error_msg)
	if (status)
	{
		myForm["cmd"].value = "del";
		myForm.submit();		
	}	
}


function viewImage (filename, width, height)
{
	var tmp = filename.split ("/");
	var str = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height
	var html ='<html>\n<head>\n<title>Preview - '+ tmp[2] +'</title></head>\n';
	html += '<body bgcolor="white" leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginwidth=0 marginheight=0>\n';
	html += '<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr><td align=center id="s"><a href="javascript:window.close();"><img src="'+filename+'" width="'+width+'" height="'+height+'" border=0 alt="Click to Close Window"></a></td></tr></table>';
	html += '\n</body>\n</html>';

	var win = window.open("","_blank", str);
	win.document.open("text/html", "replace");	
	win.document.write(html);
	win.document.close();
	win.window.focus();	
}

var prev_image	= "";
var target		= "";
var prev_path	= "";

var reload_image = new Array ();
function loadImage (filename)
{
	if (prev_image)
	{
		document.getElementById(prev_image).className = '';
		document.getElementById('d_'+prev_image).style.display = 'none';
	}
	document.getElementById(filename).className = 'selected_image';
	document.getElementById('d_'+filename).style.display = 'block';
	prev_image = filename;

}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)
}



function CreateBookmarkLink(title,url) 
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
function HideDiv (div_name)
{
	document.getElementById(div_name).className 				= "invisible";	
}

var current_promo = 1;
function NextPromo (total_size)
{
	document.getElementById("promo"+current_promo).className 	= "invisible";	
	
	if (current_promo == total_size)
		current_promo = 1
	else
		current_promo++;	
		
	document.getElementById("promo"+current_promo).className 	= "visible";	
		
}
