/* JavaScript Document            */
/* Coded by Sharon Webber-Zvik    */
/*    Miss.Behave Design Studio   */
/*       http://www.mis-b.com     */
/*        sharonweb@gmail.com     */
/*								  */

/* templink: <script type="text/javascript" src="http://www.mis-b.com/netta/design_tweaks.js"></script> */


// debugger


// replace images, texts, IDs



//give the body tag an ID for later usage inside IDless objects:

function setbodyid (newid)
{
//	alert (document.body.id);
	document.body.id = newid;
//	alert (document.body.innerHTML);
}




function IdentifyBrowser ()
{
	if (ie) 
	alert ("This is Internet Explorer");
	else 
	alert ("This is -NOT- Internet Explorer");
}




// TEXT REPLACEMENT FUNCTION
// Uses replace() on innerHTML property of DOM Objects
function replaceById(needle, replacement, id) {
	 if (document.getElementById(id))
	 {
		 var haystackText = "";
		 if (haystackText.length == 0) {
			  haystackText = document.getElementById(id).innerHTML;
		 }
		 var match = new RegExp(needle, "ig");  
		 var replaced = "";
		 if (replacement.length > 0) {
			  replaced = haystackText.replace(match, replacement);
		 }
		 else {
			  var boldText = "<div style=\"background-color: yellow; display: inline; font-weight: bold;\">" + needle + "</div>";
			  replaced = haystackText.replace(match, boldText);
		 }
		 document.getElementById(id).innerHTML = replaced;
	 }
}


// TEXT REPLACEMENT DEBUGGING FUNCTION
// Uses replace() on innerHTML property of DOM Objects
// Does the same as "replaceById", but adds alert messages
function replaceByIdDebug(needle, replacement, id) {
	IdentifyBrowser ();
	var haystackText = "";
	if (document.getElementById(id)) 
	{
		alert ('inside fuction');
		alert ('needle:\n ' + needle);
		alert ('replacement:\n ' + replacement);
		alert ('id:\n ' + id);
		 if (haystackText.length == 0) {
			  alert ('no haystackText');
			  haystackText = document.getElementById(id).innerHTML;
			  alert('innerHTML before:\n ' + haystackText);
		 }
		 var match = new RegExp(needle, "ig");
		 alert ('match:\n ' + match);
		 var replaced = "";
		 if (replacement.length > 0) {
			  replaced = haystackText.replace(match, replacement);
			  alert('replaced:\n ' + replaced);
		 }
		 else {
			  var boldText = "<div style=\"background-color: yellow; display: inline; font-weight: bold;\">" + needle + "</div>";
			  replaced = haystackText.replace(match, boldText);
		 }
		 if (haystackText != document.getElementById(id).innerHTML)
			alert ('ERROR !!!');
		 document.getElementById(id).innerHTML = replaced;
		 alert ("DONE!!!");
    }
    else 
	{
	    alert ('ID NOT found');		  	  
    }

}

//Replace cart buttons
var ordinpts = document.getElementsByTagName('input');
//alert (ordinpts.length); 
if(ordinpts)
	{ 
	for(var i=0; i<ordinpts.length; i++)
		{
		//alert (ordinpts[i].name);
        if(ordinpts[i].name == "_submit")
            ordinpts[i].src = "/images/add_to_cart.jpg";
		if(ordinpts[i].alt == "Update")
            ordinpts[i].src = "/images/update.jpg";	
		if(ordinpts[i].name == "go")
            ordinpts[i].src = "/images/go.jpg";				
        }
	}
	
//Replace various images
var ordinpts2 = document.getElementsByTagName('img');
//alert (ordinpts2.length); 
if(ordinpts2)
	{ 
	for(var i=0; i<ordinpts2.length; i++)
		{
		//alert (ordinpts2[i].alt);
        if(ordinpts2[i].alt == "Add to Cart")
            ordinpts2[i].src = "/images/add_to_cart.jpg";
        if(ordinpts2[i].alt == "Checkout")
            ordinpts2[i].src = "/images/begin_checkout.jpg";
		if(ordinpts2[i].alt == "Email a friend")
            ordinpts2[i].src = "/images/email.jpg";	
		if(ordinpts2[i].alt == "View larger image")
            ordinpts2[i].src = "/images/larger.jpg";	
		if(ordinpts2[i].alt == "Continue Shopping")
            ordinpts2[i].src = "/images/continue.jpg";	
		if(ordinpts2[i].alt == "Update") 
			ordinpts2[i].src = "/images/update.jpg";	
		if(ordinpts2[i].alt == "Remove")
            ordinpts2[i].src = "/images/remove.jpg";	
		if(ordinpts2[i].alt == "Details")
            ordinpts2[i].src = "/images/details.jpg";
		if(ordinpts2[i].alt == "Alma Boutique") {
            ordinpts2[i].width = "150";	
			ordinpts2[i].height = "77";	
		}
		}
	}



//replace top link bar
if (ie)
	{
	replaceById ("<a class=t href=\"/\">Home</a> \\| <a class=t href=\"/cart.htm\">View Cart</a> \\| <a class=t href=\"/myAccount.htm\">My Account</a> \\| <a class=t href=\"/orderStatus.htm\">Order Status</a>", "<a class=\"t\" href=\"/\">Home</a> | <a class=\"t\" href=\"/cart.htm\">View Cart</a> | <a class=\"t\" href=\"/myAccount.htm\">Customer Service</a> | <a class=\"t\" href=\"/orderStatus.htm\">Order Status</a> | <a class=\"t2\" href=\"/info/About_Us\">About Us</a> | <a class=\"t2\" href=\"/info/Contact_Us\">Contact Us</a> | <a class=\"t2\" href=\"http://blog.almaboutique.com\" target=\"_blank\">Blog</a>", "myaccountnav");
	}
else
	{
	replaceById("My Account", "Customer Service", "myaccountnav");
	replaceById("<a class=\"t\" href=\"/orderStatus.htm\">Order Status</a>", "<a class=\"t\" href=\"/orderStatus.htm\">Order Status</a> | <a class=\"t2\" href=\"/info/About_Us\">About Us</a> | <a class=\"t2\" href=\"/info/Contact_Us\">Contact Us</a> | <a class=\"t2\" href=\"http://blog.almaboutique.com\" target=\"_blank\">Blog</a>", "myaccountnav");
	}
	
	
	
//replace SKU text	
replaceById ('<b>SKU: </b>', '<b>Item Code: </b>', "sku");
	


//replace bottom link bar
if (ie)
	replaceById ("<td><a class=v href=\"/info/Privacy_Policy\">Privacy Policy</a></td>", "<td><a class=\"v\" href=\"/home.htm\">Home</a>&nbsp;|&nbsp;<a class=\"v\" href=\"/info/Privacy_Policy\">Privacy Policy</a>&nbsp;</td>", "footernav");
else
	replaceById ("<td><a class=\"v\" href=\"/info/Privacy_Policy\">Privacy Policy</a></td>", "<td><a class=\"v\" href=\"/home.htm\">Home</a>&nbsp;|&nbsp;<a class=\"v\" href=\"/info/Privacy_Policy\">Privacy Policy</a>&nbsp;</td>", "footernav");
		
		
