
/*-------------------------------------------------
Validation Functions
-------------------------------------------------*/
function openWindow(page, win) {
	OpenWin = window.open(page, win, "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=620,height=400");
	if (parseInt(navigator.appVersion) >= 4) { OpenWin.window.focus(); }
}

function openWindow2(page, win) {
	OpenWin = window.open(page, win, "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=320,height=400");
	if (parseInt(navigator.appVersion) >= 4) { OpenWin.window.focus(); }
}


function validateQuantity(quantity, minimum, packsize) {
	
	if (quantity < minimum) {
		alert("The minimum order for this product is " + minimum + ".\nPlease enter a larger quantity.");
		return false;
	}	
	
 else if (quantity % packsize != 0) {
		// trace(Math.floor(quantity % packsize));
		var suggestion =  quantity - (quantity % packsize) + packsize;
		alert("The quantity that has been entered is not a multiple of the pack size. If you require a minumum of " + quantity + ", you should order a total quanity of " + suggestion + ".");
		return false;
	}
	
	else {
		 
		 return true;
		 
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

// Object convert
// http://snook.ca/archives/javascript/testing_for_a_v
function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}

function updateShipping(postcode, shoppingbagtotalpreshipping){
	//if((postcode >= 3000) && (postcode <= 3210)) {
  if( postcode in oc(['3000', '3001', '3002', '3003', '3004', '3005', '3006', '3008', '3010', '3011', '3012', '3013', '3015', '3016', '3018', '3019', '3020', '3021', '3022', '3023', '3024', '3025', '3026', '3028', '3029', '3030', '3031', '3032', '3033', '3034', '3036', '3038', '3039', '3040', '3041', '3042', '3043', '3044', '3045', '3046', '3047', '3048', '3049', '3050', '3051', '3052', '3053', '3054', '3055', '3056', '3057', '3058', '3060', '3061', '3062', '3064', '3065', '3066', '3067', '3068', '3070', '3071', '3072', '3073', '3074', '3075', '3076', '3078', '3079', '3081', '3082', '3083', '3084', '3085', '3086', '3087', '3088', '3093', '3094', '3095', '3097', '3101', '3102', '3103', '3104', '3105', '3106', '3107', '3108', '3109', '3110', '3111', '3121', '3122', '3123', '3124', '3125', '3126', '3127', '3128', '3129', '3130', '3131', '3132', '3133', '3134', '3135', '3136', '3137', '3138', '3141', '3142', '3143', '3144', '3145', '3146', '3147', '3148', '3149', '3150', '3151', '3152', '3153', '3154', '3155', '3156', '3161', '3162', '3163', '3164', '3165', '3166', '3167', '3168', '3169', '3170', '3171', '3172', '3173', '3174', '3175', '3176', '3177', '3178', '3179', '3180', '3181', '3182', '3183', '3184', '3185', '3186', '3187', '3188', '3189', '3190', '3191', '3192', '3193', '3194', '3195', '3196', '3197', '3198', '3199', '3200', '3201', '3202', '3204', '3205', '3206', '3207', '3753', '3770', '3800', '3802', '3803', '3804', '3805', '3806', '3807', '3920', '3976', '3977']) ) {
		shoppingbagtotalexgst = shoppingbagtotalpreshipping + 10;
		shoppingbaggsttotal = shoppingbagtotalexgst * 0.1;
		shoppingbagtotalincgst = shoppingbagtotalexgst * 1.1
		document.getElementById('shippingprice').innerHTML = "$10.00";
		document.getElementById('shoppingbaggsttotal').innerHTML = "$" + roundNumber(shoppingbaggsttotal,2);
		document.getElementById('shoppingbagtotal').innerHTML = "$" + roundNumber(shoppingbagtotalincgst,2);
		
	} else {
		shoppingbagtotalexgst = shoppingbagtotalpreshipping + 20;
		shoppingbaggsttotal = shoppingbagtotalexgst * 0.1;
		shoppingbagtotalincgst = shoppingbagtotalexgst * 1.1
		document.getElementById('shippingprice').innerHTML = "$20.00";
		document.getElementById('shoppingbaggsttotal').innerHTML = "$" + roundNumber(shoppingbaggsttotal,2);
		document.getElementById('shoppingbagtotal').innerHTML = "$" + roundNumber(shoppingbagtotalincgst,2);
		
	}
}


// Copy delivery address to billing address
function CopyDeliveryAddress(form) {
  if (form.copy.checked) {
    form.ad1.value = form.dad1.value;
    form.ad2.value = form.dad2.value;
    form.sub.value = form.dsub.value;
		form.pco.value = form.dpco.value;
    form.sta.selectedIndex = form.dsta.selectedIndex;
    form.cou.selectedIndex = form.dcou.selectedIndex;
  } 
}

function enterTextArea(el) {	
  if (el.value == 'Please enter the details of the required artwork.  We will contact you by phone and/or email to confirm specs and artwork.') {
	  el.value='';
	}
	el.setStyles({ 'height': '100px',  'color': '#000000' });
}
	
function exitTextArea(el) {
	if (el.value == '') {
	  el.value = 'Please enter the details of the required artwork.  We will contact you by phone and/or email to confirm specs and artwork.';
		el.setStyles({ 'height': '40px', 'color': '#666666' })
	} else {
		el.setStyles({ 'color': '#000000' })
	}
}

// Object convert
// http://snook.ca/archives/javascript/testing_for_a_v
function oc(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}



// Show Payment Method options
function PaymentMethod(form) {
  if (document.getElementById('vpc_card').value == "account") {
	  
		document.getElementById('vpc_CardNum_label').style.display = '';
		document.getElementById('vpc_CardNum_field').style.display = 'none';
		document.getElementById('con_field').style.display = '';
		document.getElementById('vpc_CardNum_label').innerHTML = 'PO Number*';
		
		document.getElementById('vpc_name_label').style.display = 'none';
		document.getElementById('vpc_name_field').style.display = 'none';
		
		document.getElementById('vpc_cardExp_month_label').style.display = 'none';
		document.getElementById('vpc_cardExp_month_field').style.display = 'none';
		
		document.getElementById('vpc_CardSecurityCode_label').style.display = 'none';
		document.getElementById('vpc_CardSecurityCode_field').style.display = 'none';
		
		alert('The Ezitag office will issue you with an invoice for this order.  Payment will be required prior to production of goods and shipment of this order.  Please ensure your contacts details are correct and contact the Ezitag office by phone if you do not receive the invoice within 3 working days.');
	
	} else  if (document.getElementById('vpc_card').value == "eft") {
	  
		document.getElementById('vpc_CardNum_label').style.display = 'none';
		document.getElementById('con_field').style.display = 'none';
		document.getElementById('vpc_CardNum_field').innerHTML = "Deposit funds in account:<br>Ezitag Systems Pty Ltd";
		
		document.getElementById('vpc_name_label').style.display = 'none';
		document.getElementById('vpc_name_field').innerHTML = " BSB:063 182<br>Acc No: 1016 338";
		
		document.getElementById('vpc_cardExp_month_label').style.display = 'none';
		document.getElementById('vpc_cardExp_month_field').style.display = 'none';
		
		document.getElementById('vpc_CardSecurityCode_label').style.display = 'none';
		document.getElementById('vpc_CardSecurityCode_field').style.display = 'none';
		
		alert('Please make an electronic funds tranfer to Ezitag Systems Pty Ltd (BSB:063 182. Acc No: 1016 3385).  Enter the order number with your eft.  You will be issued with this order number upon submission of this web order.');
		
	} else {
		
		document.getElementById('vpc_CardNum_label').style.display = '';
		document.getElementById('vpc_CardNum_field').style.display = '';
		document.getElementById('con_field').style.display = 'none';
		document.getElementById('vpc_CardNum_label').innerHTML = 'Card Number*';
		document.getElementById('vpc_CardNum_field').innerHTML = '<input name="vpc_CardNum" type="text" size="20" tabindex="2" class="textfield" value="">';
	
		document.getElementById('vpc_name_label').style.display = '';
		document.getElementById('vpc_name_field').style.display = '';
		document.getElementById('vpc_name_field').innerHTML = '<input name="vpc_name" type="text" size="20" tabindex="2"  class="textfield" value="">';
		
		document.getElementById('vpc_cardExp_month_label').style.display = '';
		document.getElementById('vpc_cardExp_month_field').style.display = '';
		
		document.getElementById('vpc_CardSecurityCode_label').style.display = 'block';
		document.getElementById('vpc_CardSecurityCode_field').style.display = '';
		
	}

}


/*-------------------------------------------------
Product Page animation
-------------------------------------------------*/
function pageAnimation() {
	
	var animation = new Chain();
	
	var pageAnimation = function(){
		$$('#fadecontent').each(function(el){el.get('tween', {property: 'opacity', duration: 500, transition: Fx.Transitions.Quint.easeIn}).start(0,1)});
	};
	
animation.chain(pageAnimation);
	animation.callChain(); // fade in
	animation.callChain.delay(500, animation);
}





/*-------------------------------------------------
Domready events
-------------------------------------------------*/

window.addEvent('domready',function() {
																		
	// Link hover	
	$each($$('#navigation li a'), function(el) {
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color': '#6699cc' }) },
			'mouseleave' : function() { morph.start({ 'color': original }) }
		});
	});
	
	// Link hover	
	$each($$('.productcategory', '.productsubcategory'), function(el) {
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color': '#FFF'}) },
			'mouseleave' : function() { morph.start({ 'color': original }) }
		});
	});
	
	// Link hover	
	$each($$('.footerlink'), function(el) {
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color': '#990000'}) },
			'mouseleave' : function() { morph.start({ 'color': original }) }
		});
	});
	
	// Link button hover	
	$each($$('.linkbutton', '.linkbuttonsmall', '.linkbuttonleft'), function(el) {
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color': '#b1d2e1'}) },
			'mouseleave' : function() { morph.start({ 'color': original}) }
		});
	});

	// Link button hover	
	$each($$('.featuretext', '.featureimage'), function(el) {
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'500', link:'cancel' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'background-color': '#17405e'}) },
			'mouseleave' : function() { morph.start({ 'background-color': '#20668e'}) }
		});
	});

	
});
	
