

// below is code for writing to mysql via Ajax which deals with xmlhttp re-use and cache problems by using POST
// see: http://radio.javaranch.com/pascarello/2006/03/30/1143735438047.html
//      http://www.enja.org/david/?p=25
//      http://en.wikipedia.org/wiki/XMLHTTP
// for standrad implentation see:
//		http://www.tutorialspoint.com/ajax/ajax_database.htm
//
// a test version of this is available in ajax3.html
//
var req = null;

  function getXHR(){
    var newReq = null;
	if(window.XMLHttpRequest) {
      try {
        newReq = new XMLHttpRequest();
      }
      catch(e) {
        newReq = false;
      }
    }
    else if(window.ActiveXObject) {
      try {
        newReq = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e) {
        try {
           newReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {
          newReq = false;
        }
      }
    }
	return newReq;
  }

var req_IE = getXHR();

function loadXHR_IE(tsk,job,pic,usr)
{
    //alert('inside loadXHR');

	if(pic == 'get_num')
  		{
	  	pic = document.pictures.active.value;
		}
	else if (pic == 'get_nump')
		{
		pic = document.preview.active.value;
		}
	else if (pic == 'get_num2')
		{
		pic = document.pictures.active.value+'/'+document.pictures.active2.value;	
		}
	//alert(pic);

	var queryString= "?tsk=" + tsk;
    queryString += "&job=" + job;
    queryString += "&pic=" + pic;
    queryString += "&usr=" + usr;

    //alert(queryString);
    if(req_IE)
	   {
       req_IE.open("POST", "ajax_routines.php" +
                       queryString, true); 
	   req_IE.onreadystatechange = processReqChange_IE;
       req_IE.send("");
       }
    else
	   {
       alert("The XMLHttpRequest Object is not supported");
       }

	req_IE.onreadystatechange = function()
	{
		if(req_IE.readyState == 4)
	       {
    	   var reply;
	       reply = req_IE.responseText;
		   //alert('reply is: '+reply);
    	   }
        if (tsk == 'check_login' && reply == 'notfound')
			{
            //alert('User ID not found - please try again');
            document.loginform.advice.value = 'User ID not found - please try again';
            document.loginform.usr.focus;
            return false;
			}

       if (tsk == 'check_login' && reply == 'found_error')
			{
            //alert('Password does not match User ID - please try again');
            document.loginform.advice.value = 'Password and User ID do not match - please try again';
            document.loginform.pwd.focus;
			return false;
			}

	   if (tsk == 'check_login' && reply == 'found_ok')
			{
            document.loginform.advice.value = 'Yippee';
			return true;
			}

		if (tsk == 'copy_to_basket' && reply == 'y')
		   {
           //alert('incing basket');
		   document.lmenu.bskt.value++;
    	   }
	}

}

function processReqChange_IE() {
    if (req_IE.readyState == 4) {
      if (req_IE.status == 200 || req_IE.status == 0) {
        alert(req_IE.responseText);
      }
      else {
        alert("There was an issue retrieving the data:\n" +
              "Reason: " + req_IE.statusText);
      }
    }
}

// This Script is for the Div Layer. This Script will work with IE5+ & Netscape 6+
var d = document, n = navigator; 
var agent = n.userAgent.toLowerCase(); 
var mX, mY; 


//Browser sniff hash obj 
var sniff = { 
bw: { 
ns:d.layers, 
ie:d.all && !d.getElementById, 
ie4:agent.indexOf("msie 4.") != -1, 
ie5:agent.indexOf("msie 5.") != -1, 
ie6:agent.indexOf("msie 6.") != -1, 
dom:d.getElementById, 
ns6:d.getElementById && agent.indexOf("gecko") != -1 
}, 
os: { 
win:agent.indexOf("win") != -1, 
mac:agent.indexOf("mac") != -1 
} 
}; 

function showHide(lyrId, prop) { 
var lyrObj = (d.layers)?d[lyrId]:d.all?d.all[lyrId].style:d.getElementById(lyrId).style; 
lyrObj.visibility = prop;

var ww = document.body.clientWidth;
var wh = document.body.clientHeight;

//alert('mX is: '+mX+' mY is: '+mY);
if ( (ww - mX) < 200)
	{
	lyrObj.left= mX-200;
	}
else
	{	
	lyrObj.left = mX+10; 
	}

if ( (wh - mY) < 100)
	{
	lyrObj.top= mY-10;
	}
else
	{	
	lyrObj.top = mY-100; 
	}

if (lyrId == 'changeLightBox')
	{
	lyrObj.left= mX-160;
	lyrObj.top = mY+75; 
    }
} 


function showHideStatic(lyrId, prop) { 
var lyrObj = (d.layers)?d[lyrId]:d.all?d.all[lyrId].style:d.getElementById(lyrId).style; 
lyrObj.visibility = prop;




var ww = document.body.clientWidth;
var wh = document.body.clientHeight;


if ( (ww - mX) < 200)
	{
	lyrObj.left= mX-200;
	}
else
	{	
	lyrObj.left = mX+10; 
	}

if ( (wh - mY) < 100)
	{
	lyrObj.top= mY-100;
	}
else
	{	
	lyrObj.top = mY-10; 
	}

if (lyrId == 'changeLightBox')
	{
	lyrObj.left= mX-220;
	lyrObj.top = 100; 
    }
} 



function showHideMenu(lyrId, prop) { 

var lyrObj = (d.layers)?d[lyrId]:d.all?d.all[lyrId].style:d.getElementById(lyrId).style; 
lyrObj.visibility = prop;
}


function showHideFixed(lyrId, prop) { 

var lyrObj = (d.layers)?d[lyrId]:d.all?d.all[lyrId].style:d.getElementById(lyrId).style; 
lyrObj.visibility = prop;
//alert('layerid is:'+lyrId);

if (lyrId == 'showKeywords')
	{
	if ( prop == 'visible')
		{
		document.preview.showkeywords.value='yes';
		}
		else
		{
		document.preview.showkeywords.value='no';
		}	
	}
} 


function mMove(e) { 

var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

mX = (sniff.bw.ns || sniff.bw.ns6)?e.pageX:event.x; 
mY = (sniff.bw.ns || sniff.bw.ns6)?e.pageY:event.y; 

if (isIE)
		{
			mX += document.body.scrollLeft;
			mY += document.body.scrollTop;
		}
} 

function init() { 
if (sniff.bw.ns) { 
d.captureEvents(Event.MOUSEMOVE) 
} 
d.onmousemove = mMove; 
} 


