
// Change color
function changeColor()
{		
	var count=document.getElementById("hiddenTurn").value;
	//alert(count);
	for(i=0;i<count;i++)
	{
		if(document.getElementById("turn"+i).checked==true)
		{
			document.getElementById("row"+i).style.backgroundColor="#FFFFFF";	
			document.getElementById("row"+i).style.border="1px solid #CCCCCC";		
		}
		else
		{
			document.getElementById("row"+i).style.backgroundColor="#FBFBF1";
			document.getElementById("row"+i).style.border="1px solid #FBFBF1";	
		}
	}		
}


	
//Ajax Calling

function computeTurnaround(priceval){
 var ajaxRequest1;
 
 try{
  ajaxRequest1 = new XMLHttpRequest();  
 } catch (e){
  try{
   ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");      
  } catch (e) {
   try{
    ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");   
   } catch (e){
    alert("Your browser broke!");
    return false;
   }
  }
 }

 ajaxRequest1.onreadystatechange = function(){
  if(ajaxRequest1.readyState == 4){
    var ajaxDisplay1 = document.getElementById('showTurnaround');
     ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
     
   }
 }
 	

 curTurn=document.getElementById("hiddenTurn").value; 
for(i=0;i<curTurn;i++)
{
	arrTurn=document.getElementById("turn"+i).value;  	
	if(document.getElementById("turn"+i).checked==true)
	{
		turnaround=arrTurn;			
		break;
	}
	else
	{
		turnaround="";	
		//document.getElementById("row"+i).style.backgroundColor="#FBFBF1";
	}
}
 
 stock=document.getElementById('paper_type').value;
 
 //alert(stock);
 
 var url1="calculator_turnaround.php"
 url1=url1+"?size="+priceval['size'].value+"&stk="+stock+"&color="+priceval['color'].value+"&qty="+priceval['quantity'].value+"&turn="+turnaround;


 ajaxRequest1.open("GET", url1, true);
 ajaxRequest1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

 ajaxRequest1.send(null);  
 
	 setTimeout("changeColor()", 1000);
}


//Ajax Calling

function computePrice(priceval){
 var ajaxRequest1;
 
 try{
  ajaxRequest1 = new XMLHttpRequest();  
 } catch (e){
  try{
   ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");      
  } catch (e) {
   try{
    ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");   
   } catch (e){
    alert("Your browser broke!");
    return false;
   }
  }
 }

 ajaxRequest1.onreadystatechange = function(){
  if(ajaxRequest1.readyState == 4){
    var ajaxDisplay1 = document.getElementById('showprice');
     ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
     
   }
 }

 curTurn=document.getElementById("hiddenTurn").value;
 
 
 
for(i=0;i<curTurn;i++)
{
	arrTurn=document.getElementById("turn"+i).value;  	
	if(document.getElementById("turn"+i).checked==true)
	{
		turnaround=arrTurn;
		
		break;
	}
	else
	{
		turnaround="";	
		//document.getElementById("row"+i).style.backgroundColor="#FBFBF1";
	}
}
 stock=document.getElementById('paper_type').value;
 
 //alert(stock);
 
 var url1="calculator.php"
 url1=url1+"?size="+priceval['size'].value+"&stk="+stock+"&color="+priceval['color'].value+"&qty="+priceval['quantity'].value+"&turn="+turnaround;


 ajaxRequest1.open("GET", url1, true);
 ajaxRequest1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 ajaxRequest1.send(null);  
}



//Ajax loader lightbox 
var curr_lb_div;
var is_modal = false;

function ShowLightBox(lb_div, isModal)
{
    document.getElementById(lb_div).style.display='block';
    document.getElementById('fade').style.display='block';
    curr_lb_div = lb_div;
    if (isModal)
        is_modal = true;
    else is_modal = false;
}

function HideLightBox()
{
    if (document.getElementById(curr_lb_div))
    {
         document.getElementById(curr_lb_div).style.display='none';
         document.getElementById('fade').style.display='none';
         curr_lb_div = '';
    }
}


//Ajax Calling

function changeStock(quantity){
 var ajaxRequest1;
 
 try{
  ajaxRequest1 = new XMLHttpRequest();  
 } catch (e){
  try{
   ajaxRequest1 = new ActiveXObject("Msxml2.XMLHTTP");      
  } catch (e) {
   try{
    ajaxRequest1 = new ActiveXObject("Microsoft.XMLHTTP");   
   } catch (e){
    alert("Your browser broke!");
    return false;
   }
  }
 }

 ajaxRequest1.onreadystatechange = function(){
  if(ajaxRequest1.readyState == 4){
    var ajaxDisplay1 = document.getElementById('showstock');
     ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
     
   }
 }

 
 var url1="change_stock.php"
 url1=url1+"?qty="+quantity;

var frm=document.frmCalculator;

setTimeout("computePrice(frm)", 800);

setTimeout("computeTurnaround(frm)", 800);

 ajaxRequest1.open("GET", url1, true);
 ajaxRequest1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 ajaxRequest1.send(null);  
}
