/**
* JavaScript for doc_checkout.php
*
* @package Site
* @subpackage Templates
* @author <tonis@digitalfruit.ee>
*/

function lightboxSubmit(form){

	form.request({

		onSuccess : function(transport){
			var res = transport.responseText;
			if(res == "OK"){
				window.location.reload(true);
			}
			else {
				openedLightbox.processInfo(transport);
			}
		}

	});


}

function ajaxSubmit(form,container)
{
	var f = $( form );
	if ( f ) {
		f.request({
			evalScripts: true,
			onSuccess : function(transport){
				var res = transport.responseText;
				$(container).update(res);
			}
		});
	}
}


function copyFields( checkbox )
{
	if(typeof checkbox != "object") return;
	var f = checkbox.form;
	var names = [ 'address', 'town', 'zip' ];

	for ( var i in names ) {
		if ( f.elements['s_'+names[i]] ) {
			var s = $(f.elements['s_'+names[i]]);
			var b = $(f.elements['b_'+names[i]]);

			if ( checkbox.checked ) {
				b.sfield = s;
				b.copyFunction = copyContentsToShipping.bindAsEventListener(b);
				s.stopFunction = stopCopy.bindAsEventListener(s);
				s.value = b.value;
				b.observe("change",b.copyFunction);
				s.observe("change",s.stopFunction);
				b.observe("keydown",b.copyFunction);
				s.observe("keydown",s.stopFunction);
			} else {
				b.stopObserving("keydown",b.copyFunction);
				s.stopObserving("keydown",s.stopFunction);
				b.stopObserving("change",b.copyFunction);
				s.stopObserving("change",s.stopFunction);
			}
		}
	}
}
function copyContentsToShipping(){
	this.sfield.value = this.value;
}

function stopCopy(){
	var checkbox = $("s_billing");
	checkbox.checked = false;
	copyFields(checkbox);
}

function redborder(ob){
	ob.style.borderColor = "#BF1D1B";
}
function grayborder(ob){
	ob.style.borderColor = "#CCCCCC";
}