
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fncLoad() {
	preloadImages('/img/bg/bg_insideleft.gif','/img/bg/bg_insideright.gif','/img/bg/bg_account.gif','/img/bg/bg_inside_listleft.gif','/img/bg/bg_inside_listright.gif','/img/bg/bg_login.gif','/img/bg/bg_lower_leftside.gif','/img/bg/bg_lowerright.gif','/img/bg/bg_pricing-leftedge.gif','/img/bg/bg_pricing-rightedge.gif','/img/bg/bg_rightside.gif','/img/bg/bg_slide_rightedge.gif')
}

// REMOVE IE LINK BOX //

function CSRemoveIEbox(){
if (document.images&&navigator.userAgent.indexOf("MSIE")!=-1){
	for(i=0;i<document.links.length;i++){
		target=eval("document.links[i]")
		target.onfocus=blurHandler
		}
	}
}

function blurHandler(){
obj=window.event.srcElement
if(obj.tagName == "A"||obj.tagName=="AREA") obj.blur()
}

//require fields in a form and redirect to url
function fncSubmit(obj,url) {
	var req = obj.required_fields;
	var submitflag = true;
	var notice = "Some of the required fields are blank:\n\n";
	if (req) {
		//Means the required fields are present, let's check for values
		var arrFields = obj.required_fields.value.split("|")
		for(var x=0; x<=arrFields.length-1; x++) {
			var arrName = arrFields[x].split(",");
			arrLabel=arrName[0];
			
			if (obj.elements[arrLabel]){
				var str = "if (obj."+arrName[0]+".value == '') { notice += '-->  "+arrName[1]+"\\n'; submitflag = false;}";
				eval(str);
			}
    }
		notice += "\nPlease fill in these fields and resubmit!";
	} else {
		//Means there isn't a required fields parameter; keep going
	}
	if (submitflag) {
		
		obj.action = url;
		obj.submit();
	} else {
		alert(notice);
	}
}

function fncCenteredChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=no')
}

function doAction(obj,url){
	obj.action = url;
	obj.submit();
}


/*	CarryOn specific functions		*/

//this function changes the background styles for the choose your package screen


/*********				Account Login					************/
function accountLogin(){
	document.frmLB.submit();
}

/***********			Account Functions				*************/
function submitAccountInfoForm(){					//account information change form
	document.infoForm.submit();
}

function submitPasswordForm(){
	document.passwordForm.submit();
}

function submitTripInfo(){					//trip planner info form
	document.tripInfo.submit();
}

function updateDestForm(obj){
	id = obj.value;
	url = '/account/ajax.php?m=dest&id='+id;
	loadFragmentInToElement(url, 'destination');
}

function submitSelectItem(){
	document.selectItem.submit();
}

function itemToggle(id,type) { 
   var element = document.getElementById('item_'+id);
	if(type=='add'){
		var fragment_url = '/account/ajax.php?m=add_item&id='+id
	}else{
		var fragment_url = '/account/ajax.php?m=remove_item&id='+id
	}
    element.innerHTML = '<img src="/img/spacer.gif" height="125" width="110" />';
    xmlhttp.open("GET", fragment_url); 
    xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      element.innerHTML = xmlhttp.responseText; 
      
      //document.getElementById('loadInfo').innerHTML = '....'; 
		
		//refresh selected items div
		loadFragmentInToElement('/account/ajax.php?m=refresh_items','selected_items');
      } 
    } 
    
	xmlhttp.send(null);
}

function confirmTripPlanner(){
	var chk = document.getElementById('termsAgreement');
	if(chk.checked){
		window.location='index.php?m=plan_trip&tpm=save_trip';
	}else{
		alert('You must agree to the terms and conditions outlined on this website before continuing.');
	}
}

function show(id,tlink,text){
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById(tlink);
		el.innerHTML = 'hide '+text;
	} else {
		el.style.display = 'none';
		el = document.getElementById(tlink);
		el.innerHTML = 'show '+text;
	}
}

function submitOnlineStore(){
	document.onlineStore.submit();
}

//trip edit forms
function submitDestEdit(){
	document.tripInfo.submit();
}
function submitItemEdit(){
	document.itemEdit.submit();
}

function itemEditToggle(id,type) { 
   var element = document.getElementById('item_'+id);
	if(type=='add'){
		var fragment_url = '/account/ajax.php?m=add_item_edit&id='+id
	}else{
		var fragment_url = '/account/ajax.php?m=remove_item_edit&id='+id
	}
    element.innerHTML = '<img src="/img/spacer.gif" height="125" width="110" />';
    xmlhttp.open("GET", fragment_url); 
    xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      element.innerHTML = xmlhttp.responseText; 
      
      //document.getElementById('loadInfo').innerHTML = '....'; 
		
		//refresh selected items div
		loadFragmentInToElement('/account/ajax.php?m=refresh_items_edit','selected_items');
      } 
    } 
    
	xmlhttp.send(null);
}

function submitStoreEdit(){
	document.storeEdit.submit();
}
function submitItemEditForm(){
	document.itemEdit.submit();
}
/***********			Registration Functions			*************/
function packageSelect(type){
	//declare all the elements we need to change
	var rh = document.getElementById('request_header');
	var rc = document.getElementById('request_cell');
	var sh = document.getElementById('send_header');
	var sc = document.getElementById('send_cell');
	
	if(type=='send'){
		//person is sending their own boxes
		rh.className='request-not';
		rc.className='choose-not';
		sh.className='send-selected';
		sc.className='choose-yes';
	}else{
		//person is requesting boxes be sent
		rh.className='request-selected';
		rc.className='choose-yes';
		sh.className='send-not';
		sc.className='choose-not';
	}
}

function submitPackageChoice(){
	document.packaging.submit();
}

function submitAddNewCarton(){
	document.addNew.submit();
}

function submitLabelCarton(){
	document.addLabeled.submit();
}

function submitTaggedCartons(){
	check = document.getElementById('no-illegal');
	if(check.checked==true){
		document.submitCartons.submit();
	}else{
		alert('You must certify that you are not sending illegal substances or firearms.');
	}
}

function submitStorage(){
	check = document.getElementById('no-illegal');
	if(check.checked==true){
		document.storing.submit();
	}else{
		alert('You must certify that you are not sending illegal substances or firearms.');
	}
}

function storageSelect(type){
	//declare all the elements we need to change
	var i = document.getElementById('request_cell');
	var ih = document.getElementById('stortop_sel');
	var c = document.getElementById('send_cell');
	var ch = document.getElementById('stortop-not_sel');
	
	if(type==0){
		//person is sending their own boxes
		i.className='choose-not';
		ih.className='stortop-not_sel';
		c.className='choose-yes';
		ch.className='storetop_sel';
		
	}else{
		//person is requesting boxes be sent
		i.className='choose-yes';
		ih.className='storetop_sel';
		c.className='choose-not';
		ch.className='stortop-not_sel';
	}
}
function submitInfoForm(){
	document.information.submit();
}

function submitBillingForm(){
	document.billing.submit();
}