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 getAllCookies() { 
var cookies;
propertycount = 0;   // global var
ratingcount = 0;	   // global var
var everycookievalue = document.cookie; 
var pairsSplit = everycookievalue.split(";"); 
var patternNospace = /[^\s]+/; 
var finalName; 
var finalValue; 
for ( count=0 ; ( pairsSplit[count] != undefined ) ; count++ ) 
   {elementsSplit = pairsSplit[count].split("="); 
    finalName = elementsSplit[0].match(patternNospace); 
    finalName = finalName + '';   						// converts finalName to type string
    // finalValue = elementsSplit[1].match(patternNospace);
    finalValue = GetCookie(finalName);
    // property052705-10424=1
    if (  ((finalName.substring(0,8) == 'property') && (finalName.substring(14,15) == '-') && (finalValue == 1))    ||
          ((finalName.substring(0,8) == 'OLDSTYLE') && (finalValue == 1)) 
       )
      {cookies = cookies + finalName + ' ';
       propertycount = propertycount + 1;
      }
    if (finalName.match('_rating'))
      {cookies = cookies + finalName + ' ';
       ratingcount = ratingcount + 1;
      }
   } 

return cookies;

} 

//---------------------------------------------------------------------------------------------------------------------------------
function DisplayTravelFolderNew (twidth,theight,tcellpadding) { 

// This function needs to do two things:
// 1) Prior to a permanent travel folder being created, it needs to: 
//		a) display "no properties in your folder"; or (b) display "n properties in your folder" and display "View" and "Contact Us" buttons.
// 2) After a permanent travel folder has been created, it needs to display "n properties in your folder" and display "View" button.


var tfid = GetCookie('tfid');
var cook = document.cookie;
var twidthoriginal;

if ((twidth == null) || (twidth == ""))
   {twidthoriginal == 'no';
    twidth=150;}
 else
   {twidthoriginal == 'yes';}
if ((theight == null) || (theight == ""))
   {theight=87;}
if ((tcellpadding == null) || (tcellpadding == ""))
   {tcellpadding=5;}


// 1) Prior to a permanent travel folder being created, it needs to: 
//		a) display "no properties in your folder"; or (b) display "n properties in your folder" and display "View" and "Contact Us" buttons.

if ((tfid == null) || (tfid == ""))
   {// case: pre-contact temporary travel folder

    cookies = getAllCookies();
    if (propertycount == 0)
       {message = 'Add one or more properties that interest you, then <b>contact us (by <a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi#form" class=underlinetext>form</a> or phone)</b> for price and availability.'}
     else
       {message = 'Add as many properties as you like! Then <b>contact us (by <a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi#form" class=underlinetext>form</a> or phone)</b>, so we can help you with price, availability, alternative properties, and booking.'}

    if ((twidth == 150) && (twidthoriginal == 'yes'))
       {// new style pages: travel folder box appears in left menu
        document.write('<link rel=stylesheet Type="text/css" href="http://www.villasintl.com/css/main.css">');

        document.write('<img src="http://www.villasintl.com/newdesign/spacer.gif" width=100 height=1 border=0><table width="'+twidth+'" height="'+theight+'" border="0" cellspacing="1" cellpadding="'+tcellpadding+'" bgcolor="#004646">');
        document.write('<tr align="middle">');
        document.write('<td valign="middle" bgcolor="#FFFFFF">');
        document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0">');

        document.write('<tr><td valign=top><div class="tftext3">YOUR TRAVEL FOLDER</div><div class="tftext4">'+message);
        cookies = getAllCookies();
        document.write('<br><br><div align=right><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi">properties: '+propertycount+'</a></b>');
        document.write('<br><div align=right><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi">rated by you: '+ratingcount+'</a></b>');
        // document.write('<br>'+document.cookie);
        document.write('</div></td></tr>');

        document.write('</table></div></td></tr></table>');

        document.write('<table width="'+twidth+'" border="0" cellspacing="0" cellpadding="0">');
document.write('<tr><td bgcolor="#FFFFFF"><div align="center"><img src="http://www.villasintl.com/newdesign/tfmenu3.jpg" width="150" height="26" border="0" vspace=2 usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="95,6,149,19" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi#form" alt="Contact Us"><area shape="rect" coords="38,5,92,20" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi" alt="View"></map></div></td></tr>');
        document.write('<tr><td bgcolor="#FFFFFF">Already have a permanent travel folder? <a href="http://www.villasintl.com/cgi-bin/travelfolder1/account_signin.cgi"><b>Sign in</b></a>.</td></tr>');
        document.write('</table>');
       }
      else
       {// case: old-style pages; travel folder box appears in top menu

       twidth = 290;
       theight = 87;
       tcellpadding=5;

       document.write('<link rel=stylesheet Type="text/css" href="http://www.villasintl.com/css/main.css">');
       document.write('<table width="'+twidth+'" border="0" cellspacing="1" cellpadding="'+tcellpadding+'" bgcolor="#004646">');
       document.write('<tr>');
       document.write('<td valign="top" bgcolor="#FFFFFF">');

         document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0">');
         document.write('<td valign="top" bgcolor="#FFFFFF">');

            document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0">');
            document.write('<tr><td valign=top><div class="tftext3">YOUR TRAVEL FOLDER</div><div class="tftext4">');
            document.write('Add properties to your folder, then <b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi#form">contact us</a></b> for more info.');
            cookies = getAllCookies();
            document.write('<br><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi">properties: '+propertycount+'</a></b>');
            document.write('<br><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi">rated by you: '+ratingcount+'</a></b></div>');
            document.write('</td>');
            document.write('</tr></table>');

          document.write('</td>');
          document.write('<td width=90 valign=top align=right><img src="http://www.villasintl.com/newdesign/tfmenu5.jpg" border=0 width=64 height=61 usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="0,46,54,81" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi#form" alt="Contact Us"><area shape="rect" coords="0,26,54,41" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtemptravelfolder.cgi" alt="View"></map></td>');
          document.write('</tr>');
          document.write('</table>');

       document.write('</td>');
       document.write('</tr>');
       document.write('</table>');

       document.write('<span class=tftext4 align=right>Already have a permanent travel folder? <a href="http://www.villasintl.com/cgi-bin/travelfolder1/account_signin.cgi"><b>Sign in</b></a>.</span>');
       }

   }
 else
   {// case: post-contact travel folder with a travel folder id: tfid 

    var firstname = GetCookie('firstname');
    var firstnamesubstrings=firstname.split('+');

    if (twidthoriginal == 'yes')
      {// new-style page case: travel folder box appears in left menu

       document.write('<img src="http://www.villasintl.com/newdesign/spacer.gif" width=100 height=1 border=0><table width="'+twidth+'" height="'+theight+'" border="0" cellspacing="1" cellpadding="'+tcellpadding+'" bgcolor="#004646">');
       document.write('<tr align="middle">');
       document.write('<td valign="middle" bgcolor="#FFFFFF">');
       document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0">');

       document.write('<tr><td valign=top><div class="tftext3">YOUR TRAVEL FOLDER</div><div class="tftext4">');
       document.write('You are signed in, ');
       for (i=0; i < firstnamesubstrings.length; ++i)
            {document.write(firstnamesubstrings[i]);}
       cookies = getAllCookies();
       document.write('!<br><br><div align=right><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtravelfolder.cgi">properties: '+propertycount+'</a></b>');
       document.write('<br><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewemail.cgi">messages: 0</a></b></div>');
       document.write('</div></td></tr>');

       document.write('</table></div></td></tr></table>');

       document.write('<table width="'+twidth+'" border="0" cellspacing="0" cellpadding="0">');
       document.write('<tr><td bgcolor="#FFFFFF"><div align="center"><img src="http://www.villasintl.com/newdesign/tfmenu2.jpg" width="150" height="26" border="0"  usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="95,6,149,19" href="http://www.villasintl.com/cgi-bin/travelfolder1/signout.cgi" alt="Sign Out"><area shape="rect" coords="38,5,92,20" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtravelfolder.cgi" alt="View"></map> </div></td>');
       document.write('</tr></table>');
      }
    else
      {// old-style page case: travel folder box appears in top menu

       twidth = 200;
       theight = 87;
       tcellpadding=5;

       document.write('<link rel=stylesheet Type="text/css" href="http://www.villasintl.com/css/main.css">');
       document.write('<table width="'+twidth+'" border="0" cellspacing="1" cellpadding="'+tcellpadding+'" bgcolor="#004646">');
       document.write('<tr>');
       document.write('<td valign="top" bgcolor="#FFFFFF">');

         document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0" align=right>');
         document.write('<td valign="top" bgcolor="#FFFFFF">');

            document.write('<table width="width=100%" border="0" cellspacing="0" cellpadding="0">');
            document.write('<tr><td valign=top><div class="tftext3">YOUR TRAVEL FOLDER</div><div class="tftext4">');
            document.write('You are signed in,<br>');
            for (i=0; i < firstnamesubstrings.length; ++i)
               {document.write(firstnamesubstrings[i]);}
            cookies = getAllCookies();
            document.write('!<br><br><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtravelfolder.cgi">properties: '+propertycount+'</a></b>');
            document.write('<br><b><a href="http://www.villasintl.com/cgi-bin/travelfolder1/viewemail.cgi">messages: 0</a></b></div>');
            document.write('</td>');
            document.write('</tr></table>');

          document.write('</td>');
          document.write('<td width=64><img src="http://www.villasintl.com/newdesign/tfmenu4.jpg" border=0 width=64 height=88 usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="0,71,54,86" href="http://www.villasintl.com/cgi-bin/travelfolder1/signout.cgi" alt="Sign Out"><area shape="rect" coords="0,53,54,68" href="http://www.villasintl.com/cgi-bin/travelfolder1/viewtravelfolder.cgi" alt="View"></map></td>');
          document.write('</tr>');
          document.write('</table>');

       document.write('</td>');
       document.write('</tr>');
       document.write('</table>');
      }

   }

}


//---------------------------------------------------------------------------------------------------------------------------------
function DisplayTravelFolder (twidth,theight,tcellpadding) { 

var tfid = GetCookie('tfid');
// var cook = document.cookie;

var newdesign = GetCookie('newdesign');
if (newdesign == 1)
   {DisplayTravelFolderNew(twidth,theight,tcellpadding);
    return(true);
   }

if ((twidth == null) || (twidth == ""))
   {twidth=150;}
if ((theight == null) || (theight == ""))
   {theight=87;}
if ((tcellpadding == null) || (tcellpadding == ""))
   {tcellpadding=5;}

if ((tfid == null) || (tfid == ""))
   {document.write('<table width="'+twidth+'" height="'+theight+'" border="0" cellspacing="1" cellpadding="2" bgcolor="#007BE3">');
    document.write('<tr align="middle">');
    document.write('<td valign="middle" bgcolor="#FFFFFF">');
//    document.write('<div align="left">');
    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="'+tcellpadding+'">');
//    document.write('<tr><td valign=top><div class="tftext2">TRAVEL FOLDER</div><div class="tftext">Place all your favorite properties in your folder as you browse. Register now to get your folder!</div></td></tr>');

    if (twidth == 150)
       {document.write('<tr><td valign=top><div class="tftext2">TRAVEL FOLDER</div><div class="tftext">See some properties you like? Set up your own travel folder and keep them for future reference.</div></td></tr>');
       }
      else
       {document.write('<tr><td valign=top><div class="tftext2">TRAVEL FOLDER</div><div class="tftext">See some properties you like? Set up your own travel folder and keep them for future reference.</div></td></tr>');
       }

    document.write('</table></div></td>');

    document.write('</table></div></td>');
    document.write('<td bgcolor="#FFFFFF"><div align="center"><img src="http://www.villasintl.com/travel_folder-sm.jpg" width="67" height="71" border="0"  usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="7,53,61,66" href="http://www.villasintl.com/cgi-bin/travelfolder/account_signin.cgi" alt="Sign In"><area shape="rect" coords="7,37,61,50" href="http://www.villasintl.com/cgi-bin/travelfolder/account_register.cgi" alt="Register"></map></div></td>');
    document.write('</tr></table>');
   }
 else
   {var firstname = GetCookie('firstname');
    var firstnamesubstrings=firstname.split('+');
    document.write('<table width="180" border="0" cellspacing="1" cellpadding="2" bgcolor="#007BE3">');
    document.write('<tr align="middle">');
    document.write('<td valign="top" bgcolor="#FFFFFF">');
    document.write('<div align="left">');
    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="5">');
    document.write('<tr><td valign=top><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font size="2" color="FF0000">TRAVEL FOLDER</font></b></font><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><br>You are signed in, ');
    for (i=0; i < firstnamesubstrings.length; ++i)
        {document.write(firstnamesubstrings[i]);
         document.write(' ');}
    document.write('!</div></font></td></tr>');
    document.write('</table></div></td>');
    document.write('<td bgcolor="#FFFFFF"><div align="center"><img src="http://www.villasintl.com/travel_folder2-sm.jpg" width="67" height="71" border="0"  usemap="#travelfolder"><map name="travelfolder"><area shape="rect" coords="7,53,61,66" href="http://www.villasintl.com/cgi-bin/travelfolder/signout.cgi" alt="Sign Out"><area shape="rect" coords="7,37,61,50" href="http://www.villasintl.com/cgi-bin/travelfolder/viewtravelfolder.cgi" alt="View"></map></div></td>');
    document.write('</tr></table>');
   }

}
