// AJAX  GET
var xmlHttp
xmlHttp=GetXmlHttpObject()

var xmlHttp2
xmlHttp2=GetXmlHttpObject()


function loadMain(strURL)
{
	
	strURL=strURL+"?sid="+Math.random();
//	loadingDiv('txtMain','Loading content...');
	//alert(strURL)
	$.ajax({
        url: strURL,
       // cache: false,
		async: false,
        success: function(data){
        $("#txtMain").html(data);
		pageTracker._trackPageview(strURL);
		
    }
    }); 


}

function setColour(cc)
{
	URL="/guide/coloursystem.asp?cc="+cc+"&sid="+Math.random();
	loadMain(URL);
}



function getContentStr(strURL)
{
document.getElementById('txtContent').innerHTML='Loading...'
	
	$.ajax({
        url: strURL,
        //cache: false,
        success: function(data){
        $("#txtContent").html(data);
    }
    }); 


}

function getContentMediax(strType, intMediaPage)
{
	$.ajax({
        url: "/happening/media_content.asp?pgnum=" + intMediaPage + "&type="+ strType,
        //cache: false,
        success: function(data){
        $("#txtContent").html(data);
		return false;
    }
    }); 
}

function getContentEffects(intEffectID)
{
	$.ajax({
        url: "/inspire/painteffects_content.asp?id=" + intEffectID,
        //cache: false,
        success: function(data){
        $("#txtContent").html(data);
    }
    }); 
}

function getContentCareers(intPage)
{
	//alert(intcareerID)
	
	$.ajax({
        url: "/company/careers_content.asp?pgnum=" + intPage,
        //cache: false,
        success: function(data){
        $("#txtContent").html(data);
    }
    }); 
}

function getProductSelection(intSelect,intArea)
{
//		alert(intSelect)
//		alert(intArea)
if (intArea < 5) {
	var strurl = "/productselection/content.asp?id=" + intSelect;
}else{
	var strurl = "/productselection/content_fix.asp?id=" + intSelect + "&area=" + intArea;
}
	$.ajax({
        url: strurl,
       // cache: false,
        success: function(data){
        $("#txtProdSelection").html(data);
    }
    }); 
}

function getProductSelectionSub(intSelect, strSub)
{
		//alert(intSelect)

	var strurl = "/productselection/content_" + strSub + ".asp?id=" + intSelect;
	$.ajax({
        url: strurl,
        //cache: false,
        success: function(data){
        $("#txtInnerProductSelection").html(data);
    }
    }); 
}

function gotoCalculatorx(intCat, intProd)
{
	$.ajax({
        url: "/calculator/calculator_new.asp?prodID=" + intProd,
        //cache: false,
        success: function(data){
        $("#txtContent").html(data);
    }
    }); 
}

function loadMainX(strpgName){
var xmlHttpM
xmlHttpM=GetXmlHttpObjectM()

alert(strpgName)
divName = "txtMain"
loadingDiv(divName,'Loading content...');
var url = escape(strpgName);
//	url=url+"?id="+intID;
//	if (strExtra) { url=url+"&"+escape(strExtra); }
	url=url+"?sid="+Math.random();
xmlHttpM.open("GET",url,true);
xmlHttpM.onreadystatechange=function() { 
			if(xmlHttpM.readyState == 4 && xmlHttpM.status == 200){
                stateChangedM(xmlHttpM,divName);
			}
		}
xmlHttpM.send(null);
opacity( divName, 0, 100, 200);
}


function show7codes(strprod){
divName = "txt7codes"
loadingDiv(divName,'Loading codes...');
var url = "/guide/7year_guarantee_codes.asp";
url=url+"?prod="+escape(strprod);
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
}

function show7substrate(strprod){
divName = "txtSubstrate"
loadingDiv(divName,'Loading substrate...');
var url = "/guide/7year_guarantee_substrate.asp";
url=url+"?prod="+escape(strprod);
url=url+"&sid="+Math.random();
xmlHttp2.open("GET",url,true);
xmlHttp2.onreadystatechange=function() { 
			if(xmlHttp2.readyState == 4 && xmlHttp2.status == 200){
                stateChanged2(xmlHttp2,divName);
			}
		}
xmlHttp2.send(null);
}


function show7year(strpgName){
divName = "txtContent"
loadingDiv(divName,'Loading content...');
var url = "/guide/7year_"+strpgName+".asp";
url=url+"?sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}


function gotoCalculator(intCat, intProd){
divName = "txtContent"
loadingDiv(divName,'Loading calculator...');
var url = "/calculator/calculator_new.asp";
url=url+"?prodID="+intProd;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showAbout(strpgName){
//	alert(strpgName)
divName = "txtContent"
loadingDiv(divName,'Loading content...');
var url = "/company/"+strpgName+".asp";
url=url+"?sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showVisual(strpgName){
//	alert(strpgName)
divName = "txtVisual"
loadingDiv(divName,'Loading content...');
var url = "/inspire/visualiser_"+strpgName+".asp";
url=url+"?sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showMag(strpgName){
//	alert(strpgName)
divName = "txtMag"
loadingDiv(divName,'Loading content...');
var url = "/inspire/colourmagazine_"+strpgName+".asp";
url=url+"?sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}



function showDatasheets(){
divName = "txtContent"
loadingDiv(divName,'Loading data sheets...');
var url = "/products/product_datasheets.asp";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}


function loadProductCategory(intcatID, strcatName){
divName = "txtIntro"
loadingDiv(divName,'Loading products...');
var url = "/products/default_"+strcatName+".asp";
url=url+"?catid="+intcatID;
url=url+"&cat="+strcatName;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showCP(intcpID){
divName = "txtContent"
loadingDiv(divName,'Loading solution...');
var url = "/commonproblems/cp_content.asp";
url=url+"?id="+intcpID;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showCalculatorProduct(intProd){
divName = "txtContent"
loadingDiv(divName,'Loading calculator...');
var url = "/calculator/calculator_new.asp";
url=url+"?prodID="+intProd;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showNewsDetail(intmediaID,intpgnum){
divName = "txtContent"
loadingDiv(divName,'Loading article...');
var url = "/happening/media_detail.asp";
url=url+"?id="+intmediaID;
url=url+"&pgnum="+intpgnum;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showColourCard(intCardID){
divName = "txtContent"
loadingDiv(divName,'Loading colour card...');
var url = "/colourcards/card_content.asp";
url=url+"?id="+intCardID;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showPalette(intCardID){
divName = "txtContent"
loadingDiv(divName,'Loading colour card...');
var url = "/colourcards/palette_content.asp";
url=url+"?id="+intCardID;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function showColourCardProduct(intprodID){
divName = "txtContent"
loadingDiv(divName,'Loading product...');
var url = "/colourcards/product_content.asp";
url=url+"?prod="+intprodID;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function getContentMedia(strType, intMediaPage){
divName = "txtContent"
loadingDiv(divName,'Loading media...');
var url = "/happening/media_content.asp";
url=url+"?pgnum="+intMediaPage;
url=url+"&type="+strType;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}


function gotoLink(intCat, intID){

divName = "txtContent"
loadingDiv(divName,'Loading product...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/products/product_detail.asp";
url=url+"?prod="+intID;
url=url+"&cat="+intCat;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);

//var dHeight = document.getElementById(divName).style.height;
//	alert("dHeight:"+dHeight);


}
function gotoLinkView(intCat, intID){

divName = "txtContent"
loadingDiv(divName,'Loading product...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/products/product_view_details.asp";
url=url+"?prod="+intID;
url=url+"&cat="+intCat;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);

//var dHeight = document.getElementById(divName).style.height;
//	alert("dHeight:"+dHeight);


}

function showProductList(intCat){
divName = "txtContent"
loadingDiv(divName,'Loading products...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/products/product_list.asp";
url=url+"?cat="+intCat;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);
}

function gotoColourcard(intCat, intID){
divName = "txtContent"
loadingDiv(divName,'Loading colour card...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/products/product_colourcard.asp";
url=url+"?prod="+intID;
url=url+"&cat="+intCat;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);

//var dHeight = document.getElementById(divName).style.height;
//	alert("dHeight:"+dHeight);


}

function gotoColourcardView(intCat, intID){
divName = "txtContent"
loadingDiv(divName,'Loading colour card...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/products/product_colourcard_view.asp";
url=url+"?prod="+intID;
url=url+"&cat="+intCat;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);

//var dHeight = document.getElementById(divName).style.height;
//	alert("dHeight:"+dHeight);


}

// SHOW 5 day
function showWeather(strCity){
var divName = "txtContent"
loadingDiv(divName,'Loading weather...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/weather/weather5day.asp";
//url=url+"?city="+document.formWeather.city.value;
url=url+"?city="+escape(strCity);
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 1000);

}

// SHOW weather detail
function showWeatherDetail(strDate, strCity){
var divName = "txtCityDetail"
loadingDiv(divName,'Loading weather...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/weather/weatherCityDetail.asp";
url=url+"?city="+escape(strCity);
url=url+"&date="+escape(strDate);
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 1000);

}

// CALC PAINT
function calcPaintJax(){
var divName = "txtPaintReq"
loadingDiv(divName,'Calculating...');
var url = "/calculator/paintcalc.asp";
url=url+"?paintid="+escape(document.formCalc.product.value);
url=url+"&sarea="+escape(document.formCalc.totalM2.value);
url=url+"&substrate="+escape(valButton(document.formCalc.substrate));
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 1000);

}

// CHECK USERNAME
function checkUsername(){
var divName = "usernameDiv"
loadingDiv(divName,'Checking username...');
var url = "/includes/check_username.asp";
url=url+"?username="+escape(document.formRegister.username.value);
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,"usernameDiv");
			}
		}
xmlHttp.send(null);
}

function gotoTool(intID){
divName = "contentPro"
loadingDiv(divName,'Loading ...');
//	clearDiv("divStatus"+intItem);
//alert (divName)
var url = "/plasconpro/tools_detail.asp";
url=url+"?tool="+intID;
url=url+"&sid="+Math.random();
//alert(url)
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function() { 
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
                stateChanged(xmlHttp,divName);
			}
		}
xmlHttp.send(null);
opacity( divName, 0, 100, 200);

}


function stateChanged(req, divID) 
{ 
//alert(document.getElementById(divID).innerHTML)
	document.getElementById(divID).innerHTML=req.responseText;
}

function stateChanged2(req2, divID2) 
{ 
//alert(document.getElementById(divID).innerHTML)
	document.getElementById(divID2).innerHTML=req2.responseText;
}

function clearDiv(divID) 
{ 
	document.getElementById(divID).innerHTML="";
}

function clearcloseDiv(divID) 
{ 
	document.getElementById(divID).innerHTML='<img src="/images/spacer.gif" height="6">';
}


function loadingDiv(divID, strMessage) 
{ 
	document.getElementById(divID).innerHTML=strMessage;
}



// GLOBAL AJAX
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function GetXmlHttpObjectM()
{
var xmlHttpM=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttpM=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttpM=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttpM=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttpM;
}

// opacity

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
//<a href="javascript:opacity('digicam', 100, 0, 500)">Hide</a> 
	function valButton(btn) {
		var cnt = -1;
		for (var i=btn.length-1; i > -1; i--) {
		   if (btn[i].checked) {cnt = i; i = -1;}
		   }
		if (cnt > -1) return btn[cnt].value;
		else return null;
	}
