function reloadImage(sAnid, sColor, url) {
/*
	$("#imageContainer").ajaxStart(function(){
   		$(this).addClass("loading");
   		$(this).html("<div align='center'><div style='height:100px;'></div><img src='"+$("#sImagesDir").val()+"/loading.gif' width='32' height='32' alt='' /></div>");
 	});
 	
 	$("#imageContainer").ajaxStop(function(){
   		$(this).removeClass("loading");
 	});
*/
	$.ajax({
		url: url,
		data: { "anid": sAnid, "color": sColor, "cl": "ajax_loadpics"},
		cache: true,
		success: function(html){
			$("#imageContainer").html(html);
		}
	});
}

deleteAddress = function(url, value) {
	if(value.length == 0) {
		return false;
	}
	
	$.ajax({
		url: url + "&fnc=deleteAddress",
		data: { "oxid": value },
		cache: false,
		success: function(html){
			document.location.href = url;
		}
	});
}

selectWShipping = function(url) {
	var value = 0;
	if($('#wship').fieldValue().length > 0) {
		value = 1;
	}

	$.ajax({
		url: url + "&fnc=selectWShipping",
		data: { "value": value },
		cache: false,
		success: function(html){
			document.location.href = url;
		}
	});
}

removeGiftMoney = function(url, oxid) {
	$.ajax({
		url: url + "&fnc=removeGiftMoney",
		data: { "value": oxid },
		cache: false,
		success: function(html){
			document.location.href = url;
		}
	});
}

checkGiftMoneyForm = function()
{
	if($('#isGiftMoneyForm').val() == '0') {
		return true;
	}
	
	var emptyFields = new Array();
	
	if($("#registrationForm [@name='question1']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "1";
	}
	if($("#registrationForm [@name='question2a']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "2a";
	}
	if($("#registrationForm [@name='question2b']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "2b";
	}
	if($("#registrationForm [@name='question3[]']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "3";
	}
	if($("#registrationForm [@name='question4']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "4";
	}
	if($("#registrationForm [@name='question5']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "5";
	}
	if($("#registrationForm [@name='question6a']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6a";
	}
	if($("#registrationForm [@name='question6b']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6b";
	}
	if($("#registrationForm [@name='question6c']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6c";
	}
	if($("#registrationForm [@name='question6d']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6d";
	}
	if($("#registrationForm [@name='question6e']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6e";
	}
	if($("#registrationForm [@name='question6f']").fieldValue() == 0) {
		emptyFields[emptyFields.length] = "6f";
	}
	if($("#registrationForm [@name='question7']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "7";
	}
	if($("#registrationForm [@name='question8']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "8";
	}
	if($("#registrationForm [@name='question9']").fieldValue() == "") {
		emptyFields[emptyFields.length] = "9";
	}
	
	if(emptyFields.length > 0) {
		var emptyFieldsList = emptyFields.join(", ");
		alert("Atsakykite anketos klausimus: " + emptyFieldsList);
		return false;
	}
	
	return true;
}

function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
    // 
    // To validate, we can access the DOM elements directly and return true 
    // only if the values of both the username and password fields evaluate 
    // to true 
 	alert("validate");
    var form = jqForm[0]; 
    if (!form.question1.value || !form.question2a.value) { 
        alert('Please enter a value for both Username and Password'); 
        return false; 
    } 
    alert('Both fields contain values.'); 
}

testNumber = function(value) {
	var value = parseInt(value);
	if(isNaN(value)) {
		value = 0;
	}
	return value;
}

filterBrand = function(oxid, cnid, url, rootcl) {
	var value = 1;
	if($("#vendor_" + oxid).hasClass("on")) {
		$("#vendor_" + oxid).removeClass("on");
		value = 0;
	}else{
		$("#vendor_" + oxid).addClass("on");
	}
	
	$("#rootItemsBlock").ajaxStart(function(){
   		$(this).addClass("loading");
   		$(this).html("<div align='center'><div style='height:100px;'></div><img src='"+$("#sImagesDir").val()+"/loading.gif' width='32' height='32' alt='' /></div>");
 	});
 	
 	$("#rootItemsBlock").ajaxStop(function(){
   		$(this).removeClass("loading");
 	});
 	
 	
	$.ajax({
		url: url,
		data: { "type": "brand", "vendor": oxid, "value": value, "cnid": cnid, "cl": "filterarticlelist", "rootcl": rootcl, "searchparam": $("#searchparam").val() },
		cache: false,
		success: function(html){
			$("#rootItemsBlock").html(html);
		}
	});
}

filterPrice = function(cnid, url, rootcl) {
	var priceFrom = parseInt($("#priceFilterFrom").val());
	var priceTo = parseInt($("#priceFilterTo").val());
	
	var bSearch= parseInt($("#bSearch").val());
	
	// if need ajax
	if (bSearch == 1)
	{
    	$("#rootItemsBlock").ajaxStart(function(){
       		$(this).addClass("loading");
       		$(this).html("<div align='center'><div style='height:100px;'></div><img src='"+$("#sImagesDir").val()+"/loading.gif' width='32' height='32' alt='' /></div>");
     	});
     	
     	$("#rootItemsBlock").ajaxStop(function(){
       		$(this).removeClass("loading");
     	});
     	
     	
    	$.ajax({
    		url: url,
    		data: { "bSearch": bSearch, "type": "price", "from": priceFrom, "to": priceTo, "cnid": cnid, "cl": "filterarticlelist", "rootcl": rootcl, "searchparam": $("#searchparam").val() },
    		cache: false,
    		success: function(html){
    			$("#rootItemsBlock").html(html);
    		}
    	});
	}
}

function changePicker(id, color, cnid, url, rootcl){
    var value = 1;
    
    if($("#colorBlock-"+id).hasClass("selected")) 
    {
        value = 0;
    }
        
    $("#rootItemsBlock").ajaxStart(function(){
   		$(this).addClass("loading");
   		$(this).html("<div align='center'><div style='height:100px;'></div><img src='"+$("#sImagesDir").val()+"/loading.gif' width='32' height='32' alt='' /></div>");
 	});
 	
 	
 	
 	$("#rootItemsBlock").ajaxStop(function(){
   		$(this).removeClass("loading");
 	});
 	
 	
 	
 	$.ajax({
		url: url,
		data: { "bSearch" : true, "type": "color", "color": color, "value": value, "cnid": cnid, "cl": "filterarticlelist", "rootcl": rootcl, "searchparam": $("#searchparam").val() },
		cache: false,
		success: function(html){
			$("#rootItemsBlock").html(html);
	        if($("#colorBlock-"+id).hasClass("selected")) 
            {
                $("#colorBlock-"+id).removeClass("selected");
            }
            else
            {
                $("#colorBlock-"+id).addClass("selected");
            }
		}
	});
}

function changePickerHeader(id, color, cnid, url, rootcl){
    var value = 1;
    if($("#colorBlock-"+id).hasClass("selected")) 
    {
    	$("#colorBlock-"+id).removeClass("selected");
    	value = 0;
        $("input#color-"+id).val('');
    }
    else
    {
    	$("#colorBlock-"+id).addClass("selected");
        $("input#color-"+id).val(color);
    }
 
}

function changeSize(id, size, cnid, url, rootcl){
	var value = 1;
	
    if($("#sizeBlock-"+id).hasClass("selected")) 
    {
        value = 0;
    }
            
    $("#rootItemsBlock").ajaxStart(function(){
   		$(this).addClass("loading");
   		$(this).html("<div align='center'><div style='height:100px;'></div><img src='"+$("#sImagesDir").val()+"/loading.gif' width='32' height='32' alt='' /></div>");
 	});
 	
 	$("#rootItemsBlock").ajaxStop(function(){
   		$(this).removeClass("loading");
 	});
 	
 	
 	size = size.replace(/,/, "_");
 	
 	$.ajax({
		url: url,
		data: { "type": "size", "size": size, "value": value, "cnid": cnid, "cl": "filterarticlelist", "rootcl": rootcl, "searchparam": $("#searchparam").val() },
		cache: false,
		success: function(html){
			$("#rootItemsBlock").html(html);
		    if($("#sizeBlock-"+id).hasClass("selected")) 
		    {
                $("#sizeBlock-"+id).removeClass("selected");
            }
            else
            {
                $("#sizeBlock-"+id).addClass("selected");
            }
		}
	});
}

function changeSizeHeader(id, size, cnid, url, rootcl){
	var value = 1;
	
	size = size.replace(/,/, "_");
    if($("#sizeBlock-"+id).hasClass("selected")) 
    {
    	$("#sizeBlock-"+id).removeClass("selected");
    	value = 0;
        $("input#size-"+id).val('');
    	
    }
        else
        {
        	$("#sizeBlock-"+id).addClass("selected");
            $("input#size-"+id).val(size);
        }
}
