﻿

function sendFeedback(){
    var body = "";
    body += "\n\n\n\n\n\n\n";
    body += "================================================\n";
    body += "Site feedback provided from the following page:\n";
    body += location.href;
    location.href="mailto:MarketingServices@Andersencorp.com?subject=Site%20Feedback%20-%20"+document.title+"&body=" + escape(body);
}



var OpenWin = null;
function GetPage(page,width,height) {
    var win_toolbar = "toolbar=" + "no";
    var win_width = "width=" + width;
    var win_height = "height=" + height;
    var win_left = "left=" + (screen.width - width) / 2;
    var win_top = "top=" + (screen.height - height) / 2;
    var win_status = "status=" + "no";
    var win_location = "location=" + "no";
    var win_menubar = "menubar=" + "no";
    var win_scrollbars = "scrollbars=" + "yes";
    var win_resizable = "resizable=" + "no";
    var win_parameters = win_toolbar + "," + win_width + "," + win_height + "," + win_left + "," + win_top + "," + win_status + "," + win_location + "," + win_menubar + "," + win_scrollbars + "," + win_resizable;
    OpenWin = window.open(page,'ThisPage', win_parameters);
    if (!OpenWin.closed){OpenWin.focus();}
}

var _errorWindow = null;
function openErrorWindow(msg) {
  _errorWindow = window.open();
  _errorWindow.document.open();
  _errorWindow.document.write('<html><head><title>Error</title></head><body>');
  _errorWindow.document.write(msg);
  _errorWindow.document.write('</body></html>');
  _errorWindow.document.close();
 if (!_errorWindow.closed){_errorWindow.focus();}
}

function openVideo(video){
    alert(video)
}


function ShadowboxResponse() {

     Shadowbox.open({
        title:      '',
        type:       'html',
        content:    '<table style=\"background-color: #f5f5f5; font-family: Arial;\" height=\"150\" width=\"100%\"><tr><td valign=\"top\"><img src=\"/cmsvirtualUserfiles/images/header_ItemSaved.jpg\"></td></tr><tr><td align=\"center\" valign=\"top\"><strong>Your item has been saved.</a><br><a href=\"javascript:Shadowbox.close();\" style=\"color: #70A088;\">Click here</a> to continue browsing<br>or go to <a href=\"/project-planner/view.aspx\" style=\"color: #70A088;\">Project Planner.</a></td></tr></table>',
        height:     151,
        width:      208
    });
    
}

function getResponse(oReq) {
    //$('result').innerHTML = oReq.responseText;
    //alert(oReq.responseText)
    var response = oReq.responseText;
    if(response.length > 0){
        if(response == "100"){
            location.href="/project-planner/login.aspx";
            //alert("Please log in or create an account.")
        }else if(response == "200"){
            //alert("Your photo has been added.");
            
            ShadowboxResponse()
            
        }else if(response == "201"){
            //alert("Your product has been added.");
            //alert(response);     
            
             ShadowboxResponse()
                 
        }else if(response == "202"){
            //alert("Your product unit has been added.");
            //location.href = location.href + "#MyProducts";
            //location.href = location.href;
        }else if(response == "203"){
            //alert("Your note has been added.");
            //location.href = location.href;
        }else if(response == "300"){
            //alert("Your photo has been removed.");
            //location.href = location.href + "#MyPhotos";
            //location.href = location.href;
        }else if(response == "301"){
            //alert("Your product has been removed.");
            //location.href = location.href + "#MyProducts";
            //location.href = location.href;
        }else if(response == "302"){
            //alert("Your product unit has been removed.");
            //location.href = location.href + "#MyProducts";
            //location.href = location.href;
        }else if(response == "303"){
            //alert("Your note has been removed.");
            //location.href = location.href;
        }else if(response == "204"){
            alert("Your configuration has been updated.");
            //location.href = location.href;
        }else if(response == "304"){
            //alert("Your configuration has been removed.");
            //location.href = location.href;
        }else{
            openErrorWindow(response);
        }
    }
}

function getNoteResponse(oReq) {
    var response = oReq.responseText;
    if (response.length > 0) {
        addNoteRow(response);
    }
}
function addNoteRow(data) {
    var data = data.split("|");
    var now = new Date();
    var time = (now.getHours == 0) ? 12 : ((now.getHours() > 12) ? now.getHours() - 12 : now.getHours()) + ":" + now.getMinutes() + ":" + now.getSeconds() + " " + ((now.getHours() < 12) ? "AM" : "PM");
    var today = (now.getMonth() + 1) + "/" + now.getDate() + "/" + now.getFullYear();

    var table = document.getElementById("myNotesTable").firstChild;

/*
    var hr = document.createElement("<tr>");
    var col = document.createElement("<td colspan=\"2\">");
    col.innerHTML = "<hr color=\"#eeeeee\" size=\"1\" />";
    hr.appendChild(col);
    table.insertBefore(hr, table.firstChild);
*/
    var row = document.createElement("<tr>");
    var col1 = document.createElement("<td style=\"border-bottom:solid 1px #eeeeee;\" class=\"div_Content\" valign=\"top\" width=\"400\">");
    var col2 = document.createElement("<td style=\"border-bottom:solid 1px #eeeeee;\" class=\"div_Content\" valign=\"top\">");
    col1.innerHTML = data[1] + "<div class=\"f7\">(" + today + " " + time + ")</div>";
    col2.innerHTML = "<a onclick=\"this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode)\" href=\"javascript:deleteNote('"+ data[0] +"');\">remove</a>";
    row.appendChild(col1);
    row.appendChild(col2);
    table.insertBefore(row, table.firstChild);
}
function addNote(text) {
    if (!isEmpty(text)) {
        var url = "/project-planner/ajax-handle.aspx";
        var data = "ItemName=note&action=add&textvalue=" + escape(text.substr(0,255)) + "&dummy=" + Math.floor(Math.random()*5);
        var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getNoteResponse});
    }
}
function deleteNote(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=note&action=delete&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}
function saveProduct(product){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=product&action=add&Name=" + product + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}
function sendProduct(product){
    location.href="mailto:%20?subject="+document.title+"&body=" + location.href;
}
function printProduct(product){
    var virtualPath = location.href;
    virtualPath = virtualPath.replace("http://rba.netgaininteractive.com","");
    virtualPath = virtualPath.replace("http://www.renewalbyandersen.com","");
    virtualPath = virtualPath.replace("http://renewalbyandersen.com","");
    virtualPath = virtualPath.replace("default.aspx","");
    GetPage("/printProduct.aspx?product="+product+"&virtualPath="+virtualPath,800,400);
}
function deleteProduct(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=product&action=delete&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}

function savePhoto(photoPath,name){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=photo&action=add&ImageUrl=" + photoPath + "&Name=" + name + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}
function sendPhoto(product){
    var httpHost = (document.images['mainImage'].src.indexOf("netgaininteractive")>-1) ? "http://rba.netgaininteractive.com/":"http://www.renewalbyandersen.com/"
    location.href="mailto:%20?subject=Renewal%20by%20Andersen%20"+document.title+"&body=" + escape(httpHost + "printPhoto.aspx?imagePath="+document.images['mainImage'].src);
}
function printPhoto(product){
    GetPage("/printPhoto.aspx?product="+product+"&imagePath="+document.images['mainImage'].src,800,400);
}
function deletePhoto(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=photo&action=delete&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, { method: 'get', parameters: data, onComplete: getResponse });
}
function openVisualizer(){
    alert("openVisualizer();")
}
function sendProject(id){
    var httpHost = (location.href.indexOf("netgaininteractive")>-1) ? "http://rba.netgaininteractive.com/":"http://www.renewalbyandersen.com/"
    location.href="mailto:%20?subject=Renewal%20by%20Andersen%20"+document.title+"&body=" + escape(httpHost+"project-planner/getDetail.aspx?id="+id+"");
}
function addUnit(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=unit&action=add&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}
function deleteUnit(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=unit&action=delete&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}

function updateWindowConfig(id){
    var f = document.forms["frmMyConfigs"];
    var t = f.elements["title"+id].value;
    var w = f.elements["width"+id].value;
    var h = f.elements["height"+id].value;
    var u = f.elements["units"+id].value;
    var url = "/project-planner/ajax-handle.aspx";
    var data = "";
    data += "ItemName=config&";
    data += "action=update&";
    data += "id=" + id + "&";
    data += "title=" + t + "&";
    data += "width=" + w + "&";
    data += "height=" + h + "&";
    data += "units=" + u + "&";
    data += "dummy=" + Math.floor(Math.random()*5) + "";
    //data = escape(data;
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}
function deleteWindowConfig(id){
    var url = "/project-planner/ajax-handle.aspx";
    var data = "ItemName=config&action=delete&id=" + id + "&dummy=" + Math.floor(Math.random()*5);
    var request = new Ajax.Request(url, {method:'get',parameters: data,onComplete: getResponse});
}


function oneCheckboxChecked(group){
	var bool = false;
	for(i=0;i<group.length;i++){
		if(group[i].checked){
			bool = true;
			break;
		}
	}
	return bool;
}

//**********************************************************************************//
//START: form validation code
//-----------------------------------------------------------------------------------

// JScript Fil

function isValidZipcode(value) {
   var re = /^\d{5}([\-]\d{4})?$/;
   return (re.test(value));
}

function isValidCanadianZipcode(value) {
    var isValid = true;
     reg_exp_pcode = new RegExp(/(^s*([a-z](\s)?\d(\s)?){3}$)s*/i);

     if(!reg_exp_pcode.test(value)) {
         isValid = false;
     }
     return isValid;
}

function isEmpty(val){
 if (Trim(val)==""){return true;}else{return false;} 
}

function isNumeric(val){ 
 var boolVal = false;
 var Digits = "0123456789";
 for(j=0;j<val.length;j++){if (Digits.indexOf(val.substr(j,1))>-1){boolVal = true;}else{boolVal = false;break;}}
 return boolVal;
}

function isValidEmail(x){
    var isValid = true;
	//var x = document.forms[0].email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(x)){isValid = false;}
	
	return isValid;
}

function Trim(str){
 while (str.substring(0,1) == ' '){str = str.substring(1, str.length);}
 while (str.substring(str.length-1,str.length) == ' '){str = str.substring(0, str.length-1);}
 return str;
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false;
	}
return true;
}

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 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 ListItem(Text,Value){
 this.Text = Text;
 this.Value = Value;
}

var daysNumericList = new Array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");

var monthsList = new Array(
    new ListItem("January","01"),
    new ListItem("February","02"),
    new ListItem("March","03"),
    new ListItem("April","04"),
    new ListItem("May","05"),
    new ListItem("June","06"),
    new ListItem("July","07"),
    new ListItem("August","08"),
    new ListItem("September","09"),
    new ListItem("October","10"),
    new ListItem("November","11"),
    new ListItem("December","12")
);
var yearsList = new Array("2008","2009","2010");

var StatesList = new Array(
  new ListItem('Please Select...',''),
  new ListItem('Alabama','AL'),
  new ListItem('Alaska','AK'),
  new ListItem('Arizona','AZ'),
  new ListItem('Arkansas','AR'),
  new ListItem('California','CA'),
  new ListItem('Colorado','CO'),
  new ListItem('Connecticut','CT'),
  new ListItem('Delaware','DE'),
  new ListItem('Florida','FL'),
  new ListItem('Georgia','GA'),
  new ListItem('Hawaii','HI'),
  new ListItem('Idaho','ID'),
  new ListItem('Illinois','IL'),
  new ListItem('Indiana','IN'),
  new ListItem('Iowa','IA'),
  new ListItem('Kansas','KS'),
  new ListItem('Kentucky','KY'),
  new ListItem('Louisiana','LA'),
  new ListItem('Maine','ME'),
  new ListItem('Maryland','MD'),
  new ListItem('Massachusetts','MA'),
  new ListItem('Michigan','MI'),
  new ListItem('Minnesota','MN'),
  new ListItem('Mississippi','MS'),
  new ListItem('Missouri','MO'),
  new ListItem('Montana','MT'),
  new ListItem('Nebraska','NE'),
  new ListItem('Nevada','NV'),
  new ListItem('New Hampshire','NH'),
  new ListItem('New Jersey','NJ'),
  new ListItem('New Mexico','NM'),
  new ListItem('New York','NY'),
  new ListItem('North Carolina','NC'),
  new ListItem('North Dakota','ND'),
  new ListItem('Ohio','OH'),
  new ListItem('Oklahoma','OK'),
  new ListItem('Ontario','ON'),
  new ListItem('Oregon','OR'),
  new ListItem('Pennsylvania','PA'),
  new ListItem('Rhode Island','RI'),
  new ListItem('South Carolina','SC'),
  new ListItem('South Dakota','SD'),
  new ListItem('Tennessee','TN'),
  new ListItem('Texas','TX'),
  new ListItem('Utah','UT'),
  new ListItem('Vermont','VT'),
  new ListItem('Virginia','VA'),
  new ListItem('Washington','WA'),
  new ListItem('Washington D.C.','DC'),
  new ListItem('West Virginia','WV'),
  new ListItem('Wisconsin','WI'),
  new ListItem('Wyoming','WY')
);

function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.Register.nPassword.value;
var pw2 = document.Register.nPasswordVerify.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.Register.nPassword.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Please try again.');
return false;
}
// check for spaces
if (document.Register.nPassword.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
return true;
      }
   }
}

//-----------------------------------------------------------------------------------
//START: form validation code
//**********************************************************************************//
