$(document).ready(function(){
													 
													 
	//===============//FANCYBOX:Initiate===============											 
	$("a.gallery").fancybox();
	//===============//FANCYBOX:Initiate===============
	
	var aryTmp;
	
	
	//===============//All input fields change bgcolor on focus...===============
	$("input.form-input").each(function(){
		$(this).focus(function(){
			$(this).css("background-color","#FFF");
		});
	});
	
	$("input.form-input").each(function(){
		$(this).blur(function(){
			$(this).css("background-color","#E7E7E7");
		});
	});
	
	$("textarea.form-input").each(function(){
		$(this).focus(function(){
			$(this).css("background-color","#FFF");
		});
	});
	
	$("textarea.form-input").each(function(){
		$(this).blur(function(){
			$(this).css("background-color","#E7E7E7");
		});
	});
	//====================...and they change back on blur========================
	
	
	//===============//on "enter" keyup submit each form===============
	$("input[type=text], input[type=password]").keyup(function(e){
		var key = e.keyCode;
		if (key==13){
			$(this).siblings("input[type=submit], input[type=image], input[type=button]").trigger("click");
		}
	});
	//===============on "enter" keyup submit each form//===============
	
	
	//================//disable search if term is null====================
	$("#search input[type=image]").click(function(){ return ($.trim($(this).parent().find("input[type=text]").val())!=""); });
	//================disable search if term is null//====================
	
	
	
	
	//===================//eortologio======================
	$("#eorto-container a.eortologio-link").click(function(){
		if ($("#eorto-container .eortologio:visible").size()>0){
			$("#eorto-container .eortologio").fadeOut();
		}else{
			$("#eorto-container .eortologio").fadeIn();
		}
		return false;
	});
	$("#eorto-container .eortologio a.close").click(function(){
		$("#eorto-container .eortologio").fadeOut();
		return false;
	});
	//===================eortologio//======================
	
	
	
	
	//===================//Newsletter Functions======================
	//show and hide sub/unsub forms
	$("a#nl-unsub").click(function(){ //hide sub form+show unsub form		
		$("#sub.sub-unsub-form").fadeOut("normal",function(){
			$("#unsub.sub-unsub-form").fadeIn("normal");
			$("a#nl-unsub").fadeOut("normal",function(){
				$("a#nl-sub").fadeIn("normal");
			});																								
		});
		return false;
	});
	$("a#nl-sub").click(function(){ //hide unsub form+show sub form		
		$("#unsub.sub-unsub-form").fadeOut("normal",function(){
			$("#sub.sub-unsub-form").fadeIn("normal");
			$("a#nl-sub").fadeOut("normal",function(){
				$("a#nl-unsub").fadeIn("normal");
			});
		});
		return false;
	});
	
	//subscribe
	$("#btnNLSubscribe").click(function(){
		var strNLEmail = $("#txtNLEmail").val();
		if ( checkEmail(strNLEmail) ){
			$("img.ajax-loading#subscribe-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69", { MODE : "NEWSLETTER", SUBMODE : "SUBSCRIBE", EMAIL : strNLEmail }, function(response){ //do a AJAX post					
					$("img.ajax-loading#subscribe-loading").fadeOut("fast"); //hide loading image
					if (response=="OK"){ //successfully subscribed
						$(".nl-msg#success-sub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else if (response=="ALREADY"){ //email exists
						$(".nl-msg#already-sub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else{ //no response, error?
						$(".nl-msg#error-sub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}
				});
			});
		}else{ //invalid email
			$(".nl-msg#email-sub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	
	//unsbuscribe
	$("#btnNLUnsub").click(function(){
		var strNLUnsubEmail = $("#txtNLUnsubEmail").val();
		if ( checkEmail(strNLUnsubEmail) ){
			$("img.ajax-loading#unsub-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69", { MODE : "NEWSLETTER", SUBMODE : "UNSUB", EMAIL : strNLUnsubEmail }, function(response){ //do a AJAX post
					$("img.ajax-loading#unsub-loading").fadeOut("fast"); //hide loading image
					if (response=="OK"){ //successfully unsubscribed
						$(".nl-msg#success-unsub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else if (response=="NOMEMBER"){ //no such email
						$(".nl-msg#fail-unsub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else{ //no response, error?
						$(".nl-msg#error-unsub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}
				});
			});
		}else{ //invalid email
			$(".nl-msg#email-unsub").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	//===================Newsletter Functions//======================
	
	
	
	

	//=========================//contact form===========================
	$("#contact-form form").submit(function(){
		var strFName = $("#txtFName").val();
		var strLName = $("#txtLName").val();
		var strEmail = $("#txtEmail").val();
		//var strPhone = $("#txtPhone").val();
		//var strCaptchaBox = $("#CaptchaBox").val();
		var blnAllOk = true;
		
		if ((strFName=="") || (strLName=="") || (!checkEmail(strEmail))||  (strMessage=="")){
			blnAllOk = false
		}
		
		if (!blnAllOk){
			$("#contact-form .messages .error").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
		
		return blnAllOk;
	});
	//=========================contact form//===========================
	
	
	
	

	//=========================//displayITM2 functions===========================
	////Update color hidden field and stock
	$("#cmbProductColor").change(function(){
		var aryTmp 				= $(this).val().split("___");
		var strColorID 		= aryTmp[0];
		var strColorName 	= aryTmp[1];
		var strStock 			= aryTmp[2];
		$("#COLOR").val(strColorID);
		$("#STOCKSTATUS").val(strStock);
		$("#ITMPARAMS").val(strColorName);
		$(this).css("border","1px solid #999"); //to remove the red border if from error
	});
	
	////Check values on submit to cart
	$("#add-to-cart").submit(function(){
		var color = $("#COLOR").val();
		if ( color=="0" ){
			$("#cmbProductColor").css("border","1px solid #FF0000");
			$("#choose-color-error").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
			return false;
		}else{
			return true;
		}
	});
	//=========================displayITM2 functions//===========================	
	
	
		
	//===================//Cart Functions======================
	//check if card qualifies for installments
	var validCards = [];
	validCards[1] = 60197606;
	validCards[2] = 60197607;
	validCards[3] = 60197608;
	validCards[4] = 60197609;
	validCards[5] = 60197611;
	validCards[6] = 60197610;
	validCards[7] = 510155;
	validCards[8] = 510155;
	validCards[9] = 545865;
	validCards[10] = 552202;
	validCards[11] = 539731;
	validCards[12] = 479275;
	validCards[13] = 479273;
	validCards[14] = 479276;
	validCards[15] = 479273;
	validCards[16] = 402957;
	validCards[17] = 479274;
	validCards[18] = 402957;
	validCards[19] = 455039;
	validCards[20] = 494092;
	validCards[21] = 402957;
	validCards[22] = 479274;
	validCards[23] = 479273;
	validCards[24] = 479276;
	validCards[25] = 479275;
	validCards[26] = 479273;
	validCards[27] = 479274;
	validCards[28] = 402957;
	validCards[29] = 479274;
	validCards[30] = 455054;
	validCards[31] = 413492;
	validCards[32] = 402957;
	validCards[33] = 479274;
	validCards[34] = 402957;
	validCards[35] = 479274;
	validCards[36] = 455054;
	validCards[37] = 479274;
	validCards[38] = 402957;
	validCards[39] = 479276;
	validCards[40] = 455140;
	validCards[41] = 455192;
	validCards[42] = 455140;
	validCards[43] = 406301;
	validCards[44] = 413492;
	validCards[45] = 418895;
	validCards[46] = 510155;
	validCards[47] = 413492;
	validCards[48] = 418895;
	validCards[49] = 510155;
	validCards[50] = 479276;
	validCards[51] = 479275;
	validCards[52] = 4792737;
	validCards[53] = 4792768;
	validCards[54] = 4792764;
	validCards[55] = 402957;
	validCards[56] = 479275;
	validCards[57] = 479276;
	validCards[58] = 54586513;
	validCards[59] = 47927520;
	validCards[60] = 47927521;
	validCards[61] = 47927320;
	validCards[62] = 418895;
	validCards[63] = 418830;
	validCards[64] = 479273;
	validCards[65] = 479221;
	validCards[66] = 554209;
	validCards[67] = 430528;
	validCards[68] = 498815;
	validCards[69] = 40493400;
	validCards[70] = 490700;
	validCards[71] = 490701;
	validCards[72] = 413756;
	validCards[73] = 41375610;
	validCards[74] = 532322;
	validCards[75] = 524035;
	validCards[76] = 541514;
	validCards[77] = 49070020;
	validCards[78] = 49070120;
	validCards[79] = 496090;
	validCards[80] = 496092;
	validCards[81] = 496091;
	validCards[82] = 496094;
	validCards[83] = 496095;
	validCards[84] = 496097;
	validCards[85] = 496098;
	validCards[86] = 404736;
	validCards[87] = 404737;
	validCards[88] = 543074;
	validCards[89] = 415958;
	validCards[90] = 415959;
	validCards[91] = 466526;
	validCards[92] = 4159810;
	validCards[93] = 474343;
	validCards[94] = 518516;
	validCards[95] = 518518;
	validCards[96] = 518677;
	validCards[97] = 429970;
	validCards[98] = 557956;
	validCards[99] = 549885;
	validCards[100] = 423294;
	validCards[101] = 423295;
	validCards[102] = 524870;
	validCards[103] = 518519;
	validCards[104] = 518517;
	validCards[105] = 490947;
	validCards[106] = 490948;
	validCards[107] = 432495;
	validCards[108] = 540186;
	validCards[109] = 410201;
	validCards[110] = 444681;
	validCards[111] = 432495;
	validCards[112] = 407534;
	validCards[113] = 499954;
	validCards[114] = 409313;
	validCards[115] = 409314;
	validCards[116] = 480204;
	validCards[117] = 499970;
	validCards[118] = 510037;
	validCards[119] = 520304;
	validCards[120] = 518661;
	validCards[121] = 494039;
	validCards[122] = 494041;
	validCards[123] = 494040;
	validCards[124] = 415953;
	validCards[125] = 415954;
	validCards[126] = 415955;
	validCards[127] = 510015;
	validCards[128] = 510016;
	validCards[129] = 510001;
	validCards[130] = 409840;
	validCards[131] = 461298;
	validCards[132] = 461297;
	validCards[133] = 461299;
	validCards[134] = 522072;
	validCards[135] = 534153;
	validCards[136] = 405211;
	validCards[137] = 415970;
	validCards[138] = 403721;
	validCards[139] = 467105;
	validCards[140] = 467106;
	validCards[141] = 467107;
	validCards[142] = 467108;
	validCards[143] = 4671061;
	validCards[144] = 4671071;
	validCards[145] = 518519;
	validCards[146] = 414278;
	validCards[147] = 414279;
	validCards[148] = 550076;
	validCards[149] = 405470;
	validCards[150] = 405471;
	validCards[151] = 405472;
	validCards[152] = 405473;
	validCards[153] = 405474;
	validCards[154] = 550106;
	validCards[155] = 543018;
	validCards[156] = 552215;
	validCards[157] = 453212;
	validCards[158] = 4509034;
	validCards[159] = 4509031;
	validCards[160] = 415963;
	validCards[161] = 480946;
	validCards[162] = 480947;
	validCards[163] = 510099;
	validCards[164] = 455258;
	validCards[165] = 418861;
	validCards[166] = 4509033;
	validCards[167] = 454320;
	validCards[168] = 454321;
	validCards[169] = 402068;
	validCards[170] = 402798;
	validCards[171] = 427310;
	validCards[172] = 4305882;
	validCards[173] = 451189;
	validCards[174] = 490844;
	validCards[175] = 490845;
	validCards[176] = 490846;
	validCards[177] = 510053;
	validCards[178] = 528055;
	validCards[179] = 515877;
	validCards[180] = 558483;
	validCards[181] = 520949;
	validCards[182] = 446356;
	validCards[183] = 5203152;
	validCards[184] = 406312;
	validCards[185] = 406313;
	validCards[186] = 414029;
	validCards[187] = 429579;
	validCards[188] = 543750;
	validCards[189] = 518666;
	validCards[190] = 410222;
	validCards[191] = 425591;
	validCards[192] = 425592;
	validCards[193] = 425593;
	validCards[194] = 425594;
	validCards[195] = 425595;
	validCards[196] = 494093;
	validCards[197] = 479240;
	validCards[198] = 494062;
	validCards[199] = 402132;
	validCards[200] = 402090;
	validCards[201] = 439059;
	validCards[202] = 494061;
	validCards[203] = 479239;
	validCards[204] = 4940622;
	validCards[205] = 4020900;
	validCards[206] = 4020906;
	validCards[207] = 4940627;
	validCards[208] = 4020906;
	validCards[209] = 4797443;
	validCards[210] = 4797449;
	validCards[211] = 4020909;
	validCards[212] = 4940621;
	validCards[213] = 4940626;
	validCards[214] = 4020901;
	validCards[215] = 4940628;
	validCards[216] = 400874;
	validCards[217] = 4797445;
	validCards[218] = 4008745;
	validCards[219] = 402132;
	validCards[220] = 479239;
	validCards[221] = 439059;
	validCards[222] = 422183;
	validCards[223] = 445821;
	validCards[224] = 445822;
	$("#cardStartingDigits").change(function(){
		var digits = parseInt($("#cardStartingDigits").val());
		if (!Array.indexOf) {
			  Array.prototype.indexOf = function (obj, start) {
				for (var i = (start || 0); i < this.length; i++) {
				  if (this[i] == obj) {
					return i;
				  }
				}
			  }
			}
		if (validCards.indexOf(digits) > 0)
		{
			$("#isOkForInstallments").val(1);
		}
		else
		{
			dontShow = 1;
			$("#InstallmentsCont").slideUp("normal");
			$("#cmbInstallments").empty();
			$("#isOkForInstallments").val(0);
		}
	});
	
	//update quantities
	$("#update-quantities").live("click",function(){		
		var strNewQties = "";
		$("input[name=NEWQTY]").each(function(){
			strNewQties += "," + $(this).val();
		});
		$("img.ajax-loading#cart-loading").fadeIn("fast",function(){ //show loading image
			$.post("/Ajax/default.asp?ITMID=69", { MODE : "CART", SUBMODE : "UPDATE", NEWQTY : strNewQties }, function(cartHTML){
			$("img.ajax-loading#cart-loading").fadeOut("fast"); //hide loading image	
				if (cartHTML!=""){
					$(".cart-msg#update-success").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
					$("#cart-content").fadeOut(function(){
						$(this).html(cartHTML).fadeIn();
					});
					return false;
				}
				window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page
			});
		});
	});
	
	//limit quantities to stock
	$("input[name='NEWQTY']").live("keypress", function(e){
		if ( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {//condition to accept only tab(0), delete,backspace(8) and numbers (48<ASCII<57)
			return false;
		}
	});
	$("input[name='NEWQTY']").live("keyup", function(e){
		var intID = $(this).attr("id");
		var inputQty =  parseInt($(this).val());
		var stockStatus = parseInt($(this).attr("alt").substring(13)); //get stock status from alt attribut
		if ( isNaN(stockStatus) ) { stockStatus = 2; }
		if ( inputQty>stockStatus ){
			var msg = $(this).parent().children("p");
			if (!msg.is(":visible"))
				msg.fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
			$(this).val(stockStatus)
		}
	});
	
	//white bg effect on ajax loaded text fields
	$("#cart-content input.form-input").live("mouseover", function(){
		$(this).focus(function(){
			$(this).css("background-color","#FFF");
		});
	});
	$("#cart-content input.form-input").live("mouseout", function(){
		$(this).blur(function(){
			$(this).css("background-color","#E7E7E7");
		});
	});
	
	//delete checked items
	$("#delete-selected").live("click", function(){
		var strWhichToRemove = "";
		$("input[name=WHICHTORMV]:checked").each(function(){
			strWhichToRemove += "," + $(this).val();
		});
		strWhichToRemove += ",";
		if (strWhichToRemove==""){//hasn't checked any product to delete
			$(".cart-msg#no-checked").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
		}else{ //has selected items to delete, send ajax data
			$("img.ajax-loading#cart-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69", { MODE : "CART", SUBMODE : "DELETE", WHICHTORMV : strWhichToRemove }, function(cartHTML){			
					$("img.ajax-loading#cart-loading").fadeOut("fast"); //hide loading image	
					if (cartHTML!=""){
						$(".cart-msg#delete-success").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
						$("#cart-content").fadeOut(function(){
							$(this).html(cartHTML).fadeIn();
						});
						return false;
					}
					window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page	
				});
			});
		}
	});
	
	//check voucher code
	$("input#btnVoucherSubmit").live("click", function(){
		var strVoucher = $("input#txtVoucher").val();
		if (strVoucher==""){
			$(".cart-msg#voucher-empty").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
				return false;
		}
		$("img.ajax-loading#voucher-loading").fadeIn("fast",function(){ //show loading image
			//first post to see if voucher is correct
			$.post("/Ajax/default.asp?ITMID=69",{MODE: "CART", SUBMODE : "VOUCHERCHECK", VOUCHER: strVoucher}, function(json){
				if (json.result=="true"){
					//get the html
					$.post("/Ajax/default.asp?ITMID=69",{MODE: "CART", SUBMODE : "VOUCHER", VOUCHER: strVoucher}, function(cartHTML){
						$("img.ajax-loading#voucher-loading").fadeOut("fast"); //hide loading image		
						if (cartHTML!=""){
							$(".cart-msg#voucher-success").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
							$("#cart-content").fadeOut(function(){
								$(this).html(cartHTML).fadeIn();
							});
							return false;
						}
						window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page
					});
				}else if (json.result=="false"){
					//show "not found" message
					$(".cart-msg#voucher-error").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
					$("img.ajax-loading#voucher-loading").fadeOut("fast"); //hide loading image	
				}else{
					window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page
				}
			},"json");
		});
	});
	
	
	//show/hide shipping areas based on shipping method
	$("#cmbShippingMethod").live("click",function(){
		var shippingMethod = $(this).val();
		$("#hidShippingPrice").val("-"); //reset hidden shipping price field
		switch (shippingMethod){
			case "-":{
				$("#shipping-area-elta").fadeOut("normal",function(){
					$("#shipping-area-elta-courier").fadeOut("normal",function(){
						$("#shipping-area-elta-courier-free").fadeOut("normal",function(){
							$("#shipping-area-ems").fadeOut("normal",function(){																								
								$("#shipping-area-msg").fadeIn("normal");
							});					
						});
					});
				});
				break
			}
			case "ELTA":{
				$("#shipping-area-msg").fadeOut("normal",function(){
					$("#shipping-area-ems").fadeOut("normal",function(){
						$("#shipping-area-elta-courier-free").fadeOut("normal",function(){
							$("#shipping-area-elta-courier").fadeOut("normal",function(){
								$("#shipping-area-elta").fadeIn("normal");
							});
						});
					});
				});
				break
			}
			case "ELTACOURIERFREE":{
				$("#shipping-area-msg").fadeOut("normal",function(){
					$("#shipping-area-ems").fadeOut("normal",function(){
						$("#shipping-area-elta").fadeOut("normal",function(){
							$("#shipping-area-elta-courier").fadeOut("normal",function(){
								$("#shipping-area-elta-courier-free").fadeIn("normal");
							});
						});
					});
				});
				break
			}
			case "ELTACOURIER":{
				$("#shipping-area-msg").fadeOut("normal",function(){
					$("#shipping-area-ems").fadeOut("normal",function(){
						$("#shipping-area-elta").fadeOut("normal",function(){
							$("#shipping-area-elta-courier-free").fadeOut("normal",function(){
								$("#shipping-area-elta-courier").fadeIn("normal");
							});
						});
					});
				});
				break
			}
			case "EMS":{
				$("#shipping-area-msg").fadeOut("normal",function(){
					$("#shipping-area-elta").fadeOut("normal",function(){
						$("#shipping-area-elta-courier-free").fadeOut("normal",function(){
							$("#shipping-area-elta-courier").fadeOut("normal",function(){
								$("#shipping-area-ems").fadeIn("normal");
							});
						});
					});
				});
				break
			}
		}
	});
	
	//show hide banks
	$("#cmbPaymentMethod").live("click",function(){
		var paymentMethod = $(this).val();
		if ( paymentMethod == "3" ) {
			$("#banks").slideDown("normal");
		}else
		{
			$("#banks").slideUp("normal");
		}
		if (paymentMethod == "1")
		{
			$("#cardDigits").slideDown("normal");
		}
		else
		{
			$("#cardDigits").slideUp("normal");
		}
	});
	
	//show hide 

	$("#cmbPaymentMethod").live("click",function(){
		var count;
		var word,word3;
		var word2;
		var totalSum;
		var dontShow = 0;
		var paymentMethod = $(this).val();
		$("#cmbInstallments").empty();
		if ( paymentMethod == "1" ) 
		{
			$.post("/Ajax/default.asp?ITMID=69", { MODE : "CART", SUBMODE : "INSTALL" , SHIPPING : ""+ $("#hidShippingPrice").val() +""}, function(json){			
				if (json.result=="ok"){
					if (json.lang == "1") {word = " άτοκες δόσεις, με "; word2 = "&euro; ανα δόση"; word3 = "Χωρίς Δόσεις"}
					else if (json.lang == "2") {word = " installments , with "; word2 = "&euro; per installment";  word3 = "No Installments";}
					$("#cmbInstallments").append("<option value='0'>.::"+word3+"::.</option>");
					if (json.installments >0)
					{
						for (count=2;count<=json.installments;count++)
						{
							totalSum = (((parseInt(json.total)/count)).toFixed(2)+"").replace(".",",");
							if (count !=7) $("#cmbInstallments").append("<option value="+count+">"+count+" "+ word + totalSum + word2 +"</option>");
						}	
						if ($("#checkoutForm #shipping-area div:visible select option[class!=NoIncr]:selected").length && $("#isOkForInstallments").val() == 1) 
						{
							$("#InstallmentsCont").slideDown("normal");
							return false;
						}
						else 
						{
							$("#InstallmentsCont").slideUp("normal");
							$("#cmbInstallments").empty();
						}
					}
					else
					{
						dontShow = 1;
						$("#InstallmentsCont").slideUp("normal");
						$("#cmbInstallments").empty();
					}
					
				}
				
				//window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page	
			},"json");
		}
		else{
			$("#InstallmentsCont").slideUp("normal");
			$("#cmbInstallments").empty();
		}
		//console.log(paymentMethod)
	});
		
	$("#checkoutForm #shipping-method select option[class=NoIncr]").live("click",function(){
					$("#cmbInstallments").empty();
					$("#cmbPaymentMethod").trigger("click");
	});	
	
	//update hidden shipping price by selecting the dropdown boxes
	$("#shipping-area select").live("click",function(){
		if ($("#cmbPaymentMethod").val() == "2")
		{
			}
		var lngShippingPrice = $(this).val();
		if (lngShippingPrice!="-"){
			$.post("/Ajax/default.asp?ITMID=69", { MODE : "CART", SUBMODE : "SHIPPING", SHIPPING : lngShippingPrice}, function(json){			
				if (json.result=="ok"){
					$("#hidShippingPrice").val(lngShippingPrice);
					$("#shipping-cost span").html(json.discount);
					$("#total-price .amount").html(json.total);
					$("#cmbInstallments").empty();
					$("#cmbPaymentMethod").trigger("click");
					return false;
				}
				window.location = "/cart.asp?ITMID=45"; //in any other case refresh the page	
			},"json");
		}
	});

	//check field values on form submit
	$("#checkout-button input").live("click", function(){
		var paymentMethod 	= $("#cmbPaymentMethod").val();
		var shippingMethod 	= $("#cmbShippingMethod").val();
		var shippingPrice 	= $("#hidShippingPrice").val();
		var bank						= $("#cmbBanks").val();
		if ( paymentMethod == "-" ){
			$(".cart-msg#payment-method").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
			return false;
		}
		if (( paymentMethod == "3" ) && ( bank == "-" )){
			$(".cart-msg#nobanks").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
			return false;
		}
		if ( shippingMethod == "-" ){
			$(".cart-msg#shipping-method").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
			return false;
		}
		if ( shippingPrice == "-" ){
			$(".cart-msg#shipping-price").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
			return false;
		}
	})
	//===================Cart Functions//======================

	
	
	
	//===============//MemberShip Functions====================
	// REGISTER
	$("input#submit-register").click(function(){
		var strUserName 	= $("#txtRegUserName").val();	
		var strEmail		 	= $("#txtRegEmail").val();	
		var strPassword1	= $("#txtRegPassword1").val();		
		var strPassword2 	= $("#txtRegPassword2").val();		
		var strFName 			= $("#txtRegFName").val();		
		var strLName 			= $("#txtRegLName").val();
		
		var strHow 			= $("#cbHow").val();
		var strHowOther 	= $("#txtOtherHow").val();
		
		if ( (strUserName!="") && (checkEmail(strEmail)) && (strPassword1!="") && (strPassword2!="") && (strPassword1==strPassword2)&& (strPassword1.length>5) ){
			//all data ok, post to see if member exists
			$("img.ajax-loading#reg-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69",{MODE: "MEMBER", SUBMODE : "REGISTER", txtUserName: strUserName, txtEmail: strEmail, txtPassword: strPassword1, txtFName: strFName, txtLName: strLName, cbHow: strHow, txtOtherHow: strHowOther}, function(data){
					$("img.ajax-loading#reg-loading").fadeOut("fast"); //hide loading image																																																																																									
					if (data=="mexists") { //member exists, try again
						$("#reg-msg #reg-already").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else if(data=="ok") {//registered fine, fadein the logged on box
						$("#reg-msg #reg-success").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
						$("#login-form").fadeOut("normal",function(){
							$("#logged-on strong").html(strUserName);
							$("#logged-on").fadeIn("normal");
						})						
					}else{ //problem, contact administartor		 
						$("#reg-msg #reg-error").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
					}
				});
			});
		}else{
			//some data is missing or is incorrect - try again
			$("#reg-msg #reg-fields").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	
	// MEMBER PROFILE
	$("input#submit-profile").click(function(){
		var strUserName 	= $("#txtProfUserName").val();	
		var strEmail		 	= $("#txtProfEmail").val();	
		var strPassword1	= $("#txtProfPassword1").val();		
		var strPassword2 	= $("#txtProfPassword2").val();		
		var strFName 			= $("#txtProfFName").val();		
		var strLName 			= $("#txtProfLName").val();	
		
		var strHow 			= $("#cbHow").val();
		var strHowOther 	= $("#txtOtherHow").val();
		
		var intMID 				= $("#MID").val();	
		if ( (strUserName!="") && (checkEmail(strEmail)) && (strPassword1!="") && (strPassword2!="") && (strPassword1==strPassword2)&& (strPassword1.length>5) ){
			//all data ok, post to see if member exists
			$("img.ajax-loading#prof-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69",{MODE: "MEMBER", SUBMODE : "PROFILE", txtUserName: strUserName, txtEmail: strEmail, txtPassword: strPassword1, txtFName: strFName, txtLName: strLName, MID: intMID, cbHow: strHow, txtOtherHow: strHowOther}, function(data){
					$("img.ajax-loading#prof-loading").fadeOut("fast"); //hide loading image																																																																																									
					if(data=="ok") {//registered fine, fadein the logged on box
						$("#prof-msg #prof-success").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
						$("#login-form").fadeOut("normal",function(){
							$("#logged-on strong").html(strUserName);
							$("#logged-on").fadeIn("normal");
						})						
					}else{ //problem, contact administartor		 
						$("#prof-msg #prof-error").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
					}
				});
			});
		}else{
			//some data is missing or is incorrect - try again
			$("#prof-msg #prof-fields").slideDown("slow").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	
	// LOGIN
	$("#log-in").click(function(){
		var strEmail 	 = $("#txtLoginEmail").val();
		var strPassword = $("#txtLoginPassword").val();
		if ((checkEmail(strEmail)) && (strPassword!="")){
			$("img.ajax-loading#login-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69",{MODE: "MEMBER", SUBMODE : "LOGIN", txtLoginEmail: strEmail, txtLoginPassword: strPassword}, function(data){
				$("img.ajax-loading#login-loading").fadeOut("fast"); //hide loading image
					if ( data == "nomember" ){ //no member exists with that info, try again
						$(".login-msg#login-nomember").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
					}else{ //logged on successfully, show logged on box
					  window.location ="/homepage.asp?ITMID=2";
						/*
						$("#logged-on strong").html(data);
						$("#login-form").fadeOut("normal",function(){
							$("#logged-on").fadeIn("normal");
							
						});*/
					}
				});
			});
		}else{ //wrong input, try again
			$(".login-msg#login-fields").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	
	// LOGOUT
	$("#log-out").click(function(){
		$.post("/Ajax/default.asp?ITMID=69",{MODE: "MEMBER", SUBMODE: "LOGOUT"}, function(data){
		  window.location ="/homepage.asp?ITMID=2";
			/*$("#logged-on").fadeOut("normal",function(){
				$("#login-form").fadeIn("normal");
			});*/
		});
		return false;
	});
	
	//FORGOT PASS
	$("#forgot-pass, #forgot-pass-login").click(function(){
		$("#forgot-pass-form").slideDown("normal");
		return false;
	});
	$("#submit-fpass").click(function(){
		var txtFPEmail = $("#txtFPEmail").val();
		if ( checkEmail(txtFPEmail) ){
			$("img.ajax-loading#fpass-loading").fadeIn("fast",function(){ //show loading image
				$.post("/Ajax/default.asp?ITMID=69",{MODE: "MEMBER", SUBMODE: "FORGOTPASS", txtEmail: txtFPEmail}, function(data){
					$("img.ajax-loading#fpass-loading").fadeOut("fast"); //hide loading image
					if ( data == "sent" ){ //sent mail
						$(".fpass-msg#fpass-sent").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal", function(){
							setTimeout("$('#forgot-pass-form').slideUp()",300);
						});
					}else if( data == "unsent" ){ //no member found with that email
						$(".fpass-msg#fpass-nomember").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal", function(){
							setTimeout("$('#forgot-pass-form').slideUp()",300);
						});
					}
				});
			});
		}else{
			$(".fpass-msg#fpass-error").slideDown("normal").animate({opacity: 1.0}, 1500).slideUp("normal");
		}
	});
	
	$("#hide-fpass").click(function(){
		$("#forgot-pass-form").slideUp("normal");
		return false;
	});
	//===============MemberShip Functions//====================	

	
	
	
	//=================//Load News List========================	
	$("select#news-paging").change(function(){
		var intPage		 = $(this).val();
		var intCategID = $("#news-category").val();
		$("#left-menu-categ h2").fadeOut();
		$.post("/Ajax/default.asp?ITMID=69", { MODE: "NEWS", GO: "PAGING", PAGE: intPage, CATEGID: intCategID} , function(html){
			$("#left-menu-categ").html(html);
		$("#left-menu-categ h2").fadeIn();
		});
	});
	//=================//Load News List========================	

	
	
	
	//======================//Load News============================	
	$("#news-nav a").click(function(){
		var intCurPosition = $("#current-position").val();
		var intCategID		 = $("#news-category").val();
		var strGo;
		var intNewPosition;
		if ( $(this).parents(0).attr("class") == "next" ){
			strGo = "NEXT"
		}else if ( $(this).parents(0).attr("class") == "previous" ) {
			strGo = "PREVIOUS"
		}
		$("img.ajax-loading#news-loading").fadeIn("fast",function(){ //show loading image
			$.post("/Ajax/default.asp?ITMID=69", { MODE: "NEWS", CURPOS: intCurPosition, GO: strGo, CATEGID: intCategID} , function(html){
				$("img.ajax-loading#news-loading").fadeOut("fast"); //hide loading image
				$("#dynamic-news").fadeOut("normal",function(){
					$(this).html(html).fadeIn("normal");
					intNewPosition = $("#new-position").val();
					$("#current-position").val(intNewPosition);
				})
			});
		});
		return false;
	});
	//======================Load News//============================	

	
	
	
	//================//giftcert: toggle forms=====================	
	$("#display-content.gift-cert input[name=rdSendMethod]").click(function(){	
		var intRadValue = $(this).val();
		$("#display-content.gift-cert .send-method-form:visible").fadeOut();
		switch (intRadValue){
			case "1":{
				$("#display-content.gift-cert .send-method-form.mail-form").fadeIn();
				break
			}
			case "2":{
				$("#display-content.gift-cert .send-method-form.post-form").fadeIn();
				break
			}
		}
		$("#display-content.gift-cert .submit").fadeIn();
	});
	//================giftcert: toggle forms//=====================	

	
	
	
	//=============//giftcert: fill in all fields==================	
	$("form#gift-cert-form").submit(function(){
		var blnAllOk = true;
		$("form#gift-cert-form input:visible").each(validateGiftCertFields);	
		$("form#gift-cert-form textarea").each(validateGiftCertFields);	
		$("form#gift-cert-form select:visible").each(validateGiftCertFields);	
		function validateGiftCertFields(){
			var fieldVal = $(this).val();
			if (fieldVal==""){
				$(this).addClass("empty");
				blnAllOk = false;
			}
		}
		if ($("form#gift-cert-form input#txtRcptEmail:visible").size()>0){
			var strRcptEmail = $("form#gift-cert-form input#txtRcptEmail:visible").val();
			if (!checkEmail(strRcptEmail)){
				$("form#gift-cert-form input#txtRcptEmail:visible").addClass("empty");
				blnAllOk = false;
			}
		}
		if (blnAllOk){ //update hidden fields
			var intPrice = $("form#gift-cert-form input#txtAmount").val();
			var strFromName = $("form#gift-cert-form input#txtFromName").val();
			var strToName = $("form#gift-cert-form input#txtToName").val();
			var strMessage = $("form#gift-cert-form textarea#txtMessage").val();
			var intSendMethod = $("form#gift-cert-form input[name=rdSendMethod]:checked").val();
			var strDescription;
			strDescription  = "Δωροεπιταγή &euro;" + intPrice + " <br> <br>";
			strDescription += "Από: " + strFromName + "<br>";
			strDescription += "Προς: " + strToName + "<br>";
			strDescription += "Μήνυμα: " + strMessage + "<br>";
			strDescription += "Ποσό: &euro;" + intPrice + "<br> <br>";
			if (intSendMethod=="1"){
				var strRcptEmail = $("form#gift-cert-form input#txtRcptEmail").val();
				strDescription += "Μέθοδος αποστολής: Μέσω Email <br>";
				strDescription += "Email παραλήπτη: " + strRcptEmail + " <br>";
			}else if (intSendMethod=="2"){
				var strRcptName = $("form#gift-cert-form input#txtRcptFName").val() + " " + $("form#gift-cert-form input#txtRcptLName").val();
				var strRcptAddress = $("form#gift-cert-form input#txtRcptAddress").val();
				var strRcptCity = $("form#gift-cert-form input#txtRcptCity").val();
				var strRcptCounty = $("form#gift-cert-form input#txtRcptCounty").val();
				var strRcptState = $("form#gift-cert-form select#cmbRcptState").val();
				var strRcptCountry = $("form#gift-cert-form select#cmbRcptCountry").val();
				var strRcptZip = $("form#gift-cert-form input#txtRcptZip").val();
				var strRcptPhone = $("form#gift-cert-form input#txtRcptPhone").val();
				strDescription += "Μέθοδος αποστολής: Μέσω Ταχυδρομίου <br>";
				strDescription += "Διεύθυνση παραλήπτη: " + strRcptAddress + " <br>";
				strDescription += "Πόλη παραλήπτη: " + strRcptCity + " <br>";
				strDescription += "Περιοχή παραλήπτη: " + strRcptCounty + " <br>";
				strDescription += "Νομός παραλήπτη: " + strRcptState + " <br>";
				strDescription += "Country παραλήπτη: " + strRcptCountry + " <br>";
				strDescription += "ΤΚ παραλήπτη: " + strRcptZip + " <br>";
				strDescription += "Τηλέφωνο παραλήπτη: " + strRcptPhone + " <br>";
			}
			$("form#gift-cert-form input#TITLE").val(strDescription);
			$("form#gift-cert-form input#DEFAULTLANGTITLE").val(strDescription);
			$("form#gift-cert-form input#PRICE").val(intPrice);
		}else{
			$("#display-content.gift-cert .fillall").fadeIn("normal").animate({opacity: 1.0}, 1500).fadeOut("normal");
		}
		return blnAllOk;
	});
	//=============giftcert: fill in all fields//==================	

	
	
	
	//============//giftcert: only numbers in price================	
	$("form#gift-cert-form input#txtAmount").keypress(function(e){
		if ( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {//condition to accept only tab(0), delete,backspace(8) and numbers (48<ASCII<57)
			return false;
		}
	});
	$("form#gift-cert-form input#txtAmount").blur(function(){
		var intPrice =  parseInt($(this).val());
		if (intPrice<10){
			$("form#gift-cert-form span.more10").css("color","#F00").animate({opacity:1.0},1500,function(){
				$(this).css("color","#000");
			});
			$(this).val(10);
		}
	});
	//============giftcert: only numbers in price//================	

	
	
	
	//===============//checks if email is valid====================
	function checkEmail(strEmail){
		var strDuckyPosition = strEmail.indexOf("@")
		var strDotPosition  = strEmail.lastIndexOf(".")
		if ((strDuckyPosition>0) && (strDotPosition>strDuckyPosition)){
			return true;
		}
		else{
			return false;
		}
	}		
	//===============checks if email is valid//====================	
});