function prodImgBig(pid, file) {
	if (currentImage != file) {
		$('#prod_img_in').fadeOut('fast',
			function() {
				$('#prod_img_in').html('<a href="/pimages/'+pid+'/zoom/'+file+'" class="lightbox"><img src="/pimages/'+pid+'/big/'+file+'" id="img_16" alt="" /></a>').fadeIn('fast');
				currentImage = file;
				$("a.lightbox").lightbox();
			}
		);
	}
}

function addToBasket(pid) {
	$('#prod_addToBag').show('slow');
	
	var params = {
		act: 'add_to_basket',
		p_id: pid
	};
	$.ajax({
		type: "POST",
		url: "/ajax.php",
		data: params,
		dataType: "xml",
		success: function(msg) {
			response = msg.getElementsByTagName("data")[0].firstChild.nodeValue;
			if (response == 1) {
				//update basket items counter in header
				$('#bsketItems').html($('#bsketItems').html()*1+1);
				//show that the item was added to basket
				$('#prod_addToBag').html('Product added. Thank you!');
			}
		}
	});
}

function newsletter_add() {
	var params = {
		act: 'newsletter',
		email: $('#newsletter_field').val()
	};
	$.ajax({
		type: "POST",
		url: "/ajax.php",
		data: params,
		dataType: "xml",
		success: function(msg) {
			$('#newsletter_field').val(msg.getElementsByTagName("data")[0].firstChild.data);
		}
	});
}

function shipp_add(elm) {
	$('#shipaddr_form').css('display', 'block');
	
	if (elm == 1) {
		$('#shiptitle').val($('#title').val());
		$('#shipfname').val($('#fname').val());
		$('#shiplname').val($('#lname').val());
		$('#shipcountry').val($('#country').val());
		$('#shippcode').val($('#pcode').val());
		$('#shipadd1').val($('#add1').val());
		$('#shipadd2').val($('#add2').val());
		$('#shipadd3').val($('#add3').val());
		$('#shiptown').val($('#town').val());

		if ($('#delivery').val() == '1') {
			deliv_charge('s');
		} else if($('#delivery').val() == '2') {
			deliv_charge('e');
		}
	} else {
		$('#shiptitle').val('Select');
		$('#shipfname').val('');
		$('#shiplname').val('');
		$('#shipcountry').val('Select');
		$('#shippcode').val('');
		$('#shipadd1').val('');
		$('#shipadd2').val('');
		$('#shipadd3').val('');
		$('#shiptown').val('');
		
		deliv_charge();
	}
}

function parseFloatNum(num) {
	num = num+'';
	if (num.lastIndexOf(".") == num.length-2) {
		num = num+'0';
	}
	
	return num;
}

function chkout1() {
	var comm = "";
	if ($('#fname').val() == "" || $('#lname').val() == "") {
		comm += 'Your first nad last name\n';
	}
	if ($('#country').val() == "" || $('#country').val() == "Select") {
		comm += 'Your country of origin\n';
	}
	if ($('#pcode').val() == "") {
		comm += 'Your postcode\n';
	}
	if ($('#add1').val() == "") {
		comm += 'Your address\n';
	}
	if ($('#town').val() == "") {
		comm += 'Your town\n';
	}
	if ($('#phone').val() == "") {
		comm += 'Your telephone\n';
	}
	if ($('#email').val() == "") {
		comm += 'Email address\n';
	} else {
		var str = $('#email').val();
		if ((str.lastIndexOf(".") > str.indexOf("@") && str.indexOf("@") > 0) == false) {
			comm += 'Email address\n';
		}
	}
	
	if ($('#shipaddr_form').css('display') == "block") {
		if ($('#shiptitle').val() == "" || $('#shiptitle').val() == "Select") {
			comm += 'Receiver title\n';
		}
		if ($('#shipfname').val() == "" || $('#shiplname').val() == "") {
			comm += 'Receiver first nad last name\n';
		}
		if ($('#shipcountry').val() == "" || $('#shipcountry').val() == "Select") {
			comm += 'Shipping country\n';
		}
		if ($('#shippcode').val() == "") {
			comm += 'Shipping postcode\n';
		}
		if ($('#shipadd1').val() == "") {
			comm += 'Shipping address\n';
		}
		if ($('#shiptown').val() == "") {
			comm += 'Shipping town\n';
		}
	} else {
		comm += 'Ship to\n';
	}
	
	if (comm.length == 0) {
		return true;
	} else {
		alert('Please complete following fields!\n\n'+comm);
		return false;
	}
}



/*
function popUp(name, strURL, strType, strTop, strLeft, strWidth, strHeight) {
	var strOptions = "";
	if (strType == "console") strOptions = "resizable,top="+strTop+",left="+strLeft+",height="+strHeight+",width="+strWidth;
	if (strType == "fixed") strOptions = "scrollbars=no,status,top="+strTop+",left="+strLeft+",height="+strHeight+",width="+strWidth;
	if (strType == "elastic") strOptions = "toolbar,menubar,scrollbars,resizable,location,top="+strTop+",left="+strLeft+",height="+strHeight+",width="+strWidth;
	var newWin = window.open(strURL, name, strOptions);
	newWin.focus();
}

function checkoutValid() {
	var comm = '';
	var comm2 = '';
	
	//billing
	if ($('#b_fname').val() == '') {
		comm += '\nFirst name';
	}
	if ($('#b_lname').val() == '') {
		comm += '\nLast name';
	}
	if ($('#b_address').val() == '') {
		comm += '\nYour address';
	}
	if ($('#b_country').val() == '') {
		comm += '\nCountry';
	}
	if ($('#b_postcode').val() == '') {
		comm += '\nPost code/ZIP';
	}
	if ($('#b_phone').val() == '') {
		comm += '\nPhone';
	}
//	if ($('#b_mobile').val() == '') {
//		comm += '\nMobile';
//	}
	if ($('#b_email').val() == '' || $('#b_email').val() != $('#b_email2').val()) {
		comm += '\nCorrect email';
	}
	if (comm != '') {
		comm = '\n\nBILLING'+comm;
	}
	
	if ($('#shipbill').attr('checked') != true) {
		//shippping
		if ($('#s_fname').val() == '') {
			comm2 += '\nFirst name';
		}
		if ($('#s_lname').val() == '') {
			comm2 += '\nLast name';
		}
		if ($('#s_address').val() == '') {
			comm2 += '\nYour address';
		}
		if ($('#s_country').val() == '') {
			comm2 += '\nCountry';
		}
		if ($('#s_postcode').val() == '') {
			comm2 += '\nPost code/ZIP';
		}
		if ($('#s_email').val() == '' || $('#s_email').val() != $('#s_email2').val()) {
			comm2 += '\nCorrect email';
		}
		if (comm2 != '') {
			comm2 = '\n\nSHIPPING'+comm2;
		}
	}
	
	if (comm != '' || comm2 != '') {
		alert('Please fill in following fields:'+comm+comm2);
		return false;
	}
	return true;
}

function cardValid() {
	var comm = '';
	if ($('#cardType').val() == '') {
		comm += '\nPlease specify your credit card type.';
	}
	if ($('#cardName').val() == '') {
		comm += '\nPlease enter your name as it appears on your card.';
	}
	if ($('#cardNr').val() == '') {
		comm += '\nPlease enter your credit card number.';
	}
	if ($('#expM').val() == '' || $('#expY').val() == '' || $('#expM').val() == 'MM' || $('#expY').val() == 'YY') {
		comm += '\nPlease specify your credit card expiration date.';
	}
	if (($('#staM').val() == '' || $('#staY').val() == '' || $('#staM').val() == 'MM' || $('#staY').val() == 'YY') && $('#issue').val() == '') {
		comm += '\nPlease specify your credit card start date or issue number.';
	}
	if ($('#cv2').val() == '') {
		comm += '\nPlease specify your credit card verification number (CV2)';
	}
	
	if (comm != '') {
		alert(comm);
		return false;
	}
	return true;
}
*/
