//

$(document).ready(function() {
});

var r={
 'special':/[\W]/g,
 'quotes':/['\''&'\"']/g,
 'notnumbers':/[^\d]/g
}

function valid(o,w){
 o.value = o.value.replace(r[w],'');
}
function jumpto(obj, gotoBox){
	valid(obj,'notnumbers');
	if(obj.value.length==4){
		document.getElementById(gotoBox).focus();
	}	
}


function validate_payment_info(obj){
	chk = $('#shipping_missing').val();
	if(chk=='1'){
		alert('Please add shipping information');
		return false;
		}
	}
function hideElement(eid){
	$('#'+eid).css('display','none');
	}
function showElement(eid){
	$('#'+eid).css('display','block');
	}

function isEmailAvailable(email){
	$.ajax({
	   type: "GET",
	   url: "index.php?m=ajax&f=register_validate",
	   data: "email="+email+'&rand='+Math.random(),
	   
	   success: function(data){
	
		  if(data=='invalid'){
			  $('#msg-email').html('Invalid Email Address');
			  }
		  else 
		  if(data=='yes'){
			  $('#msg-email').html('Available as user id');
			  }
		  else 
		  if(data=='no'){
			  $('#msg-email').html('Email address already registered');
			  }
	   }
	 });
}

function editShipInfo(){
	$.ajax({
	   type: "GET",
	   url: "index.php?m=user&f=editBillingInfoMini",
	   data: 'rand='+Math.random(),
	   
	   success: function(data){
		   $('#billInfoSection').html(data);
		   $('#billInfoSection').css('display','block');

	   }
	 });
}

function cancelEditShipInfo(){
	$('#billInfoSection').html('');
	$('#billInfoSection').css('display','none');
}

function changeImage(direction){
	current_img		= document.getElementById('imagenum');
	bookpage_obj	= document.getElementById('bookpage');
	current_img_num	= parseInt(current_img.value);
	if(direction=='n'){
		if(current_img_num==24){
			alert('You are at the last page of preview');
			return false;
		}
		newPageNum = current_img_num+1;
		current_img.value = newPageNum;
		bookpage_obj.src = './images/book/page'+newPageNum+'.png';
	}
	else if(direction=='p'){
		if(current_img_num==1){
			alert('You are at the first page');
			return false;
		}
		newPageNum = current_img_num-1;
		current_img.value = newPageNum;
		bookpage_obj.src = './images/book/page'+newPageNum+'.png';
	}
	return false;
	}

var newwindow;
function miniwindow(url,w,h)
{
	newwindow=window.open(url,'name','scrollbars=yes,height='+h+',width='+w);
	if (window.focus) {newwindow.focus()}
}

function updateStates(obj){
	countryId = obj.value;
	if(countryId==223){
		showElement('states-us');
		hideElement('states-ca');
		hideElement('states');
		}
	else if(countryId==38){
		showElement('states-ca');
		hideElement('states-us');
		hideElement('states');
		}
	else {
		showElement('states');
		hideElement('states-us');
		hideElement('states-ca');
		}
	
	}

function updateStates2(obj){
	countryId = obj.value;
	if(countryId==223){
		showElement('ship_to_states-us');
		hideElement('ship_to_states-ca');
		hideElement('ship_to_states');
		}
	else if(countryId==38){
		showElement('ship_to_states-ca');
		hideElement('ship_to_states-us');
		hideElement('ship_to_states');
		}
	else {
		showElement('ship_to_states');
		hideElement('ship_to_states-us');
		hideElement('ship_to_states-ca');
		}
	
	}

function shipInfoToggle(){
	if($('#ship-to-info').css('display')=='block'){
		$('#ship-to-info').css('display','none')
		}
	else {
		$('#ship-to-info').css('display','block')
		}
	}

function changeOfficeImage(obj,imageSrc){
	obj.src = imageSrc;
	}