﻿// JScript File
//Global variables for toolbar and inline editing
var editable = true;
var autohide = true;
var varPopMenu = false;
var objDoc;
var oureditor;

window.onload = function()
{
    setTimeout('alterToolBar()',100);
}
/** Browser Detection Code **/
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring,ie6=false;
if (navigator.appVersion.substr(22,2)=="6.") { ie6 = true; }
if (checkIt('safari')) browser = "safari";
else if (checkIt('msie')) browser = "ie";
else if (!checkIt('compatible'))
{
    browser = "mozilla";
}
function checkIt(string)
{
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
}
/** Browser Detection Code **/


//function to hide and un-hide the toolbar
function alterToolBar()
{
    if(autohide == true)
    {
        autohide = false;
        //document.getElementById('bar').style.top = (objDoc.scrollTop - 27) + 'px';
        if(document.getElementById("expandArrow") != null)
        {
            document.getElementById('bar').style.top = '-27px';
            document.getElementById("expandArrow").src = txtWebsiteRootPath + "images/toolbar-expand.gif";
            document.getElementById("expandArrow").title = "Click to expand toolbar";
            document.getElementById("expandArrow").alt = "Click to expand toolbar"; 
            if(ie6)
            {
                cover(44, 13, document.getElementById("autohide"));
            }
        }
    }
    else
    {
        autohide = true;
        //document.getElementById('bar').style.top = objDoc.scrollTop + 'px';
        if(document.getElementById("expandArrow") != null)
        {
            document.getElementById('bar').style.top = '0px';
            document.getElementById("expandArrow").src = txtWebsiteRootPath + "images/toolbar-collapse.gif";
            document.getElementById("expandArrow").title = "Click to collapse toolbar";
            document.getElementById("expandArrow").alt = "Click to collapse toolbar";
            if(ie6)
            {
                cover(1001, 27, document.getElementById('bar'));
                cover(44, 13,  document.getElementById('autohide'));
            }
        }
    }
}

function cover(width, height, coverObject)
{
     var ieMat = null; //for IE6 iframe shim
    // Cover <select> elements with <iframe> elements only in IE < 7
    if (navigator.appVersion.substr(22,2)=="6.")
    {
        if(ieMat==null)
        {
            ieMat=document.createElement('iframe');
            if(document.location.protocol == "https:")
                ieMat.src="//0";
            else if(window.opera != "undefined")
                ieMat.src="";
            else
                ieMat.src="javascript:false";
            ieMat.scrolling="no";
            ieMat.frameBorder="0";
            ieMat.style.position="absolute";
            ieMat.style.top= coverObject.offsetTop + "px";
            ieMat.style.left= coverObject.offsetLeft + "px";
            ieMat.style.width= width + "px";
            ieMat.style.height= height + "px";
            ieMat.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
            ieMat.style.zIndex="-1";
            document.getElementById('bar').insertBefore(ieMat,document.getElementById('toolbarContainer'));
        }
    }
}

//function to scroll the toolbar when the user scrolls through the page
function scrollAdjust()
{
    if(autohide)
    {
        document.getElementById('bar').style.top = (objDoc.scrollTop) + 'px';
    }
    else
    {
        document.getElementById('bar').style.top = (objDoc.scrollTop-27) + 'px';
    }
}
        
function HideInfo()
{
 document.getElementById("dhtmltooltip").style.visibility = "hidden";   
}

function ExtraInformationPosition(e)
{
    
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;
var menuobj=document.getElementById("dhtmltooltip");
//Find out how close the mouse is to the corner of the window
var rightedge = ie5? (document.documentElement.clientWidth-e.clientX) : (window.innerWidth-e.clientX);
var bottomedge = ie5? (document.documentElement.clientHeight-e.clientY) : (window.innerHeight-e.clientY);

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.offsetWidth)
{
//move the horizontal position of the menu to the left by it's width
xLeft=ie5? document.documentElement.scrollLeft+e.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth;
}
else
{
//position the horizontal position of the menu where the mouse was clicked
xLeft=ie5? document.documentElement.scrollLeft+e.clientX : window.pageXOffset+e.clientX;
}
//if the vertical distance isn't enough to accomodate the height of the context menu
if (bottomedge<menuobj.offsetHeight)
{
//move the vertical position of the menu up by it's height
yTop=ie5? document.documentElement.scrollTop+e.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight;
}
else
{
if(browser == "safari")
{
//position the vertical position of the menu where the mouse was clicked
yTop=ie5? document.documentElement.scrollTop+e.clientY : e.clientY;
}
else
{
//position the vertical position of the menu where the mouse was clicked
yTop=ie5? document.documentElement.scrollTop+e.clientY : window.pageYOffset+e.clientY;
}
}

menuobj.style.visibility = "visible";
menuobj.style.top = yTop + 'px';
menuobj.style.left = xLeft + 'px';
return false;
}


function HideInfo()
{
 document.getElementById("dhtmltooltip").style.visibility = "hidden";   
}

function ExtraInformationPosition(e)
{
    
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;
var menuobj=document.getElementById("dhtmltooltip");
//Find out how close the mouse is to the corner of the window
var rightedge = ie5? (document.documentElement.clientWidth-e.clientX) : (window.innerWidth-e.clientX);
var bottomedge = ie5? (document.documentElement.clientHeight-e.clientY) : (window.innerHeight-e.clientY);

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.offsetWidth)
{
//move the horizontal position of the menu to the left by it's width
xLeft=ie5? document.documentElement.scrollLeft+e.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth;
}
else
{
//position the horizontal position of the menu where the mouse was clicked
xLeft=ie5? document.documentElement.scrollLeft+e.clientX : window.pageXOffset+e.clientX;
}
//if the vertical distance isn't enough to accomodate the height of the context menu
if (bottomedge<menuobj.offsetHeight)
{
//move the vertical position of the menu up by it's height
yTop=ie5? document.documentElement.scrollTop+e.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight;
}
else
{
if(browser == "safari")
{
//position the vertical position of the menu where the mouse was clicked
yTop=ie5? document.documentElement.scrollTop+e.clientY : e.clientY;
}
else
{
//position the vertical position of the menu where the mouse was clicked
yTop=ie5? document.documentElement.scrollTop+e.clientY : window.pageYOffset+e.clientY;
}
}

menuobj.style.visibility = "visible";
menuobj.style.top = yTop + 'px';
menuobj.style.left = xLeft + 'px';
return false;
}

//Method to change the button bg on mouse over and mouse out
function changeButton(objButton)
{
    var buttonClass = objButton.className;
    var oldButtonClass = "";
    var newButtonClass = "";
    var buttonClassNum = "";
    if(buttonClass.indexOf("Hover") > -1)
    {
        buttonClassNum = buttonClass.substring(6,7);
        newButtonClass = "button" + buttonClassNum;
        oldButtonClass = "button" + buttonClassNum + "Hover";
        objButton.className = buttonClass.replace(oldButtonClass, newButtonClass);
    }
    else
    {
        buttonClassNum = buttonClass.substring(6,7);
        oldButtonClass = "button" + buttonClassNum;
        newButtonClass = "button" + buttonClassNum + "Hover";
        objButton.className = buttonClass.replace(oldButtonClass, newButtonClass);
    }
}

//Method to change the primary button bg on mouse over and mouse out
function changePrimaryButton(objButton)
{
    var buttonClass = objButton.className;
    var oldButtonClass = "";
    var newButtonClass = "";
    var buttonClassNum = "";
    if(buttonClass.indexOf("Hover") > -1)
    {
        buttonClassNum = buttonClass.substring(13,14);
        newButtonClass = "primarybutton" + buttonClassNum;
        oldButtonClass = "primarybutton" + buttonClassNum + "Hover";
        objButton.className = buttonClass.replace(oldButtonClass, newButtonClass);
    }
    else
    {
        buttonClassNum = buttonClass.substring(13,14);
        oldButtonClass = "primarybutton" + buttonClassNum;
        newButtonClass = "primarybutton" + buttonClassNum + "Hover";
        objButton.className = buttonClass.replace(oldButtonClass, newButtonClass);
    }
}
function hideEmptyContainer()
{	
    if(!document.getElementById("autohide") || !document.getElementById("jsInclude"))
    {
          
           var y;
           var child=document.getElementById("outer"); 
           var contentDivString=document.getElementById("contentDivString");
            contentDivs = contentDivString.value.split(",");
           
            if (contentDivs.length>=0)
            {
              for(var i=0; i<(contentDivs.length); i++)   
              {   
              
               var ele = document.getElementById(contentDivs[i]);
               
               if(ele!="" || ele!=null)
               {
					
                   for (var j=0; j<ele.childNodes.length; j++)
                    {
						
                        if (ele.childNodes[j].nodeName == "DIV")
                        {
                           if(ele.childNodes[j].getAttribute("FwObjectId")=='00000000-0000-0000-0000-000000000000')
                            {
                                 ele.style.display="none";                                                                                                  
                            }  
                        }
                    }
                 }
             } 
            }   
     } 
 }
 
 function hideEmptySideBarContainer()
{    
    if(!document.getElementById("autohide") || !document.getElementById("jsInclude"))
    {
           var y;
           var child=document.getElementById("outer"); 
           var contentDivString=document.getElementById("sidebarDivString");
            
            contentDivs = contentDivString.value.split(",");
            
            if (contentDivs.length>=0)
            {
                  for(var i=0; i<(contentDivs.length); i++)   
              {   
              
               var ele = document.getElementById(contentDivs[i]);
                 if(ele!="" || ele!=null)
                {
               
                   for (var j=0; j<ele.childNodes.length; j++)
                    {
                        if (ele.childNodes[j].nodeName == "DIV")
                        {
                           if(ele.childNodes[j].getAttribute("FwObjectId")=='00000000-0000-0000-0000-000000000000')
                            {
                                 ele.style.display="none"
                            }  
                        }
                    }
                 }
             } 
            }   
     } 
 }

/*************************** Script for form Validation****************/

function checkNames(array)
{
  for(var i=0; i<array.length; i++)
  {
   
                if (array[i].type == "text" || array[i].type == "textarea")
				{
					if (array[i].value == "" && array[i].attributes["required"].value=="true")
					{
						alert("Please enter " + array[i].attributes["displayname"].value+ ".");
						array[i].select();
						return false;
					} 
					else if((array[i].attributes["displayname"].value != "PhoneNo") && (array[i].value != "") &&(!CheckName(array[i])))
					{
					    alert("Invalid " + array[i].attributes["displayname"].value+ "! Please re-enter.");
					  array[i].select();
						return false;
					}
					
					else if ((array[i].attributes["displayname"].value == "Zip")&& (array[i].value != "") && (!CheckZip(array[i]))) 
					{
					    alert("Invalid Zip Code! Please re-enter.");
						array[i].select();
						return false;					
					}
					else if ((array[i].attributes["displayname"].value == "Email Address") && (!CheckEmail(array[i]))) 
					{
					    alert("Invalid Email Address! Please re-enter.");
						array[i].select();
						return false;
					}
					else if ((array[i].attributes["displayname"].value == "PhoneNo") && (array[i].value!="") && (!CheckMobileNo(array[i])))
					{
					         alert("Invalid "+ array[i].attributes["displayname"].value+"! Please re-enter.");
						     array[i].select();
						     return false;
					}
					else if ((array[i].attributes["displayname"].value == "Credit Card Number") && (!CheckCreditCardNo(array[i]))) 
					{
					    
					    alert("Invalid Credit Card Number! Please re-enter.");
						array[i].select();
						return false;     
					}
					else if ((array[i].attributes["displayname"].value == "Numeric Values")&& (!IsNumeric(array[i]))) 
					{
					    
					    alert("Invalid "+ array[i].attributes["displayname"].value+"! Please re-enter.");
						array[i].select();
						return false;
					}
					else if ((array[i].attributes["displayname"].value == "Numeric Values")&& (array[i].value == "00")) 
					{
					    
					    alert("Attendees number should be greater than zero.");
						array[i].select();
						return false;
					}
					
				}
				//check for select-one or select-multiple field
				else if ((array[i].type == "select-one") || (array[i].type == "select-multiple"))
				{
					if ((array[i].options[array[i].selectedIndex].value == "0" ||array[i].options[array[i].selectedIndex].value =="--Select--")&& array[i].attributes["required"].value=="true")
					{
						alert("Please select " + array[i].attributes["displayname"].value+ ".");
						//array[i].focus();
						return false;
					}
					else if(((array[i].attributes["displayname"].value == "Exp.Month")||(array[i].attributes["displayname"].value == "Exp.Year")) && (!expYearMonth())) 
					{
					     alert("Invalid "+array[i].attributes["displayname"].value+"! Please re-select.");
					     return false;
					}
				}
				else if(array[i].type == "password")
				{
					if (array[i].value == "" && array[i].attributes["required"].value=="true")
					{
						alert("Please enter " + array[i].attributes["displayname"].value+ " Number.");
						array[i].focus();
						return false;
					} 
					else if ((array[i].attributes["displayname"].value == "CVV/CVC")&& (!IsNumeric(array[i]))) 
					{
					    
					    alert("Invalid "+ array[i].attributes["displayname"].value+" Number! Please re-enter.");
						array[i].focus();
						return false;
					}
					else if((array[i].attributes["displayname"].value == "CVV/CVC")&& (IsNumeric(array[i])))
					{
					    var errorflag=CVVSetLength();
					    array[i].focus();
					    return errorflag;
					}
				}
       
   }
   return true;
}
function CheckEmail(val)
 {
     if(val.value.match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/))
     {
            return true;
     }
        
 }
 function CheckCreditCardNo(val)
 {
    if(val.value.match(/^\d{16}$/) && (!(val.value=='0000000000000000')))
    {
        return true;
    }
 }
     
 function CheckName(val)
 {
    //if(val.value.match(/^\w{1,100}$/))
    if(val.value.match(/^([\w_\-~@#$%^'&*()+=;:{\[\]}?|\\,.?/\s]){1,100}$/))
    {
        return true;
    }
 }
 function CheckAddress(val)
 {
    //if(val.value.match(/^\w{1,100}$/))
    if(val.value.match(/^([\w_\-~@#$%^'\&*()+=;:{\[\]}?|\\,.?/\s]){1,100}$/))
    {
        return true;
    }
 }
 function CheckZip(val)
 {
    if(val.value.match(/^\d{5}?([\-])?([\s])?(\d{4})?$/) && (!(val.value=='00000')))
    {
       return true;
    }
 }
 function CheckMobileNo(val)
 {
        if (val.value.match(/^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/)&& (!(val.value=='000000000000000')))
        {
            return true;
        }
 }
 function IsNumeric(val)   
 {
       var strString=val.value;
       var strValidChars = "0123456789";
       var strChar;
       var blnResult = true;

       if (strString.length == 0) return false;

       //  test strString consists of valid characters listed above
       for (i = 0; i < strString.length && blnResult == true; i++)
          {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
             return false;
             }
          }
       return blnResult;
 }
/***************************End Script for form Validation****************/


/***************************BookMark url with current page url and title****************/

function openWithPageUrl(urlValue,urlParameter,titleParameter)
{
    var PageTitle=getPageTitle();
    var urlWithQueryString;
    var currentPageUrl=window.location;
    if(urlValue!=" ")
      urlWithQueryString=urlValue+"?"+urlParameter+"="+currentPageUrl+"&"+titleParameter+"=Ms. Foundation for Women - "+PageTitle;
    window.open(urlWithQueryString);
}

function ShowPrintPage(){
	        var objWindow = window.open( "/print.html", "Print", "toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=750,height=700" );
	        
	        return false;
        }
function toggleShareLinks(elemId)
{
    showHide(elemId);
    
    document.getElementById(elemId).innerHTML = document.getElementById("shareLinks").innerHTML;
    
    return false;
}
function showHide(elemId)
{
    var curElem = document.getElementById('expand');
    var icon = document.getElementById('share');
    if(curElem.style.display == "none" || curElem.style.display == "")
    {
	    curElem.style.display = "block";
	    icon.className= "expanded";
	}
	else
	{
	    curElem.style.display = "none";
	    icon.className= "collapsed";
	}
}
function ReplaceAll(str, pcFrom, pcTo)
{
    var i = str.indexOf(pcFrom);
    var c = str;

    while (i > -1)
    {
    c = c.replace(pcFrom, pcTo);
    i = c.indexOf(pcFrom);
    }

    return c;

}
function FormatDesc(desc)
{
   desc = ReplaceAll(desc, "<", "#lt");
   desc = ReplaceAll(desc, ">", "#gt");
   
   return desc;
}
function creatingCookie(formattedDesc)
{
document.cookie = "cookieAboutVideo=" + formattedDesc + ";path=/";
}