﻿String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

String.prototype.replaceAll = function(findString, replaceString) {
  var _ret = this;
  while (_ret.indexOf(findString) >= 0)
    _ret = _ret.replace(findString, replaceString);
  return _ret;
}
/*
//http://www.west-wind.com/weblog/posts/472329.aspx
jQuery.fn.serializeNoViewState = function() {
  return this.find("input,textarea,select,hidden")
               .not("[type=hidden][name^=__]")
               .serialize();
}
*/

function navTo(Url)
{
  if(!window.location)
  {
    window.navigate(Url);
  }
  else
  {
  //alert(Url);
    window.location = Url;
  }
  //return(false);
}

var urlParams = {};
(function() {
  var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function(s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

  while (e = r.exec(q))
    urlParams[d(e[1])] = d(e[2]);
})();


function MoveTrace()
{
  var __asptrace = document.getElementById("__asptrace");
  if(__asptrace != null)
  {
    __asptrace.style.position = "absolute";
    __asptrace.style.top = "1500px";
   }
}

function load()
{
  var asptrace = document.getElementById("__asptrace");
  if(asptrace != null)
    asptrace.style.display = "none";
  size();
}

function fixFlash() 
{
  objects = document.getElementsByTagName("object");
  for (var i = 0; i < objects.length; i++)
  {
    objects[i].outerHTML = objects[i].outerHTML;
  }
}

function size()
{

  var windowWidth, windowHeight;
  if (self.innerHeight) // all except Explorer
  {
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }


  var TopBar = document.getElementById("htmlCssEditor");
  var TopBarHeight = 0;
  if(TopBar) TopBarHeight = TopBar.style.height.replace("px", "");
  
  var UserContent = document.getElementById("EntireContent");
  if(UserContent)
  {
    UserContent.style.top = TopBarHeight + 'px';
    UserContent.style.height = (windowHeight - (UserContent.offsetTop)) + 'px';
  }
  
}

function Window_OnLoad()
{
  //IterateNodes(window.document.body);
}
function IterateNodes(parentNode)
{
  if(parentNode)
  {
    if(parentNode.childNodes.length > 0)
    {
      for(var i = 0; i < parentNode.childNodes.length; i++)
      {
        if(parentNode.childNodes[i].cmsFeatures)
          ProcessNode(parentNode.childNodes[i]);

        IterateNodes(parentNode.childNodes[i]);
      }
    }
  }
}

function addEvent(currNode, methodName, method)
{
  if(currNode.addEventListener)
    currNode.addEventListener(methodName, method, false);
  else
    currNode.attachEvent(methodName, method); // Microsoft
}

function ProcessNode(currNode)
{
// Use the cmsFeatures Attribute to set functionality
  var cmsFeatures = new String(currNode.cmsFeatures);
  cmsFeatures = cmsFeatures.toLowerCase();

  if(cmsFeatures.indexOf("onblur",0))
    addEvent(currNode, "onblur", OnBlur);

  if(cmsFeatures.indexOf("onfocus",0))
    addEvent(currNode, "onfocus", OnFocus);

  if(cmsFeatures.indexOf("onclick",0))
    addEvent(currNode, "onclick", OnClick);
  
  if(cmsFeatures.indexOf("onmouseover",0))
    currNode.onmouseover = OnMouseOver;
  
  if(cmsFeatures.indexOf("onmouseout",0))
    currNode.onmouseout = OnMouseOut;

}
//window.onload = Window_OnLoad;
/*############################################################################################
  RadWindow Functions
*/
function GetRadWindow()
{
  var oWindow = null;
  if (window.radWindow) oWindow = window.radWindow;
  else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
  return oWindow;
}		

function OK_Clicked(result)
{
  var oWindow = GetRadWindow();			
  oWindow.Close(result);
}

function Cancel_Clicked(result)
{
  var oWindow = GetRadWindow();			
  oWindow.Close(result);
}



/*############################################################################################
  Layout functions
*/
function MatchHighest(ids)
{

  var tallestHeight = 0;
  var elems = new Array();
  for(var i = 0; i < ids.length; i++)
  {
    ids[i] = document.getElementById(ids[i]);
    if(ids[i])
    {
      if((ids[i].clip ? ids[i].clip.height : ids[i].offsetHeight) > tallestHeight) 
      {
			  tallestHeight = ids[i].clip ? ids[i].clip.height : ids[i].offsetHeight;
        ids[i].style.height = 'auto';
      }
    }
  }
  for(var i = 0; i < ids.length; i++)
  {
    if(ids[i])
      ids[i].style.height = tallestHeight + 'px';
  }
  
}

function get_weather(ZipCode) {
  $.get("/cms/handlers/web.ashx?url=" + "http://weather.yahooapis.com/forecastrss?p=" + ZipCode,
			function(xml) {
			  var weather = { title: '', code: '', image: '', temp: '', chill: '', humidity: '',
			    text: '', temperatureUnit: 'F', windUnit: 'mph', subrise: '', sunset: '',
			    city: '', region: '', country: '', location: '', date: ''
			  };

			  var item = $(xml).find('item')[0];
			  var itemList = item.children;
			  if (itemList == undefined)
			    itemList = item.childNodes;

			  $(itemList).each(function() {
			    var tagName = $(this)[0].tagName;

			    switch (tagName) {
			      case 'title':
			        weather.title = $(this)[0].textContent;
			        break;
			      case 'link':
			        weather.link = $(this)[0].textContent;
			        break;
			      case 'yweather:condition':
			        weather.code = $(this).attr("code");
			        weather.image = "http://l.yimg.com/a/i/us/we/52/" + weather.code + ".gif";
			        weather.temp = $(this).attr("temp");
			        weather.text = $(this).attr("text");
			        weather.date = $(this).attr("date");
			        break;
			    }
			  });

			  var channel = $(xml).find('channel')[0];
			  
        var channelList = channel.children;
        if(channelList == undefined)
          channelList = channel.childNodes;
        
			  weather.humidity = $(channel).attr("humidity");
			  $(channelList).each(function() {
			    var tagName = $(this)[0].tagName;

			    switch (tagName) {
			      case 'yweather:location':
			        weather.city = $(this).attr("city");
			        weather.region = $(this).attr("region");
			        weather.country = $(this).attr("country");
			        weather.location = weather.city + ', ' + weather.region + ' ' + weather.country;
			        break;
			      case 'yweather:units':
			        weather.temperatureUnit = $(this).attr("temperature");
			        weather.windUnit = $(this).attr("speed");
			        break;
			      case 'yweather:wind':
			        weather.chill = $(this).attr("chill");
			        break;
			      case 'yweather:atmosphere':
			        weather.humidity = $(this).attr("humidity");
			        break;
			      case 'yweather:astronomy':
			        weather.sunrise = $(this).attr("sunrise");
			        weather.sunset = $(this).attr("sunset");
			        break;

			    }
			  });
			  //debugger;


			  //			var image = $(xml).find('image')[0];
			  //			var title = $(item).find('title')[0].textContent;
			  //			var desc = $(item).find('description')[0].textContent;
			  //			var imageUrl = $(item).find('yweather:condition')[0].attr("code");
			  $("#weatherImage").attr("src", weather.image);
			  $("#weatherText").html(weather.text);
			  $("#weatherTemp").html(weather.temp + '&deg; F');
			  $("#weatherHumidity").html(weather.humidity + ' %');
			  $("#weatherChill").html(weather.chill + '&deg; F');
			  $("#weatherLink").attr("href", weather.link);
			  $("#weatherLocation").html(weather.location);
			  $("#weatherDate").html(weather.date);
			  $("#weather").show();
			  //alert(new String(data).substring(0, 100));
			});
}
/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

function validateEmail(EmailToTest) {
  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
  return emailPattern.test(EmailToTest);

}

function SubmitUserForm(FormClass) {

  // Validate the form and return true / false;
  var _valid = true;
  var _message = "";

  jQuery(".required." + FormClass).each(function(index, element) {

    var _field = jQuery(element);
    debugger;
    if (_field.val() == null || _field.val().length == 0) {
      _field.css({ "borderColor": "red" });
      _valid = false;
    }
    else if (_field.attr("id").toLowerCase() == "email" && !validateEmail(_field.val())) {
      _field.css({ "borderColor": "red" });
      _valid = false;
    }
    else {
      _field.css({ "borderColor": "" });
    }

  });

  if(!_valid)
    alert("Please correct the highlighted fields");

  return _valid;
}
