var xmlHttp;
var rootpath;
var srootpath;

rootpath = "http://www.ultra-group.co.uk/";   // be sure to change this to your URL
srootpath = "https://www.ultra-group.co.uk/";   // be sure to change this to your URL
rootPath = "/";

var thisHTML = "";
var divTarget = "";

function stockistLogin()
{
    var url=rootpath + "trade-login.asp";

    xmlHttp=GetXmlHttpObject(stateChanged2)
    xmlHttp.open("POST", url , true)
    xmlHttp.send(null)
}

function stateChanged2()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		document.location.href = "trade-account.asp";
     }else{
        document.getElementById("stockistInfo").innerHTML=xmlHttp.responseText
    }
}
 
function getStockistInfo(sDist,sReq,sPcd,sMkm)
{
    // var url=rootpath + "lookup_stockist.asp?sDist="+sDist+"&sReq="+sReq+"&sPcd="+ sPcd+"&sMkm="+ sMkm;
	var url = "lookup_stockist.asp?sDist="+sDist+"&sReq="+sReq+"&sPcd="+ sPcd+"&sMkm="+ sMkm;

    xmlHttp=GetXmlHttpObject(stateChanged);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}
 


function GetXmlHttpObjectB(handler)
{
	if (window.XMLHttpRequest){
		// If IE7, Mozilla, Safari, etc: Use native object
		var xmlHttp = new XMLHttpRequest();
	}
	else
	{
	if (window.ActiveXObject){
			// ...otherwise, use the ActiveX control for IE5.x and IE6
			var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists mz1 . . .</i></b>";
	xmlHttp.onload=handler;
	xmlHttp.onerror=handler;
	
	return xmlHttp;
}

function GetXmlHttpObject(handler)
{
	var objXmlHttp=null;
 	if(window.ActiveXObject)
	{
		//use ActiveX control for IE5.x and IE6
		var strName="";
		strName="Microsoft.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5")<0)
        {
            strName="Msxml2.XMLHTTP";
        }
		document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists . . .</i></b> " + strName;
		xmlHttp=new ActiveXObject(strName);
        xmlHttp.onreadystatechange=handler;
	}else if(window.XMLHttpRequest)
	{
		//for IE7, Mozilla, Safari, etc: use native object
		xmlHttp = new XMLHttpRequest();
		xmlHttp.onload=handler;
		xmlHttp.onerror=handler;
		document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists . . .</i></b>";
	}
 	return xmlHttp;
} 


function stateChanged()
{
	// alert(xmlHttp.readyState)
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById("stockistInfo").innerHTML=xmlHttp.responseText
    }
}

// ----------------------------------------------
//  Get menu items
// ----------------------------------------------
function GetXmlResponse(handler)
{
	var objXmlHttp=null
 	if (navigator.userAgent.indexOf("Opera")>=0)
 	{
		// Firefox, Opera, Safari
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		// document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists . . .</i></b>";
		return objXmlHttp
	}
  
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
          //  document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists . . .</i></b>";
            return objXmlHttp
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled")
            return
        }
    }
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        //document.getElementById("stockistInfo").innerHTML = "<b><i>locating stockists . . .</i></b>";
        return objXmlHttp
    }
} 

function getMenuData(fieldName,targetDiv,targetField)
{
    var whichField = document.getElementById(fieldName).value;
    var url=rootpath + "/includes/pages/get_menu_items.asp?"+fieldName+"="+ whichField;
    if(document.getElementById(fieldName).value != "0")
    {
    //	alert(fieldName+" "+targetDiv+" "+targetField);
		document.getElementById(targetDiv).innerHTML = "<select name='"+targetField+"' id='"+targetField+"'></select>";
		thisHTML = "<select id='"+targetField+"' name='"+targetField+"' onchange='getMenuData(\'"+targetField+"\', \'"+targetDiv+"\',\'"+targetField+"\')'>\n";
		divTarget = targetDiv;
		xmlHttp=GetXmlResponse(stateXmlChanged)
		xmlHttp.open("GET", url , true)
		xmlHttp.send(null)
    }
}
 
function stateXmlChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        //document.getElementById("stockistInfo").innerHTML=xmlHttp.responseText
	thisHTML += xmlHttp.responseText;	// Executing the response from Ajax as Javascript code	
	thisHTML += "</select>";
	document.getElementById(divTarget).innerHTML = thisHTML;
    }
}