/// <reference path="jquery-1.5.min.js" />

function SelectProductSize(spec) {
	var fieldName = spec.replace(",5", "_5");
	$("a[id^=spec_]").removeClass("active");
	$("#spec_" + fieldName.toString()).addClass("active");
	document.getElementById("spec").value=spec;
}

function AddToCart(dimension, lang) {
//	if spec<>"" or dimension=false then
	var spec = document.getElementById("spec");
	if (spec.value!="" || dimension==false) {
		document.forms['frmProduct'].submit();
	}
	else {
		if (lang == "SI") {
			alert("Prosimo izberite velikost.");
		}
		else {
			alert("Bitte wählen Sie eine Größe.");
		}
	}
}


function updateCart(id) {
	var q = document.getElementById("q_" + id.toString()).value;
	var url = "default.asp?tn=cart&cmd=update&id=" + id.toString() + "&q=" + q;
	window.location = url;
}

function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function uredibesedilo(n){
	MM_openBrWindow('http://admin.prva-liga.si/admin/LANG_BESEDILA_VIEW_EDIT_HTML.ASP?lang=<%=default_lang%>&close=1&id='+n,'edit','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600');
}

function ToggleCoupon() {
	$('.cartCupon').hide();
	$('.cartCuponBox').show();
}

function SwitchCustomerForm() {
	$('.companyFields').hide();		// hide fields
	$('#companyForm').show();		// show company link
	$('#customerForm').hide();		// hide customer link
}

function SwitchCompanyForm() {
	$('.companyFields').show();		// show fields
	$('#companyForm').hide();		// hide company link
	$('#customerForm').show();		// show customer link
}

function validate_cart() {
	var err_msg='';
	var err=false;
	if (document.forms["frmCartOrder"].ime.value.length < 3) {
		err_msg+='- ime ni pravilno vnešeno\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].priimek.value.length < 3) {
		err_msg+='- priimek ni pravilno vnešen\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].naslov.value.length < 5) {
		err_msg+='- naslov ni pravilno vnešen\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].posta.value == '') {
		err_msg+='- pošta ni vnešena\n';
		err=true;
	}
	var postna_st = parseInt(document.forms["frmCartOrder"].postna_st.value);
	if (isNaN(postna_st)) {
		err_msg+='- poštna številka ni pravilno vnešena\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].tel.value == '') {
		err_msg+='- telefon ni vnešen\n';
		err=true;
	}
	var p=document.forms["frmCartOrder"].email.value.indexOf('@');
	if (p<1 || p==(document.forms["frmCartOrder"].email.value.length-1)) {
		err_msg+='- e-mail ni pravilno vnešen.\n';
		err=true;
	}
	/* checkbox strinjam */
	if (document.forms["frmCartOrder"].seznanjen.checked == false) {
		err_msg+='- Za nadajevanje nakupa morate sprejeti pogoje\n';
		err=true;
	}
	/* radio button - tip plačila */
	var len=document.forms["frmCartOrder"].placilo.length;
	var sel=false;
	for (i = 0; i < len; i++) {
		if (document.forms["frmCartOrder"].placilo[i].checked) {
			/*chosen = document.forms["frm_order"].poption[i].value;*/
			sel=true;
		}
	}
	if (sel == false) {
		err_msg+='- Izbrati morate tip plačila\n';
		err=true;
	}

	if (err == true) {
		alert('Napaka pri oddaji naročila:\n' + err_msg);
		return false;
	}
	else {
		//document.forms["frmCartOrder"].submit();
		return true;
	}
}

function validate_cart_de() {
	var err_msg='';
	var err=false;
	if (document.forms["frmCartOrder"].ime.value.length < 3) {
		err_msg+='- Vorname nicht angegeben\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].priimek.value.length < 3) {
		err_msg+='- Nachname nicht angegeben\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].naslov.value.length < 5) {
		err_msg+='- Straße nicht angegeben\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].posta.value == '') {
		err_msg+='- Ort nicht angegeben\n';
		err=true;
	}
	var postna_st = parseInt(document.forms["frmCartOrder"].postna_st.value);
	if (isNaN(postna_st)) {
		err_msg+='- Postleitzahl nicht angegeben\n';
		err=true;
	}
	if (document.forms["frmCartOrder"].tel.value == '') {
		err_msg+='- Telefonnummer nicht angegeben\n';
		err=true;
	}
	var p=document.forms["frmCartOrder"].email.value.indexOf('@');
	if (p<1 || p==(document.forms["frmCartOrder"].email.value.length-1)) {
		err_msg+='-  E-Mail-Adresse ist nicht korrekt eingegeben\n';
		err=true;
	}
	/* checkbox strinjam */
	if (document.forms["frmCartOrder"].seznanjen.checked == false) {
		err_msg+='- Za nadajevanje nakupa morate sprejeti pogoje\n';
		err=true;
	}
	if (sel == false) {
		err_msg+='- Izbrati morate tip plačila\n';
		err=true;
	}

	if (err == true) {
		alert('Napaka pri oddaji naročila:\n' + err_msg);
		return false;
	}
	else {
		//document.forms["frmCartOrder"].submit();
		return true;
	}
}

function equalHeights(className) {
	var currentTallest = 0;
	jQuery('.' + className).each(function() {
		if (jQuery(this).height() > currentTallest) 
			currentTallest = jQuery(this).height();
	});
	
	jQuery('.' + className).height(currentTallest);
}

jQuery.fn.equalHeights = function(px) {
	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) 
			currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'height': currentTallest}); }
		jQuery(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

// PX to EM

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};




function EmailSignupFormTextBoxClick( elementId){
	
	
	var textBoxValue=$('#' +elementId ).val();
	
	if (textBoxValue.search('@')==-1 ){

	    $('#' + elementId).val('');

        
	}
}

function SearchButton() {

    if ($('#searchTextBox').val() != '') {

        $('#serchForm').submit();
    }
}
