function submitForm(frm)
{
    s = frm.code.value.split("_");
    frm.sort.value = s[0];
    frm.sort_type.value = s[1];
    frm.code.value = "";
    frm.submit();
}

function showDesc(id1, id2)
{
	var block1 = document.getElementById(id1);
	var block2 = document.getElementById(id2);
	
	block1.style.display = 'block';
	block2.style.display = 'none';
}



function MM_findObj(n, d) 
{ 
    var p,i,x; 
    if(!d) d=document; 
    if((p=n.indexOf("?"))>0&&parent.frames.length) 
    {
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n]; 
    for (i=0;!x&&i<d.forms.length;i++) 
    {
        x=d.forms[i][n];
    }
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
    {
        x=MM_findObj(n,d.layers[i].document);
    }
    if(!x && document.getElementById) 
    {
        x=document.getElementById(n);
    } 
    return x;
}

function P7_autoLayers() 
{ 
    var g,b,k,f,args=P7_autoLayers.arguments;
    var a = parseInt(args[0]);
    if(isNaN(a)) a=0;
    if(!document.p7setc) 
    {
        p7c=new Array();
        document.p7setc=true;
        for (var u=0;u<10;u++) 
        {
            p7c[u] = new Array();
        }
    }
    for(k=0; k<p7c[a].length; k++) 
    {
        if((g=MM_findObj(p7c[a][k]))!=null) 
        {
            b=(document.layers)?g:g.style;
            b.visibility="hidden";
			b.display="none";
            try
            {
                    document.search_form.search_field.style.visibility = "visible";
            }
            catch (e)
            {
            }
        }
    }
    for(k=1; k<args.length; k++) 
    {
        if((g=MM_findObj(args[k])) != null) 
        {
            b=(document.layers)?g:g.style;
            b.visibility="visible";
			b.display="block";
			//b.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            f=false;
            for(j=0;j<p7c[a].length;j++) 
            {
                if(args[k]==p7c[a][j]) 
                {
                    f=true;
                }
            }
            if(!f) 
            {
                p7c[a][p7c[a].length++]=args[k];
            }
        }
    }
}

function clearFilters()
{
    var frm = document.filters;
    var len = frm.elements.length;
    for (var i = 0; i < len; i++)
    {
	    if (frm.elements(i).options)
	    {
		    frm.elements(i).options(0).selected = true;
	    }
	}
}

function filterFilters()
{
	var frm = document.filters;
	var len = frm.elements.length;
	for (var i = 0; i < len; i++)
	{
		if (frm.elements(i).options)
		{
			if (frm.elements(i).options(0).selected)
			{
				frm.elements(i).disabled = true;
			}
		}
	}
}

function changeProductImageBorder(b)
{
	id = document.getElementById("product-image-large");
	id_link = document.getElementById("under-image-link");
	
	if(b == 1)
	{
		id.style.background = "url(images/product_image_bg_red.gif) no-repeat";
		id_link.style.color = "#FF0000";
		id_link.style.textDecoration = "underline";
	}
	else
	{
		id.style.background = "url(images/product_image_bg.gif) no-repeat";
		id_link.style.color= "#7A7A7A";
		id_link.style.textDecoration = "none";
	}
}

function showListType1(num)
{
	var navSectionName = new Array();
	navSectionName[1] = "price-link";
	navSectionName[2] = "review-link";
	navSectionName[3] = "spec-link";
	navSectionName[4] = "price-link2";
	navSectionName[5] = "review-link2";
	navSectionName[6] = "spec-link2";
	
	var sectionName = new Array();
	sectionName[1] = "price-section";
	sectionName[2] = "review-section";
	sectionName[3] = "spec-section";
	
	for(i = 1; i <= 3; i++)
	{
		if(i == num)
		{
			id = document.getElementById(navSectionName[i + 3]);
			id.style.display = "none";
			id = document.getElementById(navSectionName[i]);
			id.style.display = "";
			id = document.getElementById(sectionName[i]);
			id.style.display = "";
		}
		else
		{
			id = document.getElementById(navSectionName[i]);
			id.style.display = "none";
			id = document.getElementById(navSectionName[i + 3]);
			id.style.display = "";
			id = document.getElementById(sectionName[i]);
			id.style.display = "none";
		}
	}
	
	return 0;
}

function openWindow(url)
{
	window.open(url, "_blank");
}

function changeTopPicksBorder(num, ch)
{
	id_str1 = "top-picks-table1" + num;
	id_str2 = "top-picks-table2" + num;
	id_str3 = "top-picks-table3" + num;
	
	bimages = new Array();
	bimages[0] = "tl_corner";
	bimages[1] = "tr_corner";
	bimages[2] = "bl_corner";
	bimages[3] = "br_corner";
	
	if(ch == 0)
	{
		id = document.getElementById(id_str1);
		id.style.borderTop = "1px solid #FF0000";
		id = document.getElementById(id_str2);
		id.style.borderBottom = "1px solid #FF0000";
		id = document.getElementById(id_str3);
		id.style.borderLeft = "1px solid #FF0000";
		id.style.borderRight = "1px solid #FF0000";
		
		for(i = 0; i < 4; i++)
		{
			idstr = bimages[i] + num;
			id = document.getElementById(idstr);
			id.style.display = "none";
			idstr = bimages[i] + "_red" + num;
			id = document.getElementById(idstr);
			id.style.display = "";
		}
	}
	else
	{
		id = document.getElementById(id_str1);
		id.style.borderTop = "1px solid #CECDCD";
		id = document.getElementById(id_str2);
		id.style.borderBottom = "1px solid #CECDCD";
		id = document.getElementById(id_str3);
		id.style.borderLeft = "1px solid #CECDCD";
		id.style.borderRight = "1px solid #CECDCD";
		
		for(i = 0; i < 4; i++)
		{
			idstr = bimages[i] + num;
			id = document.getElementById(idstr);
			id.style.display = "";
			idstr = bimages[i] + "_red" + num;
			id = document.getElementById(idstr);
			id.style.display = "none";
		}
	}
}

function showCatReviews(id)
{
	var rsection = document.getElementById(id);
	rsection.style.display = '';
}

function hideCatReviews(id)
{
	var rsection = document.getElementById(id);
	rsection.style.display = 'none';
}

function SetCookieForNDays(name, value, days, path, domain, secure)
{
	var today = new Date();
	expires = new Date(today.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) +
                "; expires=" + expires.toGMTString() +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "");
}

function GetCookie(name) 
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) 
	{
		return null;
	}
	if (start == -1) 
	{
		return null;
	}
	var end = document.cookie.indexOf(";", len);
	if (end == -1)
	{
		end = document.cookie.length;
	}
	
	return unescape(document.cookie.substring(len,end));
}

function showTopProducts(url)
{
    var cookieValue = GetCookie("top_product");
    if(!cookieValue)
    {
        SetCookieForNDays("top_product", 1, 1);
        
        popunder = window.open(url, "top_products", "menubar=no, height=660, width=717");
        popunder.blur();
        window.focus();
    }
}

function sendUserListForm(frm, root, id)
{
	var b = true;
	
	if(frm.name.value == "")
	{
		b = false;
		txt = 'Field "name" must not be empty';
	}
	if(frm.email.value == "" && b)
	{
		b = false;
		txt = 'Field "email" must not be empty';
	}
	if(!/^[^@]+@[^@\.]+\.[^@]+$/.test(frm.email.value) && b)
	{
		b = false;
		txt = 'Your email is not correct';
	}
	
    if(b)
	{
		url = root + "support/user_list.php?uid=" + escape(frm.uid.value) + "&kuid=" + escape(frm.kuid.value) + "&url=" + escape(frm.url.value) + "&name=" + escape(frm.name.value) + "&email=" + escape(frm.email.value);
		data = getURL(url);
		
		if(data == "ok")
		{
			frm.name.value = "";
			frm.email.value = "";
		}
		
		id = document.getElementById(id);
		id.style.color = "#636363";
		id.innerHTML = "Your email was added in our database";
		id.style.display = "block";
	}
	else
	{
		id = document.getElementById(id);
		id.style.color = "#FF0000";
		id.innerHTML = txt;
		id.style.display = "block";
	}
}

function getURL(url)
{
    var request = false;

    if (window.XMLHttpRequest)
    {
	    request = new XMLHttpRequest();
    }
    else
    {
	    if (window.ActiveXObject)
	    {
		    try
		    {
			    request = new ActiveXObject("Msxml2.XMLHTTP");
		    }
		    catch (e)
		    {
			    try
			    {
				    request = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			    catch (e)
			    {
			    }
		    }
	    }
    }

    if (request)
    {
	    request.open("GET", url, false);
	    request.send(null);
	    if (request.status == 200)
	    {
		    var data = request.responseText;
		    return data;
	    }
    }
}

function modifyBrandSectionTimer()
{
	var timer = setTimeout("modifyBrandSection()", 5000);
}

function modifyBrandSection()
{
	if(block = document.getElementById("brand-section"))
	{
		block.style.display = "";
	}
	if(block = document.getElementById("price-message-first"))
	{
		block.style.display = "";
	}
	if(block = document.getElementById("price-message-second"))
	{
		block.style.display = "none";
	}
}

function showSection(id)
{
	var elem;
	
	if (elem = document.getElementById(id))
	{
		if(elem.style.display == "none")
		{
			elem.style.display = "";
		}
		else
		{
			elem.style.display = "none";
		}
	}
}

function showPreloader()
{
	idSpacer = document.getElementById("divSpacer");
	id_flow = document.getElementById("wrapJsiBox");
	idForm = document.getElementById("jsiMainBox");
	
	id_flow.style.height = idSpacer.offsetTop + 10;
	id_flow.style.display = '';
	
	idForm.style.left = (document.body.clientWidth / 2 - 229) + "px";
	idForm.style.top = (document.body.scrollTop + document.body.clientHeight / 2 - 94) + "px";
	idForm.style.display = '';
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		changeAllSelectDisabled("hidden");
	}
	
	runLoader = true;
	setTimeout("animateLoading()", 900);
	setTimeout("hidePreloader()", 10000);
}

function changeAllSelectDisabled(vis)
{
	var coll = document.all.tags("SELECT");
	if (coll.length > 0)
	{
		for (i = 0; i < coll.length; i++)
		{
			coll.item(i).style.visibility = vis;
		}
	}
}

var showImgNum = 0;
var runLoader = false;
var ids = new Array();
ids[0] = "lt1";
ids[1] = "lt2";
ids[2] = "lt3";
ids[3] = "lt4";
ids[4] = "lt5";
ids[5] = "lt6";
ids[6] = "lt7";
ids[7] = "lt8";

function animateLoading()
{
	if (showImgNum < 8)
	{
		obj = document.getElementById(ids[showImgNum]);
		obj.style.backgroundColor = "#ff6500";
		showImgNum++;
	}
	else
	{
		showImgNum = 0;
		for (i = 0; i < 8; i++)
		{
			obj = document.getElementById(ids[i]);
			obj.style.backgroundColor = "#b3b3b3";
		}
	}
	
	if (runLoader)
	{
		setTimeout("animateLoading()", 150);
	}
}

function hidePreloader()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		changeAllSelectDisabled("visible");
	}
	
	runLoader = false;
	showImgNum = 0;
	for (i = 0; i < 8; i++)
	{
		obj = document.getElementById(ids[i]);
		obj.style.backgroundColor = "#b3b3b3";
	}
	
	id_flow = document.getElementById("wrapJsiBox");
	idForm = document.getElementById("jsiMainBox");
	id_flow.style.display = 'none';
	idForm.style.display = 'none';
}

