//************************************************************************
//** Vaidate Request Brochure
//************************************************************************
function validateEnquiry(){
    var f = document.frmEnquiry;
    var s = '';
    //alert('ere');
    s += validateText(f.title.value, 'Title', false, 2,30);
    s += validateText(f.name.value, 'Name', false, 2,30);
    s += validateText(f.address.value, 'Address', false, 2,30);
    s += validateText(f.postcode.value, 'Postcode', false, 2,30);
    s += validateEmail(f.email.value, 'Email', false, 2,30);
    s += validateText(f.tel.value, 'Telephone', false, 2,30);
    if(s != ''){
        alert(s);    
        return false;
    }
    return true;
}

var http = false;
var ajaxurl = '../ajax.aspx';

function createRequestObject()
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function getProductContent(AreaID)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?ID=" + AreaID + "&Process=ProductContent", true);
        http.onreadystatechange = handleProductContent;
        http.send(null);
    }
}

function handleProductContent()
{
	if(http.readyState == 4)
	{
	    document.getElementById('productContent').innerHTML = http.responseText;
	    document.body.style.cursor = 'default';
	}
	var elem, vis;
    elem = document.getElementById('spinner');
    if(elem != null)
    {
        vis = elem.style;
        if(vis.display != 'none')
        {  
            vis.display = 'none';
        }
    }
}

function getRangeContent(RangeID,GroupID,CatID)
{
    showWait();
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?RID=" + RangeID + "&GID=" + GroupID + "&CID=" + CatID + "&Process=RangeContent", true);
        http.onreadystatechange = handleProductContent;
        http.send(null);
    }
}

function showWait()
{
    document.getElementById('spinner').style.marginLeft = (screen.width / 2);
    document.getElementById('spinner').style.marginTop = (screen.height / 2);
    showDIV('spinner');
}

function getGroupContent(GroupID,CatID)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?GID=" + GroupID + "&CID=" + CatID + "&Process=GroupContent", true);
        http.onreadystatechange = handleProductContent;
        http.send(null);
    }
}

function resetProductContent(CatID,GroupID)
{
	http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?Process=BasicContent&CID=" + CatID + "&GID=" + GroupID, true);
        http.onreadystatechange = handleProductContent;
        http.send(null);
    }
}

function addEnquiry(ProductID)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
        var buttonID = 'enquiry' + ProductID;
        var btn = document.getElementById(buttonID);
        btn.src = '../images/added.jpg';
	    http.open("GET", ajaxurl + "?ProductID=" + ProductID + "&Process=Enquiry", true);
        http.send(null);
       
        var elem = document.getElementsByName('enquiryLink');
        if(elem[0].style != null)
        {
            elem[0].style.backgroundColor = '#CC0000';
        }
        
        document.body.style.cursor = 'default';
    }
}

function IncreaseEnquiry(SessionID,ProductID,QTY)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?ProductID=" + ProductID + "&SessionID=" + SessionID + "&QTY=" + QTY + "&Process=EnquiryUp", true);
        http.onreadystatechange = showEnquiry;
        http.send(null);
    }
}

function DecreaseEnquiry(SessionID,ProductID,QTY)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?ProductID=" + ProductID + "&SessionID=" + SessionID + "&QTY=" + QTY + "&Process=EnquiryDown", true);
        http.onreadystatechange = showEnquiry;
        http.send(null);
    }
}

function removeEnquiry(ProductID)
{
    http = createRequestObject(); 
    if(http)
    {
        document.body.style.cursor = 'wait';
	    http.open("GET", ajaxurl + "?ProductID=" + ProductID + "&Process=EnquiryRemove", true);
        http.onreadystatechange = showEnquiry;
        http.send(null);
    }
}

function showEnquiry()
{
	if(http.readyState == 4)
	{
	    document.getElementById('enquiryTableOuter').innerHTML = http.responseText;
	    document.body.style.cursor = 'default';
	}
}

function showBasicDIV(divName)
{
    document.body.style.cursor = 'wait';
    var elem, vis;
    elem = document.getElementById(divName);
    if(elem != null)
    {
        vis = elem.style;
        if(vis.display == 'none')
        {  
            vis.display = 'block';
        } else
        {
            vis.display = 'none';
        }
    }
    document.body.style.cursor = 'default';
}

var prevDivG = "";
var prevDivR = "";
function showDIV(divName)
{
    document.body.style.cursor = 'wait';
    var elem, vis, elemP, visP;
    elem = document.getElementById(divName);
    if(elem != null)
    {
        vis = elem.style;
        if(vis.display == 'none')
        {  
            vis.display = 'block';
            if(divName.substring(0,5) == "divGr")
            {
                elemP = document.getElementById(prevDivG);
                if(elemP != null)
                {
                    visP = elemP.style;
                    visP.display = 'none';
                      
                }
            }
            if(divName.substring(0,5) == "divRa")
            {
                elemP = document.getElementById(prevDivR);
                if(elemP != null)
                {
                    visP = elemP.style;
                    visP.display = 'none';
                    prevDivR = divName;  
                }  
            }
        } else
        {
            vis.display = 'none';
        }
    }
    if(divName.substring(0,5) == "divGr")
    {
        prevDivG = divName;
    }
    if(divName.substring(0,5) == "divRa")
    {
        prevDivR = divName;
    }
    document.body.style.cursor = 'default';
}

var prevSpanGroup, prevSpanRange, prevSpanProd;
function colourSpan(spanName)
{
    var elem = document.getElementById(spanName);
    elem.className = 'nav-selected';
    
    var prevElem;
    
    if(spanName.substring(0,5) == "spnRa")
    {
        prevElem = document.getElementById(prevSpanRange)
    }
    if(spanName.substring(0,5) == "spnGr")
    {
        prevElem = document.getElementById(prevSpanGroup)
    }
    if(spanName.substring(0,5) == "spnPr")
    {
        prevElem = document.getElementById(prevSpanProd)
    }
            
    if(spanName.substring(0,5) == "spnRa")
    {
        prevSpanRange = spanName;
    }
    if(spanName.substring(0,5) == "spnGr")
    {
        prevSpanGroup = spanName;
        
    }
    if(spanName.substring(0,5) == "spnPr")
    {
        prevSpanProd = spanName;
        
    }
    
    if(prevElem != null)
    {
        prevElem.className = 'nav-un-selected';
    }
}

function cursorOver() {
    document.body.style.cursor = 'pointer';
}

function cursorClear() {
    document.body.style.cursor = 'default';
}

function validateNewletterSubscribe(){
    var f = document.frmNewletterSubscribe
    var s = validateText(f.name.value, 'Name', false, 2, 50);
    s += validateEmail(f.email.value, 'Email', false);
    if(s != ''){
        alert(s);
        return false;
    }
    return true;
}

function openDownloadWindow(url, width, height) {
    wleft = (screen.width - width) / 2;
    wtop = (screen.height / 2) - height;
    win = window.open(url,'newWindow','width=' + width + ',height=' + height + ',left=' + wleft + ',top=' + wtop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no')
}

function openImageWindow(name) {
    width = 300;
    height = 300;
    wleft = (screen.width - width) / 2;
    wtop = (screen.height / 2) - height;
    win = window.open(name,'newWindow','width=' + width + ',height=' + height + ',left=' + wleft + ',top=' + wtop + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=yes')
}