
//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_bill_"+copyToShipping.arguments[i]+".selectedIndex = document.cartform.f_ship_"+copyToShipping.arguments[i]+".selectedIndex");
		else
		  eval("document.cartform.f_bill_"+copyToShipping.arguments[i]+".value = document.cartform.f_ship_"+copyToShipping.arguments[i]+".value");
		
	  }else{
		if(copyToShipping.arguments[i] == "state")
			eval("document.cartform.f_bill_"+copyToShipping.arguments[i]+".selectedIndex = 0");
		else
			eval("document.cartform.f_bill_"+copyToShipping.arguments[i]+".value = ''");
	  }
	  i++;
	}
}

//navigate through shopping cart process
function stepto(step){
	document.forms['cartform'].action = "checkout.php"
	document.forms['cartform'].step.value = step;
	document.forms['cartform'].submit();
	return false;
}

//function to submit the final process
var theForm;
var requestSubmitted = false; 

function disableButton(btn,form) {
	if (!requestSubmitted){
		var submitMessage = "  PLEASE WAIT...  ";
		btn.value = submitMessage;
		theForm = form;
		theForm.action = "process_payment.php"
		btn.disabled = true;
		requestSubmitted = true;
		setTimeout("submitIt()", 250);
	} else {
		return false;
	}
}

//submit the form
function submitIt() {
	theForm.submit();
	return false;
}

function session_win(url) {
	window.open(url,"info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes").focus();
	return false;
}

function cvv_win(url) {
	var thewin = window.open(url,"cvv","height=400,width=500,toolbar=no,statusbar=no,scrollbars=yes");
	thewin.focus();
	return false;
}

function switchPhoto(sImg)
{
	document['dProdImage'].src = sImg;
	return false;
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}	
}

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImages() {
    for (var i = 0; i < arguments.length; i += 2) {
		document.getElementById(arguments[i]).src = eval(arguments[i + 1]+'.src');
	}
}

document.addEvent = function(object, eventType,fn, useCapture) {
	if (object.addEventListener) {
		object.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (object.attachEvent) {
			var r = object.attachEvent("on"+eventType, fn);
			return r;
		}
	}
};

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  return elements;
};

String.prototype.replace = function(f,r){
	return (f == r? this : this.split(f).join(r));
}

Object.prototype.toggle = function(){
	if ( this.style ) {
		if ( this.style.display != 'none' ) {
			this.style.display = 'none';
		}
		else {
			this.style.display = '';
		}
	}
};


function zoomAlternateImage(type, sku) {
	var uri = '/i/prod/zoom/' + sku + '_' + type + '.jpg';
	var imageWidth = 620;
	var imageHeight = 620;
   	var left = Math.floor( (screen.width - imageWidth) / 2);
    var top = Math.floor( (screen.height - imageHeight) / 2);
	fWindow = window.open(uri,'features','left='+left+',top='+top+',width='+imageWidth+',height='+imageHeight+',scrollbars=yes,resizable=yes');
	fWindow.focus();
	return false;
}

function zoomMainImage(sku) {
	var uri = '/i/prod/zoom_big/' + sku + '.jpg';
	var imageWidth = 620;
	var imageHeight = 620;
   	var left = Math.floor( (screen.width - imageWidth) / 2);
    var top = Math.floor( (screen.height - imageHeight) / 2);
	fWindow = window.open(uri,'features','left='+left+',top='+top+',width='+imageWidth+',height='+imageHeight+',scrollbars=yes,resizable=yes');
	fWindow.focus();
	return false;
}
