

function gup( name )
		{
			//alert("Hi Lowell");
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null ){
		return "";
	  	}
	else{
		return results[1];
		}
	}


	
	function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


	function createCookie(name,value,days) {
		
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}


	function setcookies(){
			createCookie('aff_iata',gup('a'),30);
			createCookie('aff_name',gup('b'),30);
			createCookie('aff_num',gup('c'),30);
			createCookie('aff_return',gup('d'),30);
			createCookie('optParam',gup('e'),30);
	}
	
	
	function deleteCookies(){
		var cookie_date = new Date ( );  // current date & time
		cookie_date.setTime ( cookie_date.getTime() - 1 );
		document.cookie = "aff_iata=;    expires=" + cookie_date.toGMTString();
		document.cookie = "aff_name=;    expires=" + cookie_date.toGMTString();
		document.cookie = "aff_num=;    expires=" + cookie_date.toGMTString();
		document.cookie = "aff_return=;    expires=" + cookie_date.toGMTString();
		document.cookie = "optParam=;    expires=" + cookie_date.toGMTString();
		}
		
		
		
		function delBlanks(strng) {
   			var result=""
  			var i
   			var chrn
   			for (i=0;i<strng.length;++i) 
				{
      			chrn=strng.charAt(i)
      			if (chrn!=" ") result += chrn
   				}
  		 return result
		}

		
		function nameDefined(ckie,nme){
   			var splitValues
   			var i
   			for (i=0;i<ckie.length;++i)
   				{
      			splitValues=ckie[i].split("=")
      			if (splitValues[0]==nme) return true
  				 }
  			 return false
			}

		
		function testCookie(cname) {  
		   var cookie=document.cookie          
		   var chkdCookie=delBlanks(cookie)  
		   var nvpair=chkdCookie.split(";")
		   if(nameDefined(nvpair,cname))       
  			 {   
			 return true;
  			 }
  		 	else return false;
		}

		
		
		
		

// This is the case where theuser has just landed from an affiliate site. The information is encoded in the URL.  the cookies dont exist yet.


	

if (gup('a').length >1 ){	
	if( testCookie('aff_iata') && (readCookie('aff_iata') != gup('a')) ){deleteCookies()}   // delete ALL cookies and reset if cookies from a different affiliate exist.	
	 setcookies();
	document.write("<iframe frameborder='0' name='if1'  scrolling='no' width='770' height='14' marginwidth='1' marginheight='1' src='http://couples.com/reservhoteljs/AffiliateBanner.asp?a=" + gup('a') + "&b=" +  gup('b') + "&c=" +  gup('c') + "&d=" +  gup('d') + "&e=" + gup('e') + "'></iframe>");	

	}





// the user has been to an affiliate within the last 30 days, or they have navigated away from the landing page.
//either way, create the iframe and display the affiliate information
else if ( readCookie('aff_iata') != null){
	var iata = readCookie('aff_iata');
	var name = readCookie('aff_name');
	var num = readCookie('aff_num');
	var url = readCookie('aff_return');
	var opt = readCookie('optParam');
	document.write("<iframe frameborder='0' name='if1' id='if1' scrolling='no' width='770' height='14' marginwidth='1' marginheight='1' src='http://couples.com/reservhoteljs/AffiliateBanner.asp?a=" + iata + "&b=" +  name + "&c=" +  num + "&d=" +   url + "&e=" + opt + "'></iframe>");	
}

else 

//LOWELL ADDED THE STATEMENT BELOW OTHERWISE WE GET A JS ERROR - GOT THIS FROM cmLB.js - seem to remember that we did need something when there was no affiliate info present
{
	//document.write("<iframe frameborder='0' name='if1'  scrolling='no' width='770' height='25' marginwidth='1' marginheight='1' src='/reservhoteljs/AffiliateBanner.asp'></iframe>");	
}

//BELOW IS WHAT LOWELL REPLACED.
//{
	//Nothing to do here - dont create the iFrame.  the user has not been to an affiliate site
//}




