function checkdate(input){
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
alert("Invalid Date Format. Please correct and submit again.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}




function validate(d1,d2){

//Следует добавить проверку синтаксиса введенной даты dd/mm/yyyy и только.
// при этом d-0 или 1, d = 1 .. 0 ;  m=0,1,2,3. m=1..9; y=2, y=0, y=0,1, y=1..9 и все!
var valreturn = false;
if (checkdate(d1) && checkdate(d2)) {

if(
 ((d1.value.substring(6, 10) > day_today().substring(6, 10)) 
   ||
  ((d1.value.substring(6, 10) == day_today().substring(6, 10)) &&
   (d1.value.substring(0, 2)  > day_today().substring(0, 2))) 
   ||
   ((d1.value.substring(6, 10) == day_today().substring(6, 10)) &&
       (d1.value.substring(0, 2) == day_today().substring(0, 2)) &&       
       (d1.value.substring(3, 5)  >  day_today().substring(3, 5)))
  )
&&
(
(d1.value.substring(6, 10) < d2.value.substring(6, 10)) 
||
((d1.value.substring(6, 10) == d2.value.substring(6, 10)) &&
 (d1.value.substring(0, 2)  <  d2.value.substring(0, 2))) 
||
((d1.value.substring(6, 10) == d2.value.substring(6, 10)) &&   
  (d1.value.substring(0, 2) == d2.value.substring(0, 2)) &&   
  (d1.value.substring(3, 5)  <  d2.value.substring(3, 5)))
)
)
valreturn = true;  //must be true
   else { valreturn=false}  //musr be false
}
return valreturn
}


function avalability(d1,d2,ad,be,pe,sm,ty){

 if( (sm == 'SMOKING_ROOM') && ( ty == 'PREMIUM_ROOM')) return 0; else
if (d1.value == '05/08/2009') return 0; else return 0;
// return 0 means the request can't be aproved
}



function day_today(){
var da,mo,ye;
tod=new Date();
da=tod.getDate() ;
mo=tod.getMonth() +1 ;
ye=tod.getYear() + 1900;
// 2 digits month.
	m2 = '00' + mo;
	m2 = m2.substr(m2.length - 2);
	// 2 digits day.
	d2 = '00' + da;
	d2 = d2.substr(d2.length - 2);
                   y = '' + ye;
	// YYYY-MM-DD
      y = ye % 100;
      y = ((y < 50) ? (2000 + y) : (1900 + y));
// document.write(m2 + '/' + d2 + '/' + y);
	return (m2 + '/' + d2 + '/' + y);
}

function checkedbed(b){
if (b[0].checked) { return 'KING_SIZE_BED'}
if (b[1].checked) { return '2_DOUBLES_BEDS'}
}

function checkedpet(p){
if (p[0].checked) { return 'WITH_PET'}
if (p[1].checked) { return 'WITHOUT_PET'}
}

function checkedsmoke(s){
if (s[0].checked) {return 'SMOKING_ROOM'}
if (s[1].checked) { return 'NONSMOKING'}
}

function checkedtype(t){
if (t[0].checked) {return 'REGULAR_ROOM'}
if (t[1].checked) { return 'PREMIUM_ROOM'}
}


function validate3(dd1,dd2,aa,bb,pp,ss,ty,fn,ln,adr,cty,st,zip,cn,cnum,cexp,code,tt,eadr) { 
if ((fn.value.length==0) || (ln.value.length==0) || (cn.value.length==0) || (cnum.value.length==0) || (cexp.value.length==0) || (code.value.length==0) || (tt.value.length==0) || (eadr.value.length==0))  {alert("All fields are requered");return false} else {sendingdata(dd1,dd2,aa,bb,pp,ss,fn,ln,adr,cty,st,zip,cn,cnum,cexp,code,tt,eadr); return true}
}

function sendingdata(d1,d2,a,b,p,s,ty,f,l,dr,c,s,z,c,n,c,cod,t,e){alert("Thank you for your reservation. If you do not receive an email from us within 24 hours, please call to confirm your reservation. Occasionally, some spam control programs block delivery."); window.close(); return true}


function generate1(d1,d2,a,b,p,s,t,r){

nw=open('','NULL','width=400,height=500,location=yes,toolbar=yes,menubar=yes,left=0,right=0,scrollbars=yes,resizable=yes,status=yes');
 nw.document.open();

 nw.document.write("<html><head><title>Reservation Form</title>");
 nw.document.write("<style type='text/css'>"); 
 nw.document.write("h2 {color: #c22202; font-family: 'Trade Gothic', Arial; font-size: 18px; padding: 5px}");
nw.document.write(".t {color:#552a14; font-family:'Trade Gothic', Arial; font-size:12px; padding:5px}");
nw.document.write("td {color:#552a14; font-family:'Trade Gothic', Arial; font-size:12px; padding:5px}");
 nw.document.write("</style>");
 nw.document.write("<script language='JavaScript' type='text/JavaScript'>function validate2(fn,ln,ad,ci,st,zip,cna,cnu,exp,code,ph,em) {if ((fn.value.length==0) || (ln.value.length==0) || (ad.value.length==0) || (ci.value.length==0) || (st.value.length==0) || (zip.value.length==0) || (cna.value.length==0) || (cnu.value.length==0) || (exp.value.length==0) || (code.value.length==0) || (ph.value.length==0) || (em.value.length==0)) {alert('All fields are required');return false;} else {alert('Thank you for your reservation. If you do not receive an email from us within 24 hours, please call to confirm your reservation. Occasionally, some spam control programs block delivery.');window.close();return true;}}</script>");
 nw.document.write("</head><body bgcolor=#f7dd9d marginheight=o topmargin=0>");
 nw.document.write("<h2><center>The suite you requested is available.</center></h2>");
 nw.document.write("<DIV CLASS=t>Dates from: &nbsp;");
 nw.document.write(d1.value);
 nw.document.write("&nbsp; to: &nbsp;");
 nw.document.write(d2.value);
 nw.document.write("<br> for ");
 nw.document.write( a.value); 
 nw.document.write(" adult(s) ");
 nw.document.write(" with options: <br>");
 nw.document.write(b);
 nw.document.write( "&nbsp;");
 nw.document.write(s);
 nw.document.write("&nbsp;");
 nw.document.write(p);
 nw.document.write( "&nbsp; and &nbsp;");
 nw.document.write(t);

nw.document.write("<p>We accept Visa, American Express, Discover and  Master Cards<br>");
nw.document.write("<img src='images/4cards.gif'> ");
nw.document.write("<p>To confirm your reservation, please provide your contact details below:<p> ");
nw.document.write("<p>All fields are required<p> ");

nw.document.write("<form action='http://www.hostmonster.com/monstermail' method='POST' name='reservation' enctype='multipart/form-data' onSubmit='return validate2(firstname, lastname, addr, city, state, zipcode, cardname, cardnumber, cardexp, verificationcode, phone, email);'>");

// http://formmail.dreamhost.com/cgi-bin/formmail.cgi

nw.document.write("<input type=hidden name='subject' value='Reservation'>");
nw.document.write("<input type=hidden name='sendtoemail' value='info@easyreserve.biz'>");
// reservations#dtreservations.dbank.net

nw.document.write("<input type=hidden name=room value="); 
nw.document.write(r);
nw.document.write(">");
nw.document.write("<input type=hidden name=dd1 value="); 
nw.document.write(d1.value);
nw.document.write(">");
nw.document.write("<input type=hidden name=dd2 value=");
nw.document.write(d2.value);
nw.document.write(">"); 
nw.document.write("<input type=hidden name=aa value=");
nw.document.write(a.value);
nw.document.write(">"); 
nw.document.write("<input type=hidden name=bb value=");
nw.document.write(b);
nw.document.write(">"); 
nw.document.write("<input type=hidden name=pp value=");
nw.document.write(p);
nw.document.write(">");
nw.document.write("<input type=hidden name=ss value=");
nw.document.write(s);
nw.document.write(">"); 
nw.document.write("<input type=hidden name=tt value=");
nw.document.write(t);
nw.document.write(">"); 
 
nw.document.write("<table cellspacing=0 cellpadding=0>");
nw.document.write("<tr><td>First Name </td><td><input type=text size=22 name=firstname></td></tr>"); 
nw.document.write("<tr><td>Last Name </td><td><input type=text size=22 name=lastname></td></tr>"); 
nw.document.write("<tr><td>Address </td><td><input type=text size=22 name=addr></td></tr>"); 
nw.document.write("<tr><td>City </td><td><input type=text size=22 name=city></td></tr>"); 
nw.document.write("<tr><td>State</td><td><input type=text size=22 name=state></td></tr>"); 
nw.document.write("<tr><td>Zip</td><td><input type=text size=22 name=zipcode></td></tr>");
nw.document.write("<tr><td>Card Holder name </td><td><input type=text size=22 name=cardname></td></tr>");  
nw.document.write("<tr><td>Card Number </td><td><input type=text size=22 name=cardnumber></td></tr>"); 
nw.document.write("<tr><td>Expiration Date </td><td><input type=text size=22 name=cardexp></td></tr>"); 
nw.document.write("<tr><td>Card Verification Code </td><td><input type=text size=4 name=verificationcode></td></tr>"); 
nw.document.write("<tr><td>Contact phone # </td><td><input type=text size=12 name=phone></td></tr>"); 
nw.document.write("<tr><td>E-mail </td><td><input type=text size=22 name=email></td></tr>");
nw.document.write("<tr><td>Special Needs</td><td><input type=text size=22 name=comment></td></tr>");
nw.document.write("</table></DIV>"); 
 nw.document.write("<input type='submit' value='Submit'>");
nw.document.write("<input type='reset' value='Reset'>");  
nw.document.write("</form></body></html>");
// nw.focus();
nw.document.close(); 
// nw.focus();



}



function generate2(d1,d2,a,b,p,s,t){

nw=open('','NULL','width=400,height=500,location=yes,toolbar=yes,menubar=yes,left=0,right=0,scrollbars=yes,resizable=yes,status=yes');
 nw.document.open();

 nw.document.write("<html><head><title>Negative generation</title>");

nw.document.write("<style type='text/css'>"); 
 nw.document.write("h2 {color: #c22202; font-family: 'Trade Gothic', Arial; font-size: 18px; padding: 5px}");
 nw.document.write("h3 {color:#552a14; font-family:'Trade Gothic', Arial; font-size:12px; font-weight:bold; padding:5px}");

nw.document.write(".t {color:#552a14; font-family:'Trade Gothic', Arial; font-size:14px; font-weight:normal; padding:5px}");

 nw.document.write("</style>");
 nw.document.write("</head><body bgcolor=#f7dd9d marginheight=o topmargin=0>");

// next 2 lines will be substitute by full text in next comments
 nw.document.write("<h2><center><br>&nbsp;<br>Reservation system is <br>under construction. <br>&nbsp;<br>&nbsp;<br>Please call the office, <br>919-687-4444, <br>for reservations.</center></h2>");
// end of temporary text
 
/*
 nw.document.write("<h2>We're sorry, but this type of suite is not available on these dates:</h2>");
 nw.document.write("<div class=t>from: ");
 nw.document.write(d1.value);
 nw.document.write("&nbsp; to: &nbsp;");
 nw.document.write(d2.value);
 nw.document.write("<p>with options:<br> Adult=");
 nw.document.write(a.value);
 nw.document.write("<br>  bed = ");
 nw.document.write(b);
 nw.document.write("<br>  pet=");
 nw.document.write(p);
 nw.document.write("<br>  smoke=");
 nw.document.write(s);
nw.document.write("<br>  type=");
 nw.document.write(t);
 nw.document.write("<p>Duke Tower has many suite alternatives available and we suggest that you may also wish to try a different type of suite or bed type for your stay. <p>Or please call our staff at 919-687-4444 or at 1-866-385-3869.");
*/

 nw.document.write("<p><INPUT TYPE='submit' VALUE='Close' OnClick='window.close(); return true'></form></div>");
 nw.document.write("</body></html>");
 nw.document.focus();
nw.document.close(); 
}
