function externalLinks() {
    if (!document.getElementsByTagName) return;

    var anchors = document.getElementsByTagName('a');
    for(var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == 'external' || (anchor.getAttribute('href').indexOf('javascript') == -1 && anchor.hostname != window.location.hostname))) {
            anchor.target = '_blank';
        }
    }
}
window.onload = externalLinks;

//function to copy shipping to billing fields
function copyToShipping(){
	var flag = document.cartform.f_bill_sameasshipping.checked;
	var form = document.cartform;
	var i = 0;
	while(i < copyToShipping.arguments.length) {
	  if(flag){
		if(copyToShipping.arguments[i] == "state")
		  eval("document.cartform.f_billing_"+copyToShipping.arguments[i]+".selectedIndex = document.cartform.f_shipping_"+copyToShipping.arguments[i]+".selectedIndex");
		else
		  eval("document.cartform.f_billing_"+copyToShipping.arguments[i]+".value = document.cartform.f_shipping_"+copyToShipping.arguments[i]+".value");

	  }else{
		if(copyToShipping.arguments[i] == "state")
			eval("document.cartform.f_billing_"+copyToShipping.arguments[i]+".selectedIndex = 0");
		else
			eval("document.cartform.f_billing_"+copyToShipping.arguments[i]+".value = ''");
	  }
	  i++;
	}
}

function changeFontSize(inc)
{
	new Ajax.Request("/togglefont/index/"+inc, {
		method: "get",
		onLoading: function(transport) {
			$('main').style.fontSize = inc+"%";
			
			var elem = document.getElementsByTagName('h3');
		  	for(n=0; n<elem.length; n++) {
				if(elem[n].style.fontSize) {
			 	  var size = parseInt(elem[n].style.fontSize.replace("pt", "").replace("px", ""));
				} else {
			 	  var size = 100;
				}	
	
				elem[n].style.fontSize = inc + 'px';
		  	}
		}
	});
}
