function redirect (url) {

	location.href = url;

	return false;

}

function confirm_redirect (url, message) {

	if (confirm (message))
		redirect (url);

	return false;

}

function confirm_delete (url, message)
{
	if (confirm (message))
		redirect (url);
}

function highlight (element) {

	Element.addClassName (element, 'highlight');

}

function unhighlight (element) {

	Element.removeClassName (element, 'highlight');

}

function show (id)
{
	$('#' + id).show();
}

function hide (id)
{
	$('#' + id).hide();
}

function toggle_visibility(id)
{
	$('#' + id).toggle();
}

function switch_display (hide, show) {

	if (hide)
	document.getElementById(hide).style.display = 'none';

	if (show)
	document.getElementById(show).style.display = '';

}

function get_XML_element_content(tag, xmlString){

	var startTag = "<"+tag+">";
	var endTag = "</"+tag+">";

	return xmlString.substring( (xmlString.indexOf(startTag)+startTag.length) , (xmlString.indexOf(endTag,xmlString.indexOf(startTag)+startTag.length)) );
}

function urlencode(str) {
	var result = "";

	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}

	return escape(result);
}

function urldecode(str) {
	return unescape(str.replace(/\+/g, " "));
}

function format_cc (element) {

	element.value = element.value.replace(/([^0-9]*)/g, '');

}

function Convert(){

    this.inchesInMM = 0.0393700787;

    this.inchesToMm = function (inch){
    return (parseFloat(inch) / this.inchesInMM).toFixed(3);
    }

    this.mmToInches = function (mm){
    return (parseFloat(mm) * this.inchesInMM).toFixed(3);
    }

}

function checkShipMethod(value){

    var changeAccount = new RegExp("charge([A-Z]+)");
    var DHL = new RegExp("DHL 3-4");
    var over250 = new RegExp("over250");


    var shipAcIn = document.getElementById('shipping_account_input');
    shipAcIn.style.display = 'none';
    shipAcIn.value = '';

    var shipNote = document.getElementById('shipping_note');
    shipNote.style.display = 'none';

    if( value.search(changeAccount)!= -1){

        shipAcIn.style.display = '';
        shipNote.style.display = '';

    }else if( value.search(DHL)!= -1 || value.search(over250)!= -1 ) {

        shipNote.style.display = '';
    }
}

$(document).ready(function()
{
	
	$(".close-widget").each(function(i){
		$(this).bind("click",function(){
			div_parent = this.parentNode.parentNode;
			$(div_parent).hide();
		});
	});

	//Auto focus first form element on a page
	focused = false;
	$('.ncform input').each(function(i){
		if(this.type == 'text' && focused == false)
		{
			try
			{
				this.focus();
				focused = true;
			}
			catch(e){}
		}
	});
	
	//Popup windows, just add popup class to any link (replaces the old target=_blank)
	$('a.popup').bind('click',function(){
		window.open(this.href);
		return false;
	});

	$(window).resize(function(){
		$('body > div.autocomplete').remove();
	});

	if($('#main_shoppingcart_nested').length)
		$('#main_shoppingcart_nested').corner('5px');
});

//jquery plugin for unsetting an attribute
$.fn.unset = function(a) {
  return this.each(function(){
    if ( a && a.constructor == String ) {
      var fix = {
        'for': 'htmlFor',
        'text': 'cssText',
        'class': 'className',
        'float': 'cssFloat'
      };
      a = (fix[a] && fix[a].replace && fix[a]) || a;
      this[a] = null;
      if ( this.removeAttribute ) this.removeAttribute(a);
    }
  });
} 

