//used by googleAnalytics
function trackTransaction(){
	if(document.getElementById("thankYouPage"))
		{__utmSetTrans();}
}

function openSizeWindow(popurl){
var winpops=window.open('http://www.le-chameau-clothing.co.uk/ires/53/lcc/lccsizeguides/'+popurl,'','width=650,height=200,toolbar=no,resizable=yes')
}

//***************************************************************************
// Utility functions
//***************************************************************************

//The getElements() method returns an array of elements with the css class 
//If you want to scan the whole document, use document as the 
//elm paramter and * as the strTagName parameter.
function getElements(elm, strTagName, strClassName){
		//get the array of elements to check by tagName type
	    var arrElements = (strTagName == "*" && elm.all)? elm.all : elm.getElementsByTagName(strTagName);
	    var arrReturnElements = [];
	    for(var i=0; i<arrElements.length; i++){
	        var temp = arrElements[i];
	        //check if the current element's css class is of the type we want.      
			if(check(temp, strClassName)){
			//yes it is so add it to our results
				arrReturnElements.push(temp);
			}
	    }
	    // the array of matching elements whose css class=strClassName
	    return (arrReturnElements)
	}
	
//is the css class of element passed the same as the css class name passed?
function check(elm, strClassName){
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var regEx = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		return regEx.test(elm.className);
		}
			


//get the file path to the pop-up image
function getFilePath(aURL){
//re=/wosid=([^\&]*)/;
re=/(.*\/)(.*\..*)/;
if(re.exec(aURL))
	{
		if(!RegExp.$1==""||!RegExp.$2=="") return RegExp.$1+"pop-"+RegExp.$2;
	}
}

// display Pop Up img element on the current page
function displayPop(event){
	var posx=0;
    var posy=0;
    if(!event)var event=window.event;
    // determine target img
    var targ=event.target?event.target:event.srcElement;
    var targetPath=targ.getAttribute('src');
    //create the pop img file patch from it
    var popPath=getFilePath(targetPath);
    if(!popPath){return;}
    //  document.write(popPath);  
    // get the mouse coordinates
    if(event.pageX||event.pageY)
    {
   		posx=event.pageX;
        posy=event.pageY;
    }
    else if(event.clientX||event.clientY)
    {
        posx=event.clientX;
        posy=event.clientY;
        // check for scroll offsets in IE 6
        if(document.documentElement.scrollLeft ||document.documentElement.scrollTop)
        	{
            	posx+=document.documentElement.scrollLeft;
            	posy+=document.documentElement.scrollTop;
           }
    }
    
    // assign attributes to pop-up DIV element and append
    // it to web document tree
    var div=document.getElementById('pop');
    //make sure we don't have a pop open
    if(div) div.parentNode.removeChild(div);      
    var popUp=document.createElement('div');
    popUp.setAttribute('id','pop');
    popUp.className='pop';
    var img=document.createElement('img');
    img.setAttribute("src",popPath);
    img.onclick=removePop;
    // move pop-up DIV element
  //  popUp.style.top=posy+-180+'px';
//    popUp.style.left=posx+-250+'px';
 popUp.style.top=posy+-180+'px';
 popUp.style.left=posx+'px';
  //  popUp.style.zIndex=100;
    popUp.appendChild(img);
    document.getElementsByTagName('body')[0].appendChild(popUp);    

}

// remove pop-up DIV element
function removePop(){
	var popUp=document.getElementById('pop');
    if(!popUp)return;
    popUp.parentNode.removeChild(popUp);
}

// activate pop-up DIV elements
// This is called when a webPage is loaded.  It writes our "mouse" events to the "popContainer"
// so they will trigger popups when hovered over etc.
function activatePops(){
	var popDiv=document.getElementById('popDiv');
	if(!popDiv)return;	
	var popContainers=getElements(popDiv, 'div', 'popContainer')
    if(!popContainers)return;
    
    for(var i=0;i<popContainers.length;i++){
    	if(popContainers[i].className=='popContainer')
    	{
        	// display pop-up DIV element
            popContainers[i].onmouseover=displayPop;
            // hide pop-up DIV element
            popContainers[i].onmouseout=removePop;
        }
	}
 }

//***************************************************************************
// Stuff to enable the flash product images
//***************************************************************************
//global vars
var pageId=null;

//Load the xml image data file
//when it fires its loaded event it will call _writeImageFlash
function writeImageFlash(id){
//keep hold of the pageId for later
pageId=id;
//load the xml
loadXMLDoc("/ires/53/lcc/lccflash/images.xml");
}

//fired by the xml event handler processReqChange
function _writeImageFlash(imageXml){

//by default assume this page has no flash
pageHasFlash=false;

//do we have an xml object ?
if(typeof imageXml == "undefined") return ;

//iterate over the image sets to see if we have one for this page.
//if not then we are not going to try to put flash here
imageSets= imageXml.getElementsByTagName("imageset");
for(var i=0;i<imageSets.length;i++){
   setId=imageSets[i].getAttribute('setId');
	if(setId==pageId)
		{//yes we do
		pageHasFlash=true;
		break;
		}
}

// if we do not have flash then exit.
if(!pageHasFlash)return;

//write the flash to the page
var so = new SWFObject("/ires/53/lcc/lccflash/p-slides-v3.swf?xmlFile=/ires/53/lcc/lccflash/images.xml&setId="+pageId, "flashView", "100%", "100%", "6", "#084a33");
so.write(document, "div", "pageImageDiv");
}

//private
function setFlashWidth(divid, newW){
	//var node=document.getElementById(divid);
	var node=getElements(document, "div", "pageImageDiv")[0];
	var parentNode=node.parentNode;
	//var grandParentNode=parentNode.parentNode;
	node.style.width = newW+"px";
	parentNode.style.width = newW+"px";
	//grandParentNode.style.width = newW+"px";
	
}
//private
function setFlashHeight(divid, newH){
	//var node=document.getElementById(divid);
	var node=getElements(document, "div", "pageImageDiv")[0];
	var parentNode=node.parentNode;
	//var grandParentNode=parentNode.parentNode;
	node.style.height = newH+"px";
	parentNode.style.height = newH+"px";
	//grandParentNode.style.height = newH+"px";	
}


//called by the swf actionscript to set the containing html elements to the correct size.
function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
	
}



// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        requestObject = new XMLHttpRequest();
        requestObject.onreadystatechange = processReqChange;
        //note by using true we will wait until we get a response
        requestObject.open("GET", url, true);
        requestObject.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        requestObject = new ActiveXObject("Microsoft.XMLHTTP");
        if (requestObject) {
            requestObject.onreadystatechange = processReqChange;
            //note by using true we will wait until we get a response
            requestObject.open("GET", url, true);
            requestObject.send();
        }
    }
}

// handle onreadystatechange event of XMLHttpRequest object
function processReqChange() {
    // only if req shows "loaded"
    if (requestObject.readyState == 4) {
        // only if "OK"
        if (requestObject.status == 200) {
        // all ok so do what we need
         _writeImageFlash(requestObject.responseXML);
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                requestObject.statusText);
         }
    }
}
//***************************************************************************
//	MISC
//***************************************************************************
function getSO(){

var SORegex=/SO(.+)/i;
var elements=document.getElementsByTagName("b");		
		for (var i = 0; i < elements.length; i++) 
			{
				var spanText=elements[i].childNodes.item(0).data;
				if(SORegex.test(spanText))
					{document.write("<input type='hidden' name='so' value='"+spanText+"'>");}
							
			};
	}

//***************************************************************************