// JavaScript Document
<!--
function updateOptionid() {
document.getElementById('optionid').value = document.getElementById('optionidlist').options[document.getElementById('optionidlist').selectedIndex].value;
//alert(document.getElementById('optionid').value);
 } // end of function Optionid
function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200 ) {
//alert(req.readyState);
good = 0;
if (req.responseXML)
{
if (req.responseXML.documentElement)  // for mozilla we need to test for req.response itself and this one is for IE
{
good = 1;
}
}
if ( good == 0 )
{
document.getElementById("ajaxcheck").value  = 0 ;
goProcess('add');
}
if (good == 1) {

response = req.responseXML.documentElement;
//req = null ;
//alert(req.responseText);
method0 = response.getElementsByTagName('localmethod')[0].firstChild.data;
//alert(method0);
if (method0 == 'ajaxcheck') {
var returnvalue = response.getElementsByTagName('returnvalue')[0].firstChild.data;
//alert(returnvalue);
var ac = document.getElementById("ajaxcheck").value ;
if (ac == returnvalue)
{
document.getElementById("ajaxcheck").value  = 1 ;
url = '/ajaxcheckserver.cfm?ajaxset=1';
//loadXMLDoc(url);
//alert(1);
}
else
{
document.getElementById("ajaxcheck").value  = 0 ;
 //alert(0);
}
//goProcess('add');
return;
} // end of method checkajax
if (method0 == 'ajaxset') 
{
return;
}
method = response.getElementsByTagName('qtyadded')[0].firstChild.data;
if (method) {
//alert(method);
//alert(method + ' of  this added to your cart');
method1 = response.getElementsByTagName('optionid')[0].firstChild.data;
method2 = response.getElementsByTagName('qtyinstock')[0].firstChild.data;
method3 = response.getElementsByTagName('grandtotal')[0].firstChild.data;
method4 = response.getElementsByTagName('totalqty')[0].firstChild.data;
method2 = method2*1 + 0; //otherwise firefox javascript engine was not doing numeric GT comparison below
method = method*1 + 0 ;
method3 = method3*1;   // same reason
if (method > method2)
{
alert('In stock :' + method2 + ' . Your Order:' + method+'. Please allow 2-4 weeks for not in stock qty');
}
else
{
alert('Qty of this item in cart:' + method+'.');

}
//alert('In stock :  ' + method2 + ' . Your Order:' + method+'. Please allow 2-4 weeks for not in stock qty');

                               document.getElementById("totalqty").innerHTML = '<u><a href="/bagcart.cfm" title="check jewelry in cart">Qty  in Cart</a></u><br /><strong><span style="background-color:white;">This Item: ' + method +'</span></strong><br /><a href="/bagcart.cfm" title="click to go to cart">Total: '  + method4+'</a>' ;
document.getElementById("totalqty").className = 'rowb';
if ( method1 > 0) {
document.getElementById("qtyincart").innerHTML = '<a href="/bagcart.cfm" title="click to go to cart">Qty In Cart: ' +method +' </a> <span class="optionsinline">(Option ' + method1 + ')</span>' ;
}else{
document.getElementById("qtyincart").innerHTML = ' <a href="/bagcart.cfm" title="click to go to cart">Qty In Cart: ' +method +' </a> ' ;
}
//document.getElementById("carttotal").innerHTML = '$ ' + method3  ;

document.getElementById("totalqty").className = 'itemdetailsboxgreen';
document.getElementById("qtyincart").className = 'itemdetailsboxred';
document.getElementById("erroraddingitem").className = 'hidden';
document.getElementById("grandtotal").innerHTML = '[ $' + method3 + ' , ' + method4+' Items]';

document.getElementById("grandtotal").className = 'error';
//document.getElementById("ajaxoutput").className = 'itemdetailsboxgreen';
document.getElementById("a2wl").className = 'hidden';
//alert(req.responseText);
//now invoke the method 
//eval(method + '( result,\'1\' )');
}
else{
alert("There was an error. Make sure you have entered a numeric value in the qty")
   

    }
	}else
{
//alert('Error in adding to cart!');
document.getElementById("a2cw").className = 'hidden';
document.getElementById("a2cb").className = 'greenbutton';
document.getElementById("erroraddingitem").className = 'error';
document.getElementById("ajaxoutput").className = 'itemdetailsboxred';
return false;
}

}
else {
alert("There was an error adding the Item.");
   

//alert(req.responseText);
         }
		    
document.getElementById("a2cw").className = 'hidden';
document.getElementById("a2cb").className = 'greenbutton';
    }
	return false;
}

 function ajaxCheckClient() {
 var iedcache = Math.random();
iedcache = iedcache*1000;
  iedcache = Math.round(iedcache*1000) + 1.00;
  document.getElementById('ajaxcheck').value = iedcache;
  var url = '/ajaxCheckServer.cfm?var='+iedcache ;
 // alert(url);

  loadXMLDoc(url);
return;
}
function ajaxcheck() {
 if (document.getElementById("ajaxcheck").value  ==  -1)
  { // called only once per session because then it will get set to 0 or 1  

  	ajaxCheckClient();
//	ajaxClient will itself submit the form 
	return false;
 }
 }
function goProcess(inString){
	if(inString=='add'){

	//alert(document.getElementById('price').value );
	// put checks for numeric values here
//	 if (window.XMLHttpRequest || window.ActiveXObject    ) 
 if (document.getElementById("ajaxcheck").value  == 1) { 
	 // first disable submission of form 
	 self.document.wishbuy.action="";

document.getElementById("a2cb").className = 'hidden';
document.getElementById("a2cw").className = 'greenbutton';

      q =  document.getElementById('quantity').value;
	//  	 alert(1);  
	   n = document.getElementById('newitem').value  ;
	   c = document.getElementById('unclashcategory').value ; // for ie, getElementById treats Name attribute as Id attribute
	   p = document.getElementById('price').value; 
	 
	   if (document.getElementById('optionid').options)
	   {
	   
o  =	   document.getElementById('optionid').options[document.getElementById('optionid').selectedIndex].value;
	   }else
	   	   o = document.getElementById('optionid').value;  // here first we will have to check if it is a option ilst and the process accordingly
iedcache = Math.random();
iedcache = iedcache*1000;
    	url ='/cartcontrol/cartmonitor.cfc?method=additem&newitem=' + n+ '&quantity=' +q + '&category=' +c+ '&price=' + p + '&optionid='+ o +'&iedcache=' + iedcache+'&endof';
//	alert(url);
   self.document.wishbuy.action="";

   loadXMLDoc(url);
      return false; // should stop submiting of form in case return button was hit
} else {
	self.document.wishbuy.action="/bagcart.cfm";
self.document.wishbuy.submit();
	}
	
	return false;
	
	}
	if(inString=='Add to Wish List'){
	self.document.wishbuy.action='/wish.cfm';
	self.document.wishbuy.submit();
	return;
	}
	if(inString=='Show Next'){
	self.document.wishbuy.action='/laptop-case.cfm/' + self.document.wishbuy.nextitem.value + '.htm';
	//self.document.wishbuy.method = 'get';
	self.document.wishbuy.submit();
	return;
	}
}

//-->
