//Ajax Calling

function computePrice(){
    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="";
        }
    }
	
	curShipping=document.getElementById("hiddenShipping").value;
    for(i=0;i<curShipping;i++){
        arrShipping=document.getElementById("shipping"+i).value;
        if(document.getElementById("shipping"+i).checked==true){
            shipping=arrShipping;		
            break;
        }else{
            shipping="";
        }
    }
	
    stock=document.getElementById('paper_type').value;
	var quantity = $('#quantity').attr('value');
    //alert(stock);
 
    var url1="card_calculator.php"
    url1=url1+"?stk="+stock+"&qty="+quantity+"&turn="+turnaround+"&shipping="+shipping;

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

function stockChange(){
	$(".turnaround").hide();
	var stock = $('#paper_type').attr('value');
	switch(stock) {
		case '14 or 16PT Business Cards UV (1or2 Sided)':
		case '14 or 16PT Matte/Dull Finish (1or2 Sided)':
		case '14 or 16PT Round Corner  Matte or UV (1or2 Sided)':	
			$("#div_turn0").show();
			break;
		default:
	}
	switch(stock) {
		case '14 or 16PT Business Cards UV (1or2 Sided)':
		case '14 or 16PT Matte/Dull Finish (1or2 Sided)':
			$("#div_turn1").show();
			$("#turn1").attr("checked", "checked");
			break;
		case '14 or 16PT Round Corner  Matte or UV (1or2 Sided)':	
		case '14 or 16PT w/ Silver(877 C) Matte or UV (1or2 Sided)':	
		case '14 or 16PT  Matte Finish w/ Spot UV (1or 2 Sided)':	
		case '14 or 16PT Matte Round Corner  w/ Spot UV (1or2 Sided)':	
			$("#div_turn3").show();
			$("#turn3").attr("checked", "checked");
			break;
		default:
			$("#div_turn2").show();
			$("#turn2").attr("checked", "checked");
			break;
	}

	$(".shipping").hide();
	$("#div_shipping2").show();
	switch(stock) {
		case '14 or 16PT Business Cards UV (1or2 Sided)':
		case '14 or 16PT Matte/Dull Finish (1or2 Sided)':
		case '14 or 16PT w/ Silver(877 C) Matte or UV (1or2 Sided)':	
		case '14 or 16PT  Matte Finish w/ Spot UV (1or 2 Sided)':	
			$("#div_shipping3").show();
			$("#shipping3").attr("checked", "checked");
			break;
		case '14 or 16PT Round Corner  Matte or UV (1or2 Sided)':	
		case '14 or 16PT w/ Silver(877 C) Round Corner Matte or UV':	
		case '14 or 16PT Matte Round Corner  w/ Spot UV (1or2 Sided)':	
			$("#div_shipping1").show();
			$("#shipping1").attr("checked", "checked");
			break;
		default:
			$("#div_shipping0").show();
			$("#shipping0").attr("checked", "checked");
			break;
	}
	
}

function funOrderNow(){   
	var x=document.getElementById("frmCalculator");
	document.getElementById("hidValue").value="Submit";   
	x.submit();
} 

function computeQuantity(){
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('quantity_contain');
            ajaxDisplay1.innerHTML = ajaxRequest1.responseText;
			computePrice();
        }
    }

    stock=document.getElementById('paper_type').value;

    var url1="load_quantity.php"
    url1=url1+"?stk="+stock;

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


}
