function showLargeImage(num){
	for(var i=1;i<9;i++){
			$('.largediv' + i).hide();
		}
		$('.largediv' + num).show();
}	
function checkterms(){
	if(!document.getElementById('terms').checked){			
		alert("Please agree to our terms and conditions");
		return false;
	}else {
		if($('#aboutus').val()!=0){ 
			var aboutus='';
			if($('#aboutus').val()!='other'){
				aboutus=$('#aboutus').val();
			}else{
				aboutus=$('#otheraboutus').val();
			}
			$.get('/courses/storeaboutus.php', {aboutus:aboutus});
		}
		return true;
	}
}
function CopyShippingToBilling(){
	var billing= document.getElementById("billingaddress");
	var shipping= document.getElementById("shippingaddress");
	var billingcode= document.getElementById("billingpostcode");
	var shippingcode= document.getElementById("shippingpostcode");
	shipping.value=billing.value;
	shippingcode.value=billingcode.value;
}
function productInfoSetup(){	
	$('.productlargeimage').show();
	for(var i=2;i<9;i++){
		$('.largediv' + i).hide();
	}	
	for(var i=1;i<5;i++){
		$('.print' + i).hide();
	}	
}
function archiverequest(id){
	document.location='/support/sendtoarchive.php?id=' + id;
}
function clearsearch(){
	$('#searchbox').val('');
	$('#searchbox').css('color','black');
}
function addpost(){
	$('#forumpost').show();
	return false;
}
function checkcountry(){	
	if($('#countrylist').val()==1){
		document.location='changedelivery.php?id=1&c='+$('#countrylist').val();
	}else if($('#countrylist').val()==2){
		document.location='changedelivery.php?id=2&c='+$('#countrylist').val();
	}else{
		document.location='changedelivery.php?id=3&c='+$('#countrylist').val();
	}
}
function checkcountry2(){	
	if($('#countrylist').val()==1){
		document.location='changedelivery2.php?id=1&c='+$('#countrylist').val();
	}else if($('#countrylist').val()==2){
		document.location='changedelivery2.php?id=2&c='+$('#countrylist').val();
	}else{
		document.location='changedelivery2.php?id=3&c='+$('#countrylist').val();
	}
}
function outlyingdelivery(i){	
	if(i==1)document.location='changedeliveryol.php?id=1&c=1';	
	if(i==3)document.location='changedeliveryol.php?id=3&c=3';
}
function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}
function vidlinkhover(thisorder,mainorder,courseid){
	$('.vids').css('background', 'white');
	$('#vid'+mainorder).css('background', '#EC008B');
	$('#vid'+thisorder).css('background', '#F9B3DC');	
}
function vidlinkhoverout(thisorder,mainorder,courseid){	
	$('#vid'+thisorder).css('background', 'white');	
	$('#vid'+mainorder).css('background', '#EC008B');
}
function updatevideo(id,videonum){
	var loc='videodisplay.php?id='+id+'&videonum='+videonum;
	document.location=loc;
}
function updatevideoprev(id,videonum){
	var loc='how_ecourses_work1.php?id='+id+'&videonum='+videonum;
	document.location=loc;
}
function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function editaddress(){
	var id=$('#addresses').val();
	document.location='editaddress.php?id='+id;
}
var newimgcount=1;
function newimage(){
	if(newimgcount<=20){
	$('#newimages').append('<div style="width:40%;padding:10px;margin-left:100px"><fieldset style="padding:10px 20px"><h3 style="max-width:65%">Additional Image '+newimgcount+'</h3><br /><input type="file" id="newimage'+newimgcount+'" name="newimage'+newimgcount+'" /><p>Description: <br /><textarea name="newdescription'+newimgcount+'" cols="25" rows="5"></textarea></p></fieldset></div>');}	
	newimgcount++;	
	window.scrollTo(0,999999);
	return false;
}
function clear_output(){
	$('#output_sq_feet').val('');
	$('#output_sq_meters').val('');
	$('#product_price').val('');
}
function calculate_area(type){
	var t_length = parseFloat(document.area.input_length.value);
	var t_width = parseFloat(document.area.input_width.value);
	
	if ((t_length <= 0) || (isNaN(t_length))) {t_length = 1;}
	if ((t_width <= 0) || (isNaN(t_width))) {t_width = 1;}
	
	document.area.input_length.value = t_length;
	document.area.input_width.value = t_width;
	var material=$('#material').val();
	var laminating=$('#laminating').val();
	if(!laminating)laminating=0;
	if(!material)material=0;
	if (t_length >1.55){  
		alert("Height of "+type+" selected larger than 1.55 metres - please contact us on 0191 268 4001 for a quotation");
		return false;
	}else{
		var resultm=(t_length * t_width);
		var vartotal=(resultm*material)+(resultm*laminating);
		$('#output_sq_meters').val(resultm);
		$('#dimen').val('Size: ' +t_width+ 'W X ' + t_length + 'H');
		$('#uidDimen').val('Size: ' +t_width+ 'W X ' + t_length + 'H');
		var outputval=$('#output_sq_meters').val(); 
		if (outputval <=1.3) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (29 + 2.9) +vartotal)));
		if (outputval <=1.3) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (29 + 2.9) +vartotal)));
		if (outputval >1.3) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (25.5 + 2.55) +vartotal)));
		if (outputval >1.3) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (25.5 + 2.55) +vartotal)));	
		if (outputval >2) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (21.5 + 2.15) +vartotal)));
		if (outputval >2) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (21.5 + 2.15) +vartotal)));	
		if (outputval >2.49999) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (21 + 2.1) +vartotal))); 
		if (outputval >2.49999) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (21 + 2.1) +vartotal))); 
		if (outputval >3) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (20.5 + 2.05) +vartotal)));
		if (outputval >3) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (20.5 + 2.05) +vartotal)));
		if (outputval >3.49999) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (19 + 1.9) +vartotal)));
		if (outputval >3.49999) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (19 + 1.9) +vartotal)));
		if (outputval >4.99999) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (18 + 1.8) +vartotal)));
		if (outputval >4.99999) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (18 + 1.8) +vartotal)));
		if (outputval >7.9999) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (17 + 1.7) +vartotal)));
		if (outputval >7.9999) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (17 + 1.7) +vartotal)));
		if (outputval >9.99999) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (16.66 + 1.666) +vartotal)));
		if (outputval >9.99999) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (16.66 + 1.666) +vartotal)));
		$('#addtobasket').show();
		return true;
		//alert($('#output_sq_meters').val() + ' '+t_length +' ' + t_width + ' ' +$('#output_sq_feet').val());		 
	}	
}
function calculate_area_home(){
	if(calculate_area('banner')){
		var width=parseFloat(document.area.input_width.value);
		var height=parseFloat(document.area.input_length.value);
		var quantity=$('#qty').val();
		var total=$('#output_sq_feet').val();
		document.location="http://www.monkey-print.com/index.php?route=product/product&product_id=62&width="+width+"&height="+height+"&quantity="+quantity+"&total="+total;
	}
}
function calculate_area2(type){
	var t_length = parseFloat(document.area.input_length.value);
	var t_width = parseFloat(document.area.input_width.value);
	
	if ((t_length <= 0) || (isNaN(t_length))) {t_length = 1;}
	if ((t_width <= 0) || (isNaN(t_width))) {t_width = 1;}
	
	document.area.input_length.value = t_length;
	document.area.input_width.value = t_width;
	var material=$('#material').val();
	var laminating=$('#laminating').val();
	var extralam=0;
	var extramat=0;
	if(!laminating)laminating=0;
	if(!material)material=0;
	if(laminating>0)extralam=2;
	if(material>0)extramat=2;
	if (t_length >1.55){  
		alert("Height of "+type+" selected larger than 1.55 metres - please contact us on 0191 268 4001 for a quotation");
	}else{
		var resultm=(t_length * t_width);
		var vartotal=(resultm*material)+(resultm*laminating);
		vartotal+=extralam+extramat;
		$('#dimen').val('Size: ' +t_width+ 'W X ' + t_length + 'H');
		$('#output_sq_meters').val(resultm);
		var outputval=$('#output_sq_meters').val(); 
		if (outputval <=0.49) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (29 + 2.9) +vartotal)));
		if (outputval <=0.49) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (29 + 2.9) +vartotal)));
		if (outputval >=0.491) $('#output_sq_feet').val(CurrencyFormatted(Math.round((resultm) * (19.2 + 1.92) +vartotal)));
		if (outputval >=0.491) $('#product_price').val(CurrencyFormatted(Math.round((resultm) * (19.2 + 1.92) +vartotal)));
		$('#addtobasket').show();
		//alert($('#output_sq_meters').val() + ' '+t_length +' ' + t_width + ' ' +$('#output_sq_feet').val());		 
	}	
}
var imgi=2
function changeimage(){
	setTimeout(updateimage, 4000);		
}
function updateimage(){
	$('#hidden').attr('src','monkeyimages/img'+imgi+'.jpg'); 
	$('#area').fadeOut(800, function() { 	
		$('#img1').attr('src','monkeyimages/img'+imgi+'.jpg'); 
	}).fadeIn(1200,function(){
		$('#hidden').attr('src',''); 
		if(++imgi==5)imgi=1;
		setTimeout(updateimage, 4000);
	});
	
}
function checkselectedo(){
	var selectedo=$('#selectedo').val();
	for(i=0;i<selectedo;i++){
		if($('.selectedo'+i).val()==1000)	{
			$('#selectalert').html("You must select all available options");
			return false;
		}
	}
	return true;
}
function updateQty(){
var qty = parseFloat(document.area.qty.value);
$('#quantity').val(qty);
}
