/*@ author Comit Technology : Manawor Qutub javaScript and Ajax,J Query for Coupon code . 
 * contain all script needed by Coupon Management System.
 *
 */
$(document).ready(function(){
    $('.submitToImage').attr('type', 'image');
});



function coupon_cash(id){

    var xmlhttp = false;
    //Check if we are using IE.
    try {
        //If the javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        //If not, then use the older active x object.
        try {
            //If we are using IE.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) {
            //Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
    //If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    
    //capturing coupon text value 
    var coupon_code = document.getElementById(id);
    
    // if (validate_Alphanumeric(coupon_code, "coupon code must be alphanumeric value")) {
    var theelement = "coupon_message";
    //alert(document.getElementById(theelement).innerHTML.length);
    
    // var serverPage = "coupon_cash2.php" + "?cID=" + coupon_id +"& cEmail="+customer_email ;
    var serverPage = "coupon_cash2.php" + "?coupon_code=" + coupon_code.value
    
    var objID = "coupon_message";
    var obj = document.getElementById(objID);
    // alert(obj);
    xmlhttp.open("POST", serverPage);
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        
            obj.innerHTML = xmlhttp.responseText;
            
        }
    }
    xmlhttp.send(null);
}



//   return true;

//}

//return flase;


//validating Alphanumeric on the form
function validate_Alphanumeric(field, alerttxt){
    with (field) {
    
        var alphaExp = /^[0-9a-zA-Z]+$/;
        if (!field.value.match(alphaExp)) {
            alert(alerttxt);
            return false;
        }
        else {
        
            return true
        }
    }
}

//for stokes tropical to check subtotal > $25 

function checkSubtotla(){
    var subtotal = document.getElementById('sub_total').value;
    
    
    if (subtotal > 24) {
    
        return true;
    }
    else {
        alert("Minimum order must be $25");
        // document.frmCartLogin.Proceed_checkOut.focus();
        // history.go(-1)
        
        return false;
    }
    
    return false;
}


function giftcard_cash(){

    var xmlhttp = false;
    //Check if we are using IE.
    try {
        //If the javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        //If not, then use the older active x object.
        try {
            //If we are using IE.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) {
            //Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
    //If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    
    var gift_code = document.getElementById('giftcard-code').value;
    var pass_code = document.getElementById('giftcard-passcode').value;
    //alert(gift_code);
    //alert(pass_code);
    
    // var theelement = "gift-card-message";
    
    var serverPage = "giftCard_cash.php" + "?Gift_Code=" + gift_code + "&Pass_Code=" + pass_code;
    //alert(serverPage);
    var objID = "gift-card-message";
    var obj = document.getElementById(objID);
    xmlhttp.open("POST", serverPage);
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        
            obj.innerHTML = xmlhttp.responseText;
            
        }
    }
    xmlhttp.send(null);
    
}


