
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();}
}

function editPage(id){
    GetPage("/editPageContent.aspx?id="+id,900,500);
}

function printPage(){
    var virtualPath = location.href;
    virtualPath = virtualPath.replace("http://awswebdev", "");
    virtualPath = virtualPath.replace("http://aws.netgaininteractive.com","");
    virtualPath = virtualPath.replace("http://www.anchorwall.com","");
    virtualPath = virtualPath.replace("http://anchorwall.com","");
    virtualPath = virtualPath.replace("http://dev.anchorwall.com","");
    virtualPath = virtualPath.replace("http://216.17.93.67","");
    virtualPath = virtualPath.replace("default.aspx","");
    var title = document.title;
    title = title.replace("°"," degree");
    GetPage("/printPage.aspx?virtualPath="+virtualPath+"&title="+escape(title),800,400)
}
function printProductDetail(id){
    GetPage("/printPage_ProductDetail.aspx?ProdID=" + id,800,400);
}

//**********************************************************************************//
//START: form validation code
//-----------------------------------------------------------------------------------

// JScript Fil
function isEmpty(val){
 if (Trim(val)==""){return true;}else{return false;} 
}


function isValidZipcode(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          //alert("Zip Code Is Not Valid");
          return false;
     }

return true;
}

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 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('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')
);

var StatesAndProvincesList = new Array(
  new ListItem('Please Select...',''),
  new ListItem('Alabama','AL'),
  new ListItem('Alaska','AK'),
  new ListItem('Alberta','AB'),
  new ListItem('Arizona','AZ'),
  new ListItem('Arkansas','AR'),
  new ListItem('British Columbia','BC'),
  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('Manitoba','MB'),
  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('Newfoundland and Labrador','NL'),
  new ListItem('New Brunswick','NB'),
  new ListItem('New Hampshire','NH'),
  new ListItem('New Jersey','NJ'),
  new ListItem('New Mexico','NM'),
  new ListItem('New York','NY'),
  new ListItem('Northwest Territories','NT'),
  new ListItem('North Carolina','NC'),
  new ListItem('North Dakota','ND'),
  new ListItem('Nova Scotia','NS'),
  new ListItem('Nunavut','NU'),
  new ListItem('Ohio','OH'),
  new ListItem('Oklahoma','OK'),
  new ListItem('Ontario','ON'),
  new ListItem('Oregon','OR'),
  new ListItem('Pennsylvania','PA'),
  new ListItem('Prince Edward Island','PE'),
  new ListItem('Quebec','QB'),
  new ListItem('Rhode Island','RI'),
  new ListItem('Saskatchewan','SK'),
  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'),
  new ListItem('Yukon','YK')
);

function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.myAccountRegisterForm.Password.value;
var pw2 = document.myAccountRegisterForm.PasswordVerify.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.myAccountRegisterForm.Password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Please try again.');
return false;
}
// check for spaces
if (document.myAccountRegisterForm.Password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same password twice. Please re-enter your password.");
return false;
}
else {
return true;
      }
   }
}

function ResponseNotLoggedIn()
{
     Shadowbox.open({
        title:      'Anchor Wall Systems',
        type:       'html',
        content:    '<table style=\"background-color: #f5f5f5; font-family: Trebuchet MS;\" height=\"150\" width=\"100%\"><tr><td valign=\"top\"><img src=\"/cmsvirtualUserfiles/images/header_ItemSaved.jpg\"></td></tr><tr><td align=\"center\" valign=\"top\"><strong>You must be logged in to save an item to your project. <a href=\"/MyProject/View.aspx\">Click here </a>to log in or <a href=\"javascript:Shadowbox.close();\">click here</a> to keep browsing.</td></tr></table>',
        height:     170,
        width:      208
    });
}

function closeShadowBox()
{
Shadowbox.close();
}
function printIt() {
    window.print();
}
function printGlossary() {
    window.open("/GlossaryReport.aspx");
}

// Pass an array of elements the add a class to self or parent while focused
var formRowHighlight = function(arrEls, iWalkUp, sClass) {
    jQuery(arrEls).each(function() {
        var hlEl = this;
        for (i = 0; i < parseInt(iWalkUp,10); i++) {
            hlEl = hlEl.parentNode;
        }
        this.onfocus = function() {
            jQuery(hlEl).addClass(sClass);
        };
        this.onblur = function() {
            jQuery(hlEl).removeClass(sClass);
        };
    });
};