﻿



function BookHotel(page){ 
 
          var fYear = getObj("arrivalMonthYear").value.substring(0,4);
        var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
        
        var tYear = getObj("departureMonthYear").value.substring(0,4);
        var tmonth = getObj("departureMonthYear").value.substring(4,6);
        
        if (fmonth.substring(0,1) == "0"){
			
            fmonth = fmonth.substring(1,2);			
         }        
         fmonth = parseFloat(fmonth)+1;
        
        
        if (tmonth.substring(0,1) == "0"){        
           tmonth = tmonth.substring(1,2);   		  
         }
        
          tmonth = parseFloat(tmonth)+1;
iRet = window.open( "http://www.choicehotels.ca/rooms/CN715?srp="+getObj("srp").value+"&checkin="+ getObj("arrivalDay").value +"-"+fmonth+"-"+fYear+"&checkout="+ getObj("departureDay").value +"-"+tmonth+"-"+tYear);

//        var fmonth = getObj("arrivalMonthYear").value.substring(4,6);
//        
//        var tmonth = getObj("departureMonthYear").value.substring(4,6);
//      
//        fmonth = parseFloat(fmonth)+1;
//        tmonth = parseFloat(tmonth)+1;
//     
////        if (fmonth.substring(0,1) == "0"){
////            fmonth = fmonth.substring(1,2);
////         }
////        if (tmonth.substring(0,1) == "0"){
////           tmonth = tmonth.substring(1,2);
////         }
//         
//        iRet = window.open("http://www.choicehotels.ca/hotels/roomRates?hotel=CN715" +
//        "&srp=" + getObj("srp").value + 
//        "&minisrp=" + getObj("minisrp").value + 
//        "&day=" + getObj("arrivalDay").value + 
//        "&month=" + fmonth + 
//        "&depart_day=" + getObj("departureDay").value + 
//        "&depart_month=" + tmonth + 
//        "&nadult=" + getObj("nadult").value + 
//        "&nchild=" + getObj("nchild").value + 
//        "&destination=Winnipeg" );



 
 
  var pagename=page+"?Visitor=1"
  window.parent.location.href=pagename;	
  return true;
}

function Validate1()
{

		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		
		if(getObj("Name").value=='')
		{
			alert("Please enter your name");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RequiredFieldValidator3").style.visibility="visible";
			return false;
		}
		
		if(getObj("FromEmail").value=='')
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RequiredFieldValidator1").style.visibility="visible";
			return false;
		}
		if (!filter.test(getObj("FromEmail").value))
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RegularExpressionValidator1").style.visibility="visible";
			return false;
		}

        if(getObj("ToEmail").value=='')
		{
			alert("Please enter a valid email address of the recipient");
			getObj("RequiredFieldValidator2").style.visibility="visible";
			return false;
		}
		
		if (!filter.test(getObj("ToEmail").value))
		{
			alert("Please enter a valid email address of the recipient");
			getObj("RegularExpressionValidator2").style.visibility="visible";
			return false;
		}
		
		if(getObj("Subject").value=='')
		{
			alert("Please enter a subject line for the email");
			getObj("RequiredFieldValidator4").style.visibility="visible";
			return false;
		}

    
	  if(confirm('Your email has been sent!  Would you like to subscribe to our hotel e-newsletter to receive updates on specials happening in and around our hotel?'))
	  {
	    var ok = 1
    	  //window.getObj("hidMail").value = 1;
    	  
	  }        
	 var cancel =0
	 if(ok ==1 && cancel == 0)
	  {
	   window.getObj("hidMail").value = 1;
	  }  
	   else 
	  {
	    window.getObj("hidMail").value = 0;
	  }
	  
		return true;
}

	function Validate2()
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

		if(getObj("FromEmail").value=='')
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RequiredFieldValidator1").style.visibility="visible";
			return false; 
		}
		if (!filter.test(getObj("FromEmail").value))
		{
			alert("Please enter your valid email address");
			getObj("RequiredFieldValidator1").style.visibility="hidden";
			getObj("RequiredFieldValidator3").style.visibility="hidden";
			getObj("RegularExpressionValidator1").style.visibility="visible";
			return false;
		}

        window.getObj("hidMail").value = 1;
	    return true;
	}
	
	
	
	function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

