// JavaScript Document

function checkDelete(iid, cms){
	
	if (cms=="dis_interGroup")
		var b = (confirm('Deleting this category will delete all details within it.  Are you sure?'));
	else
		var b= confirm('Are you sure you wish to delete?');


	if(b && cms=="award"){		
		window.location = "../editor/edit_winery_awards.php?action=delete&id="+iid; 
	}
	if(b && cms=="wevent"){		
		window.location = "../editor/edit_winery_events.php?action=delete&id="+iid; 
	}
	if(b && cms=="dis_can"){		
		window.location = "../editor/edit_dis_canada.php?action=delete&id="+iid; 
	}	
	if(b && cms=="ievent"){		
		window.location = "../editor/edit_island_events.php?action=delete&id="+iid; 
	}
	if(b && cms=="contact"){		
		window.location = "../editor/edit_contacts.php?action=delete&id="+iid; 
	}
	if(b && cms=="link"){		
		window.location = "../editor/edit_winery_links.php?action=delete&id="+iid; 
	}
	if(b && cms=="wine"){		
		window.location = "../editor/edit_wines.php?action=delete&id="+iid; 
	}
	if(b && cms=="gift"){		
		window.location = "../editor/edit_gifts.php?action=delete&id="+iid; 
	}

	if(b && cms=="news"){		
		window.location = "../editor/edit_newsletters.php?action=delete&id="+iid; 
	}

	if(b && cms=="labelsimg"){		
		window.location = "../editor/edit_labels.php?action=deleteimg&id="+iid; 
	}

	if(b && cms=="dis_inter"){		
		window.location = "../editor/edit_dis_inter.php?action=delete&id="+iid; 
	}

	if(b && cms=="dis_interGroup"){		
		//alert ("../editor/edit_dis_interGroup.php?action=delete&id="+iid);
		window.location = "../editor/edit_dis_interGroup.php?action=delete&id="+iid; 
	}
	if(b && cms=="whatsnew"){		
		window.location = "../editor/edit_whats_new.php?action=delete&id="+iid; 
	}
}

function checkDeleteEvent(eventid){
	var b= confirm('Are you sure you wish to delete this event?');

	if(b){		
		window.location = "../editor/deletewineryevent.php?id="+eventid; 
	}
}

function updateallcart(cnt){
	while(cnt>0){
		var form = "update"+cnt;
		eval("document."+form+".submit();");
		cnt = cnt-1; 
	}
}

function checkFields(){
	if (document.checkoutform.same.checked){
		//shipping and billing info is the same; check only shipping is all filled in
		if(document.checkoutform.sfn.value==''|| 
		document.checkoutform.saddr.value=='' || 
		document.checkoutform.scity.value=='' || 			
		document.checkoutform.sprov.value=='' || 
		document.checkoutform.scountry.value=='' || 
		document.checkoutform.spostal.value=='' || 
		document.checkoutform.sphone.value=='' || 	
		document.checkoutform.semail.value=='' || 	
		document.checkoutform.cname.value=='' || 	
		document.checkoutform.cpay.value=='' || 	
		document.checkoutform.cnumber.value=='' || 	
		document.checkoutform.cmonth.value=='' || 	
		document.checkoutform.cyear.value=='' ){
			alert("Please enter all fields.");	
		} else {
			document.checkoutform.action='checkCheckout.php';
			document.checkoutform.submit();
		}
	} else {
		//shipping and billing need to be filled in 
		if(document.checkoutform.sfn.value==''|| 
			document.checkoutform.saddr.value=='' || 
			document.checkoutform.scity.value=='' || 			
			document.checkoutform.sprov.value=='' || 
			document.checkoutform.scountry.value=='' || 
			document.checkoutform.spostal.value=='' || 
			document.checkoutform.sphone.value=='' || 	
			document.checkoutform.semail.value=='' || 	
			document.checkoutform.bfn.value=='' || 	
			document.checkoutform.bln.value=='' || 	
			document.checkoutform.baddr.value=='' || 	
			document.checkoutform.bcity.value=='' || 	
			document.checkoutform.bprov.value=='' || 	
			document.checkoutform.bcountry.value=='' || 	
			document.checkoutform.bpostal.value=='' || 	
			document.checkoutform.bphone.value=='' || 	
			document.checkoutform.bemail.value=='' || 	
			document.checkoutform.cname.value=='' || 	
			document.checkoutform.cpay.value=='' || 	
			document.checkoutform.cnumber.value=='' || 	
			document.checkoutform.cmonth.value=='' || 	
			document.checkoutform.cyear.value=='' ){
				alert("Please enter all fields.");	
				} else {
					document.checkoutform.action='checkCheckout.php';
					document.checkoutform.submit();
				}
		}

}

function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}


//Shop Cart Ajax


			
			
	
