﻿

function ToggleTabs(div,hiddenctrl,tabcount,selected,hiddenT)
{
     
     if ( tabcount > 1)
     {
        
        document.getElementById(div+"1").style.display = "none";
        document.getElementById(div+"1li").className = "link1";
        if ( tabcount >= 2 )
        {
        
            document.getElementById(div+"2").style.display = "none";
            document.getElementById(div+"2li").className = "link2";
         
        }
        if ( tabcount >= 3)
        {
         
            document.getElementById(div+"3").style.display = "none";
            document.getElementById(div+"3li").className = "link3";
            
        }
        
        document.getElementById(selected).style.display = "block";
        document.getElementById(selected+"li").className = "linkSelected";
        
        document.getElementById(hiddenctrl).value = hiddenT;
        
    }
}

function ToggleStaticTabs(div1,div2,hiddenctrl,hiddenT)
{
    
    document.getElementById(div1).style.display = "block";
    document.getElementById(div1+"li").className = "linkSelected";
    
    document.getElementById(div2+"").style.display = "none";
    document.getElementById(div2+"li").className = "link1";
    
    document.getElementById(hiddenctrl).value = hiddenT;
    

}

function PopulateTipText(selectId, textId, input1, input2, input3, input4, input5)
{
     var theselection = document.getElementById(selectId).value
     if ( theselection == 'home')
     {
        document.getElementById(textId).value = document.getElementById(input1).value;
        
    }
    else if ( theselection == 'aboutus')
     {
        document.getElementById(textId).value = document.getElementById(input2).value;
        
    }
    else if ( theselection == 'research')
     {
        document.getElementById(textId).value = document.getElementById(input3).value;
        
    }
    else if ( theselection == 'workforce')
     {
        document.getElementById(textId).value = document.getElementById(input4).value;
        
    }
    else if ( theselection == 'knowledge')
     {
        document.getElementById(textId).value = document.getElementById(input5).value;
        
    }
    else
    {
        document.getElementById(textId).value ="";
    }
}

function Divdisplay(divid, divid2,img1, img2)
{
    
    if(divid != '')
    {
        document.getElementById(divid).style.display = "inline";
    }
    else
    {
        document.getElementById(divid2).style.display = "none";
     }
    
     document.getElementById(img1).style.display = 'none';
     document.getElementById(img2).style.display = 'inline';
     
     return false;
}

function modNav(topid, subid, divid)
{
//alert(topid);
    var top = topid 
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
   
    
    if(subid != '')
    {
        document.getElementById(subid).className = "selected";
    }
    if(divid != '')
    {
        document.getElementById(divid).style.display = "inline";
    }
    if(top != '')
    {
        document.getElementById(top).className = "on";
    }
}

function toggleBanner()
{
    var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if (sPage=="default.aspx" || sPage=="")
{
    document.getElementById("hbannerdiv").className= "homebanner";
   
}
else
{

    document.getElementById("hbannerdiv").className= "internalbanner";
  
}

}
   
function NukeSafeGuard()
{
    var ret = confirm('Are you sure you want to Nuke this section (whole control, all its tabs and all its previously saved states.)?');
    
    if(ret==true)
    {
        return confirm('Are you really sure? there is no going back.\nThis section would be taken off the draft and live sites for good.\nAll previously saved states of this control would also be deleted.');
    }
    else
    {
        return ret; 
    }
}
function TabNukeSafeGuard()
{
    var ret = confirm('Are you sure you want to Nuke this tab and all its sub controls?');
    
    if(ret==true)
    {
        return confirm('Are you really sure? there is no going back.\nThis tab would be taken off the draft and live sites for good');
    }
    else
    {
        return ret; 
    }
}
function InTabNukeSafeGuard()
{
    var ret = confirm('Are you sure you want to Nuke this in-tab section (section directly below action image clicked)?');
    
    if(ret==true)
    {
        return confirm('Are you really sure? there is no going back.\nThis in-tab section would be taken off the draft and live sites for good');
    }
    else
    {
        return ret; 
    }
}

function PopupPicker(ctl,w,h)
    {
        var PopupWindow=null;
        settings="width="+ w + ",height="+ h + ",location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no";
        PopupWindow=window.open("datepicker.aspx?Ctl=" + ctl,"DatePicker",settings);
        PopupWindow.focus();
    }
    
function opentestgroup(open)
{
    if (open)
    {
        document.getElementById("testgroupdiv").style.display = "inline";
        document.getElementById("notestgroupdiv").style.display = "none";
    }
    else
    {
        document.getElementById("notestgroupdiv").style.display = "block";
        document.getElementById("testgroupdiv").style.display = "none";
     }
}

function RedirectToSearch(location, ctrl1, ctrl2 ,ctrl3)
{
alert(location);
var link = location+"?q="+ctrl1.value+"&cx="+ctrl2.value+"&cof="+ctrl3.value;
alert(link);
    window.location="http://www.google.com";
}

function displayHTML(printContent)
{
    var title = "<title>National Academy for Parenting Practitioners - Print Preview</title>";
    var stylesheet = title + "<link media=\"screen\" rel=\"stylesheet\" type=\"text/css\" href=\"styles/default/global_print.css\" /><link media=\"print\" rel=\"stylesheet\" type=\"text/css\" href=\"styles/default/global_print_final.css\" /><br />" ;
    var print_icon = "<a href=\"javascript:void(0);\" onclick=\"window.print();\"><img title=\"Print this page\" id=\"imgDetail\" alt=\"Print this page\" src=\"styles/default/images/icons/print_icon.gif\" width=\"134\" height=\"34\" border=\"1\" /></a>";
  //var logo = "<div id=\"print_logo\" style=\"background: url(styles/default/images/logo/NAPP_logo.gif) no-repeat top right; width:100%;height:105px; display:block;\">" + print_icon + "</div><br /><br />";
    var NAPP_logo = "<span id=\"NAPP_logo\" style=\"width:177px;height:105px;position:relative;margin-top:0px; float: right;\"><img src=\"styles/default/images/logo/NAPP_logo.gif\" width=\"177\" height=\"103\" alt=\"\" /></span>";
    var logo = "<div id=\"print_logo\" style=\"width:100%;height:105px;border:0px solid red;display:inline; \">" + print_icon + NAPP_logo + "</div><br /><br /><br /><br /><br /><br /><br /><br />";


    var inf = stylesheet + logo + printContent;
    win = window.open("print.htm",'Print','toolbar=yes,status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,height=700,width=700');
    win.document.write(inf);
    win.document.close();
}

function printWindow()
{
   bV = parseInt(navigator.appVersion)

   if (bV >= 4)
   {
    window.print();
    }
}

function popUp(url, content)
{
      var link = url; //Full url of the page that is being emailed
      var body = stripHTML(content); //The contents of the page

      win = window.open("send_to_friend_test.htm",'Email','toolbar=no,status=no,resizable=no,scrollbars=no,location=no,menubar=no,height=570,width=520');

      win.document.write(CreateEmailPage(url, body));
      win.document.close();
}

/*
function stripHTML()
{
    var re = /(<([^>]+)>)/gi;
    for (i=0; i<arguments.length; i++)
    {
       arguments[i].value = arguments[i].value.replace(re, "") ;
    }
}
*/

function stripHTML(oldString)
{
   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++)
   {
        if(oldString.charAt(i) == '<')
        {
          inTag = true;
        }

        if(oldString.charAt(i) == '>')
        {
           if(oldString.charAt(i+1)=="<")
           {
             //DO NOTHING
           }
           else
           {
              inTag = false;
        	  i++;
           }
        }

        if(!inTag)
        {
           newString += oldString.charAt(i);
        }
   }

   return newString;
}



function CreateEmailPage(url, content)
{
      var testText = "This is some test content to be sure that it's posting correctly";

      var sb = new StringBuilder();
      sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
      sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
      sb.append("<head>");
      sb.append("<title>E-mail a friend</title>");
      sb.append("<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"styles/default/global_print.css\" />");
      sb.append("<link media=\"all\" rel=\"stylesheet\" type=\"text/css\" href=\"styles/default/email_to_friend.css\" />");

      sb.append("<script type=\"text/javascript\"> ");
      sb.append("function checkEmail(){");

      sb.append("var yourEmail  = document.getElementById(\"txtYourEmail\");");
      sb.append("var theirEmail = document.getElementById(\"txtEmail\");");

      sb.append("var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; ");

      sb.append("if (!filter.test(yourEmail.value)){ ");
      sb.append("alert('Please provide a valid e-mail address'); yourEmail.focus(); return false; }");

      sb.append("if (!filter.test(theirEmail.value)){ ");
      sb.append("alert('Please provide a valid e-mail address for recipient'); theirEmail.focus(); return false; }");

      sb.append("}");

      sb.append("function valChkBox(){ ");
      sb.append(" var box = document.getElementById('accept_terms');");
      sb.append("if(!box.checked){");
      sb.append("alert(\"Please check box to confirm that you wish to send mail!!!\");");
      sb.append(" box.focus();return false;}");
      sb.append("}");

      sb.append("function IsEmpty(){");
      sb.append("var name = document.getElementById(\"txtName\"); ");
      sb.append(" if ((name.value.length == 0) ||(name.value == null)){");
      sb.append("alert(\"Please enter your name\");name.focus(); return false;}");
      sb.append("return checkEmail();}");

      sb.append("</script>");

      sb.append("</head><body><div id=\"send_to_friend\">");

      sb.append("<form action=\"FormMail.aspx\" method=\"post\" id=\"frm_mailing_list\" onsubmit=\"return IsEmpty();\">");
      sb.append("<table id=\"tblSendToFriend\" cellspacing=\"5\">");
      sb.append("<tbody><tr><td>&nbsp;</td><td align=\"right\"><img src=\"styles/default/images/logo/NAPP_logo.gif\" width=\"177\" height=\"103\" alt=\"NAPP logo\" alt=\"National Academy for Parenting Practitioners\" title=\"National Academy for Parenting Practitioners\" /></td></tr>");
      sb.append("<tr><td colspan=\"2\" class=\"spacer\">&nbsp;</td></tr>");
      sb.append("<tr><td colspan=\"2\" class=\"title\"><hr />E-mail a friend<hr /></td></tr>");
      sb.append("<tr><td colspan=\"2\" class=\"spacer\"><!-- URL: --></td></tr>");
      sb.append("<tr><td class=\"label\">Your name:</td><td><input type=\"text\" name=\"txtName\" id=\"txtName\" /></td></tr>");
      sb.append("<tr><td class=\"label\">Your e-mail address:</td><td><input type=\"text\" name=\"txtYourEmail\" id=\"txtYourEmail\" /></td></tr>");
      sb.append("<tr><td class=\"label\">Recipient's e-mail address:</td><td><input type=\"text\" name=\"txtEmail\" id=\"txtEmail\" /></td></tr>");

      sb.append("<tr><td class=\"label\">Add a note (optional):</td><td><textarea name=\"txtAddNote\" id=\"txAddNote\" cols=\"17\" rows=\"7\" wrap=\"hard\"></textarea></td></tr>");
 sb.append("<tr><td>&nbsp;</td><td class=\"disclaimer\"><hr />*The details you provide on this page will not be used to send unsolicited e-mail, and will not be sold to a 3<sup>rd</sup> party<hr /></td></tr>");
      sb.append("<tr class=\"hidden\"><td class=\"label\">please check:</td><td style=\"text-align:left\"><input class=\"chkBox\" type=\"checkbox\" name=\"accept_terms\" id=\"accept_terms\" value=\"accept_terms\" />");
      sb.append("<input class=\"hidden\" style=\"display:none;\" type=\"hidden\" id=\"hdnContent\" name=\"hdnContent\" value=\"" + content + "\" />");
      sb.append("<input class=\"hidden\" style=\"display:none;\" type=\"hidden\" id=\"hdnURL\" name=\"hdnURL\" value=\"" + url + "\" />");
      sb.append("</td></tr>");
      sb.append("<tr><td>&nbsp;</td><td align=\"left\"><input class=\"submit\" type=\"submit\" name=\"Submit\" value=\"Send\"  /></td></tr>");
sb.append("<tr><td colspan=\"2\" class=\"title\">&nbsp;</td></tr>");
      sb.append("</tbody></table></form></div></body></html>");

      // Get the final page
      var Page = sb.toString();
      return Page;

}

// EMAIL VALIDATION - REG X
 function regX_Email(obj_email)
{
	// validate an e-mail address
	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(obj_email))
	{
	  return false;
	}

	 return true;
}

function checkEmail(id)
{
    var email = document.getElementById(id);
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var altFilter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

    if (!filter.test(email.value))
    {
      alert('Please provide a valid email address');
      email.focus();

      return false;
    }
    else
    {
       return true;
    }

}

function valChkBox()
    {
        var box = document.getElementById('accept_terms');
        if(!box.checked)
         {
              alert("Please check box to confirm that you wish to send mail!!!");
              box.focus();
              return false
          }
    }




// Initializes a new instance of the StringBuilder class and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}

function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
/*function _fontResize(){
	var _element = document.body;
	_default = 64;
	_curent = _default;
	_max = 76;
	_min = 52;
	_element.style.fontSize = _default + '%';
	var _step = 4;
	var _aaa = document.getElementById('aaa');
	var _btn = _aaa.getElementsByTagName('a');
	for (var j = 0; j < _btn.length; j++)
	{
		_btn[j].onclick = function()
		{
			if(this.className == 'zoom-in')
			{
				_curent += _step;
				if(_curent > _max)
				_curent = _max;
				_element.style.fontSize = _curent + '%';
			}
			else if(this.className == 'zoom-out')
			{
				_curent -= _step;
				if(_curent < _min)
				_curent = _min;
				_element.style.fontSize = _curent + '%';
			}
			else 
			{
				_element.style.fontSize = _default + '%';
				_curent = _default;
			}
		}
	}
}*/
function initAccordion(){
	$('ul#accordion').accordion({ 
		autoheight: false,
		header: ".opener",
		active: '.selected',
		selectedClass: 'active',
		alwaysOpen: false,
		event: "mouseover"
	});
}
if (window.addEventListener){
	window.addEventListener("load", initTabs, false);
	//window.addEventListener("load", _fontResize, false);
	window.addEventListener("load", initAccordion, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initTabs);
	//window.attachEvent("onload", _fontResize);
	window.attachEvent("onload", initAccordion);
}