function updateArtworkStatus(value, id){

	var url = 'bin/update_artwork_status.php';
	var params = 'id=' + id + '&status=' + value;
	new Ajax.Request(url, {method: "post", parameters: params, onComplete:reportSuccess});
	
}

function reportSuccess(){
	alert("Artwork Status Updated");
}

function cancelRider(id, canceled_status){
	if (confirm("Are You Sure")) {
		params = "id="+id+"&status="+canceled_status
		url = "bin/cancel_rider.php"
		new Ajax.Request(url, {method: "post", parameters: params, onComplete:reportCancelRiderSuccess(canceled_status)});
		return true;
	};
	return false;
}

function changeCharro(order_id, new_charro){
	$('change_charro_result').toggle();
	if (confirm("Are You Sure")) {
		var new_charro_id = $(new_charro).value;
		params = "order_id="+order_id+"&charro="+new_charro_id
		url = "bin/change_charro.php"
		new Ajax.Updater('change_charro_result',url, {method: "post", parameters: params, onSuccess:function(){$('change_charro_result').show()}});
		return true;
	};
	return false;
}

function reportCancelRiderSuccess(status){
	if (status == "true") {
		alert("Rider was successfully cancelled");
	}else{
		alert("Rider was successfully activated");
	};
	
}

function checkRows(order_id){
	var boxes = document.getElementsByTagName('input');
	for (var i=0; i < boxes.length; i++) {
		if (boxes[i].className.indexOf("order_" + order_id + "_checkbox") > -1) {
			boxes[i].checked = true;
		};
	};
}


function popwindow(url){
	var newwindow;
	newwindow=window.open(url,'name','height=800,width=1000,scrollbars=1,resizable=1');
	if (window.focus) {newwindow.focus()}
}

function addNewsCategory(value){
	if (value == "new_category") {
		// var name = prompt("Category Name:");
		// if (name != null) {
		// 	$('new_category_option').value = name;
		// 	$('new_category_option').removeChild($('new_category_option').childNodes[0]);
		// 	var option_text = document.createTextNode(name)
		// 	$('new_category_option').appendChild(option_text);
		// 	$('upload_category').value = name;
		// };
		$('new_category_text').name = "upload[category]";
		$('new_category_text').setAttribute("name","upload[category]");
		$('new_category_text_row').show();
	}else{
		$('new_category_text').value="";
		$('new_category_text').name = "";
		$('new_category_text').setAttribute("name","");
		$('new_category_text_row').hide();
	};
}

function checkAllCheckBoxes (value) {

	$A(document.getElementsByTagName('input')).each(
		function(c){
			if( c.type == "checkbox" && c.name != 'check_all' ){
				if (value == true) {
					c.checked = true;
				}else{
					c.checked = false;
				};
				
			}
		});
}

function customerChange( val, id )
{
	
	if( val == "old" && id != "" ){
		//new Ajax.Updater('newcustomer','bin/customer_form.php', {parameters:'id='+id});
		$("#newcustomer").load("bin/customer_form.php", { 'id': id } );
		$('#newcustomer').show();
	}else if(val == "new"){
		$("#newcustomer").load("bin/customer_form.php", { 'id': -1 } );
		$('#newcustomer').show();
	};
}

function paymentChange(  )
{
	var el = document.getElementById( 'payment_method' );
	var val = el.value;
	var entry = document.getElementById( 'cc_details' );
	if( val=='bill' || val=='paid' || val=='comp' || val=='echeck' || val=="billmelater")
		entry.style.display = "none";
	else
		entry.style.display = "block";
		
	entry = document.getElementById( 'paid_details' );
	if( val=='paid' )
		entry.style.display = "block";
	else
		entry.style.display = "none";
		
	entry = document.getElementById( 'echeck_details' );
	if( val=='echeck' )
		entry.style.display = "block";
	else
		entry.style.display = "none";
}

function processSameAs( checkboxId, sourcePrefix, destPrefix )
{
	var checked = document.getElementById( checkboxId ).value;
	if( checked!='on' )
		return;

	var cols = Array( 'firstname','lastname','email','title','company','address1','address2','city','state','zip','phone','mobile','fax' );
	for( i=0; i<cols.length; i++ )
	{
		var col = cols[i];
		var src = document.getElementById( sourcePrefix + col );
		var dest = document.getElementById( destPrefix + col );
		if( src && dest )
			dest.value = src.value;
	}
}

function sameasClick(  )
{
	if( document.getElementById('sameas_billing').checked )
		document.getElementById('billing_fields').style.display='none';
	else
		document.getElementById('billing_fields').style.display='block';
		
	if( document.getElementById('sameas_artwork').checked )
		document.getElementById('artwork_fields').style.display='none';
	else
		document.getElementById('artwork_fields').style.display='block';
	
}

function validate(  )
{
	if( !document.getElementById('agree').checked )
	{
		alert( "Please agree to the Terms and Conditions before continuing." );
		return false;
	}
	
	return true;
}

function  test_function() {
	alert("Successful.");
}
