function gen_pasts(prefix,postfix){
	if (prefix!='' && postfix!='')
	{
		var pasts=prefix;
			pasts=pasts+'@';
			pasts=pasts+postfix;
		document.write('<a href="mailto:'+pasts+'">'+pasts+'</a>');
	}
	else document.write('-');
};
function cart_add(product,amount,coment,replace) {
	//izsauc no group_child
	postToURL(window.location.href,{
									'add_to_cart':'true',
									'product':product,
									'amount':amount,
									'coment':coment,
									'replace':replace
									});
}
function search() {
	var keyword=document.getElementById('search_field').value;
	if(keyword=='meklēt...') return false;
	postToURL('/meklesanas_rezultati',{
									'keyword':keyword
									});
}
function search_enter(e) {
	if (e.keyCode == 13) {
			search();
		}
}
function cart_add2(product,amount,coment,replace) {
	//izsauc no product
	postToURL(window.location.href,{
									'add_to_cart':'true',
									'product':product,
									'amount':amount,
									'coment':coment,
									'replace':replace
									});
	
}
function cart_add3(product,amount,coment,replace,keyword) {
	//izsauc no search
	postToURL(window.location.href,{
									'add_to_cart':'true',
									'product':product,
									'amount':amount,
									'coment':coment,
									'replace':replace,
									'keyword':keyword
									});
}
function cart_delete(product) {
	//izsauc no group_child
	postToURL(window.location.href,{
									'cart_delete':'true',
									'product':product
									});
}
function cart_clear() {
	var text="Vai tiešām vēlaties iztukšot iepirkumu grozu?";
	if(confirm(text)) {
		postToURL(window.location.href,{
									'cart_clear':'true'
									});
	}
}
function order_show_form() {
	var delivery_mode_1_wrap=document.getElementById('delivery_mode_1_wrap');
	var delivery_mode_2_wrap=document.getElementById('delivery_mode_2_wrap');
	var order_contacts=document.getElementById('order_contacts');
	var delivery_mode_1=document.getElementById('delivery_mode_1');
	var delivery_mode_2=document.getElementById('delivery_mode_2');
	var order_submit=document.getElementById('order_submit');

	delivery_mode_1_wrap.style.display="none";
	delivery_mode_2_wrap.style.display="none";
	order_contacts.style.display="none";
	order_submit.style.display="none";
		
	if(delivery_mode_1.checked) {
		delivery_mode_1_wrap.style.display="block";
		delivery_mode_2_wrap.style.display="none";
		order_contacts.style.display="block";
		order_submit.style.display="block";
	}
	if(delivery_mode_2.checked) {
		delivery_mode_1_wrap.style.display="none";
		delivery_mode_2_wrap.style.display="block";
		order_contacts.style.display="block";
		order_submit.style.display="block";
	}
}
function postToURL(url, values){
    values = values || {};

    var form = createElement("form", {action: url,
                                      method: "POST",
                                      style: "display: none"});
    for (var property in values)
    {
        if (values.hasOwnProperty(property))
        {
            var value = values[property];
            if (value instanceof Array)
            {
                for (var i = 0, l = value.length; i < l; i++)
                {
                    form.appendChild(createElement("input", {type: "hidden",
                                                             name: property,
                                                             value: value[i]}));
                }
            }
            else
            {
                form.appendChild(createElement("input", {type: "hidden",
                                                         name: property,
                                                         value: value}));
            }
        }
    }
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}
var createElement = (function(){
    // Detect IE using conditional compilation
    if (/*@cc_on @*//*@if (@_win32)!/*@end @*/false)
    {
        // Translations for attribute names which IE would otherwise choke on
        var attrTranslations =
        {
            "class": "className",
            "for": "htmlFor"
        };

        var setAttribute = function(element, attr, value)
        {
            if (attrTranslations.hasOwnProperty(attr))
            {
                element[attrTranslations[attr]] = value;
            }
            else if (attr == "style")
            {
                element.style.cssText = value;
            }
            else
            {
                element.setAttribute(attr, value);
            }
        };

        return function(tagName, attributes)
        {
            attributes = attributes || {};

            // See http://channel9.msdn.com/Wiki/InternetExplorerProgrammingBugs
            if (attributes.hasOwnProperty("name") ||
                attributes.hasOwnProperty("checked") ||
                attributes.hasOwnProperty("multiple"))
            {
                var tagParts = ["<" + tagName];
                if (attributes.hasOwnProperty("name"))
                {
                    tagParts[tagParts.length] =
                        ' name="' + attributes.name + '"';
                    delete attributes.name;
                }
                if (attributes.hasOwnProperty("checked") &&
                    "" + attributes.checked == "true")
                {
                    tagParts[tagParts.length] = " checked";
                    delete attributes.checked;
                }
                if (attributes.hasOwnProperty("multiple") &&
                    "" + attributes.multiple == "true")
                {
                    tagParts[tagParts.length] = " multiple";
                    delete attributes.multiple;
                }
                tagParts[tagParts.length] = ">";

                var element =
                    document.createElement(tagParts.join(""));
            }
            else
            {
                var element = document.createElement(tagName);
            }

            for (var attr in attributes)
            {
                if (attributes.hasOwnProperty(attr))
                {
                    setAttribute(element, attr, attributes[attr]);
                }
            }

            return element;
        };
    }
    // All other browsers
    else
    {
        return function(tagName, attributes)
        {
            attributes = attributes || {};
            var element = document.createElement(tagName);
            for (var attr in attributes)
            {
                if (attributes.hasOwnProperty(attr))
                {
                    element.setAttribute(attr, attributes[attr]);
                }
            }
            return element;
        };
    }
})();
function getY( oElement ){
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
function getX( oElement ){
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

