document.execCommand("BackgroundImageCache", false, true);

function showSection(id)
{
	var elem;
	
	if (elem = document.getElementById(id))
	{
		if (elem.style.display == "none")
		{
			elem.style.display = "";
		}
		else
		{
			elem.style.display = "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 showBlock(id)
{
	var elem;
	
	if (elem = document.getElementById(id))
	{
        elem.style.display = "block";
	}
}

function hideBlock(id)
{
	var elem;
	
	if (elem = document.getElementById(id))
	{
        elem.style.display = "none";
	}
}

function showContactForm()
{
    showGreyLayer();
    
	if (idForm = document.getElementById("jsiMainBox"))
    {
        if (navigator.appName == "Microsoft Internet Explorer")
        {
            w_h = document.documentElement.clientHeight;
        }
        else
        {
            w_h = window.innerHeight;
        }
        
        idForm.style.left = (document.body.clientWidth / 2 - 350) + "px";
        idForm.style.top = (w_h / 2 - 205) + "px";
        idForm.style.display = '';
        
        document.documentElement.scrollTop = "0px";
    }
}

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;
		}
	}
}

function showGreyLayer()
{
    idSpacer = document.getElementById("divSpacer");
	id_flow = document.getElementById("wrapJsiBox");
    
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        w_h = document.documentElement.clientHeight;
    }
    else
    {
        w_h = window.innerHeight;
    }
    
    if (w_h > (idSpacer.offsetTop + 10))
    {
        id_flow.style.height = w_h + 'px';
    }
    else
    {
        id_flow.style.height = (idSpacer.offsetTop + 10) + 'px';
    }
    
	id_flow.style.display = '';
    
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		changeAllSelectDisabled("hidden");
	}
}

function hideGreyLayer()
{
	id_flow = document.getElementById("wrapJsiBox");
	id_flow.style.display = 'none';
    
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		changeAllSelectDisabled("visible");
	}
}

function closeContactForm()
{
    idForm = document.getElementById("jsiMainBox");
	idForm.style.display = 'none';
    
    obj = document.getElementById("error-message");
    obj.innerHTML = '<b>&nbsp;</b>';
    
    hideGreyLayer();
}

function showExitPop()
{
    showGreyLayer();
    
	if (idForm = document.getElementById("exitPopBox"))
    {
        if (navigator.appName == "Microsoft Internet Explorer")
        {
            w_h = document.documentElement.clientHeight;
        }
        else
        {
            w_h = window.innerHeight;
        }
        
        idForm.style.left = (document.body.clientWidth / 2 - 390) + "px";
        idForm.style.top = (w_h / 2 - 255) + "px";
        idForm.style.display = 'block';
        
        document.documentElement.scrollTop = "0px";
    }
}

function closeExitPop()
{
    idForm = document.getElementById("exitPopBox");
	idForm.style.display = 'none';
    
    hideGreyLayer();
}


function getURL(url)
{
    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 sendContactForm(frm, root)
{
	var isNameCorrect    = true;
	var isEmailCorrect   = true;
	var isCommentCorrect = true;
	var isCaptchaCorrect = true;
	
	var fields = new Array();
	var errors = new Array();
	fields["name"]     = "name-field";
	errors["name"]     = "this information is required";
	fields["email"]    = "email-field";
	errors["email"]    = "please enter valid address";
	fields["comments"] = "comments-field";
	errors["comments"] = "this information is required";
	fields["captcha"]  = "captcha-field";
	errors["captcha"]  = "please try again";
	
	if (frm.name.value == "")
	{
		isNameCorrect = false;
	}
	if (frm.email.value == "" || !(/^[^@]+@[^@\.]+\.[^@]+$/.test(frm.email.value)))
	{
		isEmailCorrect = false;
	}
	if (frm.comments.value == "")
	{
		isCommentCorrect = false;
	}
	if (frm.captcha.value.toLowerCase() != getURL(root + "support/captcha_current.php"))
	{
		isCaptchaCorrect = false;
	}
	
	if (isNameCorrect && isEmailCorrect && isCommentCorrect && isCaptchaCorrect)
	{
        data = getURL(root + "support/contact.php?name=" + escape(frm.name.value) + "&email=" + escape(frm.email.value) + "&comments=" + escape(frm.comments.value));
        
        var obj = document.getElementById("error-message");
		obj.innerHTML = '<b style="color: #1585db;">Thank you for your enquiry. We will endeavour to respond as soon as possible.<br /><br /></b>';
        
        frm.name.value = "";
        frm.email.value = "";
        frm.comments.value = "";
        frm.captcha.value = "";
		
		clearField(fields["name"]);
		clearField(fields["email"]);
		clearField(fields["comments"]);
		clearField(fields["captcha"]);
	}
	else
	{
		var obj = document.getElementById("error-message");
		obj.innerHTML = '<b style="color: #ff0000;">Please check the errors below and try again.<br /><br /></b>';
		
		showFieldStatus(fields["name"], errors["name"], isNameCorrect, root);
		showFieldStatus(fields["email"], errors["email"], isEmailCorrect, root);
		showFieldStatus(fields["comments"], errors["comments"], isCommentCorrect, root);
		showFieldStatus(fields["captcha"], errors["captcha"], isCaptchaCorrect, root);
	}
}

function showFieldStatus(id, error, field_status, root)
{
	var imgs = new Array();
	imgs["ok"]        = new Image;
	imgs["ok"].src    = root + "images/ok_img.gif";
	imgs["error"]     = new Image;
	imgs["error"].src = root + "images/error_img.gif";
	
	var obj = document.getElementById(id);
	if (field_status)
	{
		obj.innerHTML = '<img src="' + root + 'images/ok_img.gif" width="22" height="21" alt="" />';
	}
	else
	{
		obj.innerHTML = '<img src="' + root + 'images/error_img.gif" width="22" height="22" alt="" style="float: left;" />&nbsp;&nbsp;' + error;
	}
}

function clearField(id)
{
    var obj = document.getElementById(id);
    obj.innerHTML = '';
}