<!--

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		break;
	}
	return null;
}

function setVal(){
	var AV = GetCookie('AVIS_RI_AWD');
	if (AV != null){
		if (AV != 'T990400'){ 
			$('#AWD').val(AV);
		}
	}
}

function push_res(x){
	var AV = GetCookie('AVIS_RI_AWD');
	var url = "https://www.avis.com/car-rental/reservation/initialize-reservation.ac?MID="+x+"&AWD_NUMBER=";
	if (AV != null){
 		document.location = url+AV;
	}else{
 		document.location = url+'T990400';
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

$(document).ready(function() {
    $('#continue').click(function() {
        handleAWD();  
    });
    $("#continue").mouseover(function(){
      $(this).css('cursor', 'pointer');
    }).mouseout(function(){
      $(this).css('cursor', '');    
    });
    $('#ContinueNav').click(function() {
        handleAWD('nav');  
    });
    $("#ContinueNav").mouseover(function(){
      $(this).css('cursor', 'pointer');
    }).mouseout(function(){
      $(this).css('cursor', '');    
    });
    setVal();        
});



var pattern_awdNumber = new RegExp("\^\[a\-zA\-Z\]\[0\-9\]\{6\}\$");

function handleAWD(x){
    if(x == 'nav'){
        AWDValue = $('#AWDNav').val(); 
        errorDiv = '#awdErrorNav';
    }else{
        AWDValue = $('#AWD').val();
        errorDiv = '#introMsg';  
    }
      
    if (AWDValue.length > 0 && !pattern_awdNumber.test(AWDValue)){
        $(errorDiv).html('');
        $(errorDiv).html('Invalid AWD Number.  Please try again or call 1.800.222.2847 to obtain your Company\'s Corporate Awards AWD Number.');
        $(errorDiv).css('color','RED');
    }else{
        setCookie('AVIS_RI_AWD',AWDValue,'720');
        push_res('AvisAwards AWD Form');
    }

}

function clearField(x){
    if(x == 'focus'){
        if($('#AWD').val() == "Enter AWD #"){$('#AWD').val('')};
    }else{
        if($('#AWD').val() == ""){$('#AWD').val('Enter AWD #')};
    }
}

// -->
