jQuery(document).ready(function() {
	jQuery('#lang ul ').hide();
	jQuery('#small-menu .tx-felogin-pi1').hide();
	jQuery('.pay-by-phone-popup').hide();
	/* Show language box on click */
	
	jQuery('#lang a.lang-selector').click(
		function() {
			jQuery('#lang ul').toggle();
			return false;
		});
	jQuery('#lang ul').focusout(
		function() {
			jQuery('#lang ul').hide();
		});
	
	/* Show login box on click */
	/*
	jQuery('#small-menu .login-link').click(
		function() {
			jQuery('#small-menu .tx-felogin-pi1').toggle();
			return false;
		});
	jQuery('#small-menu .tx-felogin-pi1').blur(
		function() {
			jQuery('#small-menu .tx-felogin-pi1').hide();
		});
	*/
	/* Show Footer Poll box on click */
	
	/*jQuery('.footer-pool').click(
		function() {
			jQuery('#footer-middle .popup-footer').toggle();
			jQuery('#footer-right .popup-footer').hide();
			return false;
		});
	jQuery('#footer-middle .popup-footer').blur(
		function() {
			jQuery('.popup-footer').hide();
		});
	*/
	/* Show Footer Contact box on click */
	
	jQuery('.footer-comment').click(
		function() {
			jQuery('#footer-right .popup-footer').toggle();
			jQuery('#footer-middle .popup-footer').hide();
			return false;
		});
	jQuery('#footer-right .popup-footer').blur(
		function() {
			jQuery('.popup-footer').hide();
		});
	
	/* Show Pay by Phone popup box on click */
	
	jQuery('.pay-by-phone-popup-link').click(
		function() {
			jQuery('.pay-by-phone-popup').toggle();
			return false;
		});
	jQuery('.pay-by-phone-popup').blur(
		function() {
			jQuery('.pay-by-phone-popup').hide();
		});
		
	jQuery('.close-popup').click (
		function() {
			jQuery(this).parent().hide();
		});
	
	
	/* Product Rollover for "Add to cart" and "Compare" */
	
	jQuery('.product-img').hover(
		function() {
		jQuery(this).find(".add-to-cart").show() 
		}, 
		function() {
		jQuery('.add-to-cart').hide();		
	});
	
	jQuery('.article-img').hover(
		function() {
		jQuery(this).find(".add-to-cart").show() 
		}, 
		function() {
		jQuery('.add-to-cart').hide();		
	});
	
	jQuery('.add-to-cart').hover(
		function() {
		jQuery(this).show() 
		});
		
	
	jQuery('.product-search-form a').click(
		function() {
		jQuery('.product-search-form-box').slideToggle('fast');
		return false;
		});	
	
	/* Location selector */
	
	jQuery('.locationSelector').change(function(){;
        if (jQuery('.locationSelector').val() != '') {
        }
        window.location = '/'+jQuery('.locationSelector').val();
    });
    
    var radioValue = jQuery("input:checkbox:checked[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']").val();
	if (radioValue == 1) {
		jQuery('.content-two-cols-right').hide();
		jQuery('.you-use-payment-address').show();
	}
    	
    jQuery("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']").click(function() {
		
			var radioValue = jQuery("input:checkbox:checked[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']").val();
			jQuery('.content-two-cols-right').toggle();
			jQuery('.you-use-payment-address').toggle();
		});
		
	jQuery("ul#menu").superfish();
	
	
	
		jQuery('.register-company-row').hide();
	
	jQuery('input#tx-srfeuserregister-pi1-company_check').click(function() {
		if (jQuery('input#tx-srfeuserregister-pi1-company_check:checked').val() == "1") {
			jQuery('.register-company-row').slideDown();
		} else {
			jQuery('.register-company-row').slideUp();
		}
	});
	
	// VALIDATE REGISTRATION FORM
	if (jQuery('#mailform').length) {
		jQuery("#mailform").validate({
			rules: {
				"name":  {
					required: true,
				},
				"email":  {
					required: true,
					email: true,
				},
				"address":  {
					required: true,
				},
			},
			messages: {
				"name": "Ubacite Vaše ime",
				"email": "Ubacite Vašu E-Mail adresu",
				"address": "Ubacite Vašu poruku",
			},
			errorClass: 'errorClass',
		});
	}
	
	
	
	if (jQuery('form.felogin_loginform').length) {
		jQuery('form.felogin_loginform').validate({
			rules: {
				"user":  {
					required: true,
				},
				"pass":  {
					required: true,
				},
			},
			messages: {
				"user": "Ubacite Vaše korisničko ime",
				"pass": "Ubacite Vašu lozinku",
			},
			errorClass: 'errorClassLogin',
		});
	}
	
	
	if (jQuery('.content-two-cols-left .tx-felogin-pi1 form').length) {
		
		jQuery('.content-two-cols-left .tx-felogin-pi1 form').validate({
			rules: {
				"tx_felogin_pi1[forgot_email]":  {
					required: true,
					email: true,
				},
			},
			messages: {
				"tx_felogin_pi1[forgot_email]": "Ubacite E-Mail",
			},
			errorClass: 'errorClassLogin',
		});
	
	}
	
	
	if (jQuery('#tx_cfrsproduct_pi6_checkout_form').length) {
	
		// VALIDATE REGISTRATION FORM
		
		jQuery('#tx_cfrsproduct_pi6_checkout_form').validate({
		
			rules: {
			
				"tx_cfrsproduct_pi6[checkout_form][accepts]": "required",
			
				"tx_cfrsproduct_pi6[checkout_form][bi_firstname]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_lastname]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_address]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_city]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_postalcode]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_country]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_phone]": "required",
				"tx_cfrsproduct_pi6[checkout_form][bi_mail]":  {
					required: true,
					email: true
				},
				"tx_cfrsproduct_pi6[checkout_form][si_firstname]": {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_lastname]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_address]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_city]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_postalcode]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_country]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
				"tx_cfrsproduct_pi6[checkout_form][si_phone]":  {
					required: function(element) {
						return $("input:checkbox[name='tx_cfrsproduct_pi6[checkout_form][shiptothisaddr]']:checked").val() == undefined;
					}
				},
			
			},
			messages: {
				"tx_cfrsproduct_pi6[checkout_form][bi_firstname]":  "Upišite Vaše ime",
				"tx_cfrsproduct_pi6[checkout_form][bi_lastname]": "Upišite Vaše prezime",
				"tx_cfrsproduct_pi6[checkout_form][bi_address]": "Upišite Vašu adresu",
				"tx_cfrsproduct_pi6[checkout_form][bi_city]": "Upišite Vaš grad",
				"tx_cfrsproduct_pi6[checkout_form][bi_postalcode]": "Upišite Vaš poštanski broj",
				"tx_cfrsproduct_pi6[checkout_form][bi_country]": "Upišite Vašu državu",
				"tx_cfrsproduct_pi6[checkout_form][bi_phone]": "Upišite Vaš broj telefona",
				"tx_cfrsproduct_pi6[checkout_form][bi_mail]": "Upišite validan E-Mail",
				"tx_cfrsproduct_pi6[checkout_form][si_firstname]": "Upišite Vaše ime",
				"tx_cfrsproduct_pi6[checkout_form][si_lastname]": "Upišite Vaše prezime",
				"tx_cfrsproduct_pi6[checkout_form][si_address]": "Upišite Vašu adresu",
				"tx_cfrsproduct_pi6[checkout_form][si_city]": "Upišite Vaš grad",
				"tx_cfrsproduct_pi6[checkout_form][si_postalcode]": "Upišite Vaš poštanski broj",
				"tx_cfrsproduct_pi6[checkout_form][si_country]": "Upišite Vašu državu",
				"tx_cfrsproduct_pi6[checkout_form][si_phone]": "Upišite Vaš broj telefona",
				"tx_cfrsproduct_pi6[checkout_form][accepts]": "Ako želite kupiti morate potvrditi uslove kupovine.",
			},
			errorClass: 'errorClassLogin',
		
		});
	}
	
	
	if (jQuery('#tx-srfeuserregister-pi1-fe_users_form').length) {
	
		jQuery("#tx-srfeuserregister-pi1-fe_users_form").validate({
			rules: {
				"FE[fe_users][username]":  {
					required: true,
					minlength: 6,
				},
				"FE[fe_users][password]": {
					required: true,
					minlength: 6,
				},
				
				"FE[fe_users][password_again]": {
					required: true,
					minlength: 6,
					equalTo: "#tx-srfeuserregister-pi1-password",
				},
				
				"FE[fe_users][tx_ssmfenewsletter_company]": {
					required: function() {
						return jQuery('input#tx-srfeuserregister-pi1-company_check:checked').val() == "1"; 
					}
				},
				"FE[fe_users][tx_ssmfenewsletter_pib]": {
					required: function(element) {
						return jQuery('input#tx-srfeuserregister-pi1-company_check:checked').val() == "1"; 
					}
				},
				"FE[fe_users][first_name]": "required",
				"FE[fe_users][last_name]": "required",
				"FE[fe_users][telephone]": "required",
				"FE[fe_users][email]": {
					required: true,
					email: true,
				},
				"FE[fe_users][tx_ssmfenewsletter_tos]": "required",
			},
			messages: {
				"FE[fe_users][username]": "Ubacite željeno korisničko ime",
				"FE[fe_users][password]": {
					required: "Ubacite željenu lozinku (najmanje šest znaka)",
					minlength: "Vaša lozinka mora imati najmanje šest znaka",
				},
				"FE[fe_users][password_again]": {
					required: "Ponovite željenu lozinku (najmanje šest znaka)",
					minlength: "Vaša lozinka mora imati najmanje šest znaka",
					equalTo: "Ponovite željenu lozinku (velika i mala slova se razlikuju)"
				},
				"FE[fe_users][tx_ssmfenewsletter_company]": "Ubacite ime Vaše firme",
				"FE[fe_users][tx_ssmfenewsletter_pib]": "Ubacite PIB Vaše firme",
				"FE[fe_users][first_name]": "Ubacite Vaše ime",
				"FE[fe_users][last_name]": "Ubacite Vaše prezime",
				"FE[fe_users][telephone]": "Ubacite broj telefona",
				"FE[fe_users][email]": "Ubacite važeću e-mail adresu",
				"FE[fe_users][tx_ssmfenewsletter_tos]": "Potvrdite da ste saglasni sa našim uslovima korišćenja",
			},
			errorClass: 'tx-srfeuserregister-pi1-error',
		});
	
	}
	
	
	if (jQuery('#cfrs_ambients_mailform').length) {
	
		jQuery('#cfrs_ambients_mailform').validate({
			rules: {
				'tx_cfrsambients[name]': "required",
				'tx_cfrsambients[message]': "required",
				'tx_cfrsambients[email]': {
					required: true,
					email: true,
				},
			},
			messages: {
				'tx_cfrsambients[name]': "Ime je neophodno",
				'tx_cfrsambients[message]': "Dodajte komentar",
				'tx_cfrsambients[email]': "Ubacite važeću e-mail adresu",
			},
			errorClass: 'errorClass',
			submitHandler: function() {
	 
				var emailVal = $("#tx_cfrsambients_email").val();
				var nameVal = $("#tx_cfrsambients_name").val();
				var messageVal = $("#tx_cfrsambients_message").val();
				var errorVal = $("#tx_cfrsambients_error").val();
				var successVal = $("#tx_cfrsambients_success").val();
				var subjectVal = $("#tx_cfrsambients_subject").val();
				var messagesystemVal = $("#tx_cfrsambients_message-system").val();
				var pagepathVal = $("#tx_cfrsambients_pagepath").val();
				var ambientnameVal = $("#tx_cfrsambients_ambientname").val();				
				 
				  jQuery.ajax({
					url: "index.php?eID=cfrs_ambients_sendmail",
					type: "POST",		
					data: { email: emailVal, message: messageVal, name: nameVal, error: errorVal, success: successVal, subject: subjectVal, messagesystem: messagesystemVal, pagepath:pagepathVal, ambientname:ambientnameVal },
					success: function (reqCode) {
						jQuery("#cfrs_ambients_mailform").fadeOut("normal", function() {
							jQuery("#cfrs_ambients_mailform").before(reqCode);
						});
					}
				});
				 
				return false;
			}
			
		});
	
	}
	
	
	
	if (jQuery('#cfrs_product_collectionmailform').length) {
	
		jQuery('#cfrs_product_collectionmailform').validate({
			rules: {
				'tx_cfrsproduct_collection[name]': "required",
				'tx_cfrsproduct_collection[message]': "required",
				'tx_cfrsproduct_collection[email]': {
					required: true,
					email: true,
				},
			},
			messages: {
				'tx_cfrsproduct_collection[name]': "Ime je neophodno",
				'tx_cfrsproduct_collection[message]': "Dodajte komentar",
				'tx_cfrsproduct_collection[email]': "Ubacite važeću e-mail adresu",
			},
			errorClass: 'errorClass',
			submitHandler: function() {
	 
				var emailVal = $("#tx_cfrsproductcollection_email").val();
				var nameVal = $("#tx_cfrsproductcollection_name").val();
				var messageVal = $("#tx_cfrsproductcollection_message").val();
				var errorVal = $("#tx_cfrsproductcollection_error").val();
				var successVal = $("#tx_cfrsproductcollection_success").val();
				var subjectVal = $("#tx_cfrsproductcollection_subject").val();
				var messagesystemVal = $("#tx_cfrsproductcollection_message-system").val();
				var pagepathVal = $("#tx_cfrsproductcollection_pagepath").val();
				var collectionnameVal = $("#tx_cfrsproductcollection_collectionname").val();				
				 
				  jQuery.ajax({
					url: "index.php?eID=cfrs_product_sendmail",
					type: "POST",		
					data: { email: emailVal, message: messageVal, name: nameVal, error: errorVal, success: successVal, subject: subjectVal, messagesystem: messagesystemVal, pagepath:pagepathVal, collectionname:collectionnameVal },
					success: function (reqCode) {
						jQuery("#cfrs_product_collectionmailform").fadeOut("normal", function() {
							jQuery("#cfrs_product_collectionmailform").before(reqCode);
						});
					}
				});
				 
				return false;
			}
			
		});
	
	}
	
	
	
	if (jQuery('.share-container').length) {
	
		jQuery('.share-container').click(
			function() {
				jQuery('.cfrs_share_form').slideToggle();
			});
			
	}
	
	
	
	
	
	if (jQuery('#cfrs_share_mailform').length) {
	
		jQuery('#cfrs_share_mailform').validate({
			rules: {
				'tx_cfrs[label_1]':  {
					required: true,
					email: true,
				},
				'tx_cfrs[label_2]':  {
					required: true,
					email: true,
				},
			},
			messages: {
				'tx_cfrs[label_1]': "Ubacite E-Mail osobe kojoj želite poslati komentar",
				'tx_cfrs[label_2]': "Ubacite Vaš tačan E-Mail",
			},
			errorClass: 'errorClass',
			submitHandler: function() {
	 
				var email1Val = $("#tx_cfrslabel_1").val();
				var email2Val = $("#tx_cfrslabel_2").val();
				var messageVal = $("#tx_cfrslabel_message").val();
				var errorVal = $("#tx_cfrs_error").val();
				var successVal = $("#tx_cfrs_success").val();
				var subjectVal = $("#tx_cfrs_subject").val();
				var messagesystemVal = $("#tx_cfrs_message-system").val();
				var pagepathVal = $("#tx_cfrs_pagepath").val();			
				 
				  jQuery.ajax({
					url: "index.php?eID=cfrs_share_sendmail",
					type: "POST",		
					data: { email1: email1Val, email2: email2Val, message: messageVal, error: errorVal, success: successVal, subject: subjectVal, messagesystem: messagesystemVal, pagepath:pagepathVal },
					success: function (reqCode) {
						jQuery("#cfrs_share_mailform").fadeOut("normal", function() {
							jQuery("#cfrs_share_mailform").before(reqCode);
						});
					}
				});
				 
				return false;
			}
			
		});
	
	}
	
	
	if (jQuery('input#tx-srfeuserregister-pi1-company').val() != "") {
		jQuery('.hide-if-no-company').removeClass('hide-if-no-company');
	}
	
	
	var default_searchinputfield = jQuery('.searchinputfield').val();
	
    jQuery('.searchinputfield').focus(function() {
        if(this.value == default_searchinputfield) {
            this.value = '';
        }
    });
    jQuery('.searchinputfield').blur(function() {
        if(this.value == '') {
            this.value = default_searchinputfield;
        }
    });
	
    jQuery('#tx-indexedsearch-searchbox-sword').focus(function() {
        if(this.value == default_searchinputfield) {
            this.value = '';
        }
    });
    jQuery('#tx-indexedsearch-searchbox-sword').blur(function() {
        if(this.value == '') {
            this.value = default_searchinputfield;
        }
    });
    
    
	var default_messagefield = jQuery('#tx_cfrsambients_message').val();
	
    jQuery('#tx_cfrsambients_message').focus(function() {
        if(this.value == default_messagefield) {
            this.value = '';
        }
    });
    jQuery('#tx_cfrsambients_message').blur(function() {
        if(this.value == '') {
            this.value = default_messagefield;
        }
    });
    
    
	var default_collectionsmessagefield = jQuery('#tx_cfrsproductcollection_message').val();
	
    jQuery('#tx_cfrsproductcollection_message').focus(function() {
        if(this.value == default_collectionsmessagefield) {
            this.value = '';
        }
    });
    jQuery('#tx_cfrsproductcollection_message').blur(function() {
        if(this.value == '') {
            this.value = default_collectionsmessagefield;
        }
    });
    
    
	
});

