	
	function submitPage(path) {
		if (checkCookieEnabled()) {	
			/*if (path != "samepage" && document.getElementById("promocode") != null) {
				var promocode = document.getElementById("promocode").value;
				document.location.href="/RDNavigationServlet?gotopath="+path+"&promocode="+promocode;
			} else if (path == "samepage") {
				promoAjax();
			} else {*/
				document.location.href="/RDNavigationServlet?gotopath="+path;
			//}
		} else {
			alert("Please enable cookies");
		}
	}
	
	function checkCookieEnabled() {
		var cookieEnabled=(navigator.cookieEnabled)? true : false;

		//if not IE4+ nor NS6+
		if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled) { 
			document.cookie="testcookie";
			cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
		}
		return cookieEnabled;
	}
	
	function pageOnLoadSettings() {
		var parentUrl = parent.document.URL;		
		var url = "/RDNavigationServlet?gotopath=pageOnLoadSettings";
		if (parentUrl != null) {
			var qsIndex = parentUrl.indexOf("?");
			if (qsIndex != null) {
				url = url + "&" + parentUrl.slice(qsIndex + 1);
			}
		}
		document.getElementById("loginusertag").innerHTML = "<a href='#' onClick=submitPage('securelogin')>Login</a>";
		var xmlhttp;
		if (window.XMLHttpRequest) {// code for IE7, Firefox, Mozilla, etc.
			xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {// code for IE5, IE6
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp != null) {
			xmlhttp.onreadystatechange = function() {
    			if(xmlhttp.readyState == 4) {
	    			var isbuyerLogged = 'F';
	    			if (xmlhttp.responseXML != null) {
    				y = xmlhttp.responseXML.getElementsByTagName("isBuyerLoggedIn");
    				if (y != null && y[0] != null) {    					
    					isbuyerLogged = y[0].childNodes[0].nodeValue;    					
    				}
      				if (isbuyerLogged == 'Y') {
	      				document.getElementById("loginusertag").innerHTML = "<a href='#' onClick=submitPage('securelogout')>Logout</a>";
	      			} 
	      			if (y != null && y[0] != null) {  
	      			//if (document.getElementById("promoDescription") != null) {
						x = xmlhttp.responseXML.getElementsByTagName("isPromoCodeEntered");
						var ispromoentered = x[0].childNodes[0].nodeValue;
						if (ispromoentered == 'Y') {
							x = xmlhttp.responseXML.getElementsByTagName("promoCodeDescription");
							if (x != null && (document.getElementById("promoDescription") != null)) {
								document.getElementById("promoDescription").innerHTML = x[0].childNodes[0].nodeValue;
							}
							var pcode = "";
							x = xmlhttp.responseXML.getElementsByTagName("promoCode");
							if (x != null) {
								pcode = x[0].childNodes[0].nodeValue;
							}
							
						}
						}
					}
      			}
    		}
		  	xmlhttp.open("GET", url, true);
		  	xmlhttp.send(null);
		} else {
			alert("Your browser does not support XMLHTTP.");
		}
	}
	
	
	/*function makeAjaxCall() {
		if (checkCookieEnabled()) {				
			promoAjax();	
		} else {
			alert("Please enable cookies");
		}
	}
		
	function promoAjax(areaId, textBoxId) {
		var promocode = document.getElementById(textBoxId).value;
		var url = "/RDNavigationServlet?gotopath=samepage&promocode=" + promocode;
		var xmlhttp;
		if (window.XMLHttpRequest) {// code for IE7, Firefox, Mozilla, etc.
			xmlhttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {// code for IE5, IE6
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp != null) {
			xmlhttp.onreadystatechange = function() {
    			if(xmlhttp.readyState == 4) {
      				var promoDesc = xmlhttp.responseText;
      				document.getElementById(areaId).innerHTML = promoDesc;
      			}
    		}
		  	xmlhttp.open("GET", url, true);
		  	xmlhttp.send(null);
		} else {
			alert("Your browser does not support XMLHTTP.");
		}
	}*/
	
	function submitPromoCode(areaId, textBoxId, path) {
		if (document.getElementById(textBoxId) == null) {
			submitPage(path);
			return;
		}
		if (checkCookieEnabled()) {		
			/*if (path == null || path == "" || path == "samepage") {
				promoAjax(areaId, textBoxId);
			} else {
				var promocode = document.getElementById(textBoxId).value;
				document.location.href="/RDNavigationServlet?gotopath="+path+"&promocode="+promocode;			
			}*/
			
			var promocode = document.getElementById(textBoxId).value;
			var xmlhttp;
			var url = "/RDNavigationServlet?gotopath=_loadpromo&promocode=" + promocode +"&path=" + path;
			if (window.XMLHttpRequest) {// code for IE7, Firefox, Mozilla, etc.
				xmlhttp = new XMLHttpRequest();
			} else if (window.ActiveXObject) {// code for IE5, IE6
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (xmlhttp != null) {
				xmlhttp.onreadystatechange = function() {
	    			if(xmlhttp.readyState == 4) {		    			
	    				var isValidPromoCode = "Y";
	    				x = xmlhttp.responseXML.getElementsByTagName("isValidPromoCode");
    					if (x != null) {
    						isValidPromoCode = x[0].childNodes[0].nodeValue;
    					}
    					if (isValidPromoCode == 'N') { 
	    					
    						alert("The Promotion Code '" + promocode + "' is Not Valid. \n\nPlease Enter a Valid Promotion Code or Leave the Box Blank.");
    						document.getElementById(textBoxId).value = "";  						
    						
    					} else {
    						if (path == null || path == "" || path == "samepage") {
	    						x = xmlhttp.responseXML.getElementsByTagName("promotionDescription");
	    						if (x != null && areaId != null && areaId != '' && (document.getElementById(areaId) != null))  {
    								var promoDesc = x[0].childNodes[0].nodeValue;
    								document.getElementById(areaId).innerHTML = promoDesc;
    							}	      						
	      					} else {
	      						x = xmlhttp.responseXML.getElementsByTagName("forward");
	    						if (x != null) {
    								var forwardPath = x[0].childNodes[0].nodeValue;
    								document.location.href = forwardPath;
    							}
	      					}
    					}
	      			}
	    		}
			  	xmlhttp.open("GET", url, true);
			  	xmlhttp.send(null);
			} else {
				alert("Your browser does not support XMLHTTP.");
			}
		} else {
			alert("Please enable cookies");
		}
	}
	
	
