///////////////////////////////////////////////
/// function to change any given section
///////////////////////////////////////////////
function pop(str, windowStr){
    href=str;
    window.open(href, windowStr, 'width=800,height=550,menubar=no,scrollbars=auto');
}

///////////////////////////////////////////////
/// function to change any given section
///////////////////////////////////////////////
function pop2(str, windowStr){
    href=str;
    window.open(href,windowStr,'width=600,height=420,menubar=no,scrollbars=yes');
}

///////////////////////////////////////////////
/// function to popup and hold PDF reports
///////////////////////////////////////////////
function popPDF(str, windowStr){
    href=str;
    window.open(href, windowStr, 'width=600,height=600,scrollbars=yes,resizable=yes');
}

///////////////////////////////////////////////
/// function to change any given section
///////////////////////////////////////////////
function change(str, str2){
    //alert('this is working');
    var xmlHttp = GetXmlHttpObject();
    var toChange = str;
    var element1;
    xmlHttp.open("GET", str2, true);
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
            element1 = document.getElementById(str);
            //alert(element1);
            //alert(str);
            //alert(xmlHttp.responseText);
			element1.innerHTML=xmlHttp.responseText;
		}
    }
    xmlHttp.send(null);
}

///////////////////////////////////////////////
/// function to change any given section by name
///////////////////////////////////////////////
function changeN(str, str2){
    //alert('this is working');
    var xmlHttp = GetXmlHttpObject();
    var toChange = str;
    var element1;
    xmlHttp.open("GET", str2, true);
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
            element1 = document.getElementByName(str);
            //alert(element1);
            //alert(str);
            //alert(xmlHttp.responseText);
			element1.innerHTML=xmlHttp.responseText;
		}
    }
    xmlHttp.send(null);
}

///////////////////////////////////////////////
/// function to select the correct xmlHttp style and allocate it
///////////////////////////////////////////////
function GetXmlHttpObject(){ 
    var objXmlHttp=null;

    if (navigator.userAgent.indexOf("Opera")>=0){
        alert("This example doesn't work in Opera");
        return;
    }

    if (navigator.userAgent.indexOf("MSIE")>=0){ 
        var strName="Msxml2.XMLHTTP";
        
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
            strName="Microsoft.XMLHTTP";
            objXmlHttp=new XMLHttpRequest();
            return objXmlHttp;
        } 
        try{
            objXmlHttp=new ActiveXObject(strName);
            //objXmlHttp.onreadystatechange=processRequest();
            return objXmlHttp;
        } 
        catch(e){ 
            alert("Error. Scripting for ActiveX might be disabled");
            return;
        } 
    }
    
    if (navigator.userAgent.indexOf("Mozilla")>=0){
        objXmlHttp=new XMLHttpRequest();
        //objXmlHttp.onload=processRequest;
        //objXmlHttp.onerror=processRequest;
        return objXmlHttp;
    }
}

function add_prompt(){
	var parent = document.getElementById('wrapper');
	
	var buy_now = document.getElementById('buy_now');
	var left = findPosX(buy_now);
	var top = findPosY(buy_now);
	top = top - 5;
	left = left - 5;
	var new_div = document.createElement('div');
	new_div.setAttribute('id', 'adding');
	new_div.setAttribute('className', 'adding');
	new_div.setAttribute('class', 'adding');
	parent.appendChild(new_div);
	new_div.innerHTML = '<table id="final_table" style="position:absolute; top:'+top+'px; left:'+left+'px;"><tr><td align="center" id="insert_area"><div id="inner_prompt"></div></td></tr></table>';
	document.getElementById('inner_prompt').innerHTML = "adding product to basket...";
}
     
function remove_add_prompt(){
	var parent = document.getElementById('wrapper');
	var child = document.getElementById('adding');
	parent.removeChild(child);
}
     
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
  
  
  
  /*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[10,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename
	t = title
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,w,h);",0);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=0
		height+=0
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 )
		{
			//alert('internet explorer');
			style = 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80)';
			//newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		}
		else
		{
			//alert('firefox');
			style = 'opacity:0.8';
		}
		
		newHTML = '<div style="' + style + '; border:1px solid black; width:'+ width +'px; height:'+ height +'px"><img src="' + imagename + '" border="0"></div>';

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

/*function remove_loading() {
//this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
//var t_id = setInterval(animate,60);
}*/

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}
