
function openTellAFriendForm()
{ 
    wnd = window.open("TellaFriendForm.aspx", '', 
        'width=575, height=390, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, statusbar=no, menubar=no, copyhistory=no');
    
    window.onfocus = myfunc; 
    function myfunc() { if (wnd) { if (!wnd.closed) { wnd.close();} else { wnd = null; } } }
}


function openContactUsForm()
{ 
    wnd = window.open("ContactUsForm.aspx", '', 
        'width=575, height=390, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, statusbar=no, menubar=no, copyhistory=no');
    
    window.onfocus = myfunc; 
    function myfunc() { if (wnd) { if (!wnd.closed) { wnd.close();} else { wnd = null; } } }
}


function openSupportForm()
{ 
    wnd = window.open("SupportForm.aspx", '', 
        'width=575, height=390, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, statusbar=no, menubar=no, copyhistory=no');
    
    window.onfocus = myfunc; 
    function myfunc() { if (wnd) { if (!wnd.closed) { wnd.close();} else { wnd = null; } } }
}


function ClientSideIncludeContactUs()
{ 
	clientSideInclude("ContactUsForm", "ContactUsForm.aspx");
}
function ClientSideIncludePrivacy()
{
	clientSideInclude("PrivacyForm", "PrivacyForm.aspx");
}
function ClientSideIncludeSubscriptions()
{
	clientSideInclude("SubscriptionsForm", "SubscriptionsForm.aspx");
}
function ClientSideIncludeSupport()
{
	clientSideInclude("SupportForm", "SupportForm.aspx");
}
function ClientSideIncludeTellaFriend()
{
	clientSideInclude("TellaFriendForm", "TellaFriendForm.aspx");
}

function ClientSideIncludeTraining()
{
	clientSideInclude("Training", "Training.aspx");
}

function clientSideInclude(id, url) {
//setCookie(cookieName, url);

  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id + 
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}


function setCookie(name, value) {
alert(value);
  var curCookie = name + "=" + escape(value);
  document.cookie = curCookie;
  alert('curCookie' + curCookie);
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
    alert(dc);
  return unescape(dc.substring(begin + prefix.length, end));
}

function ValidEmail(src) 
{
	 var email = document.getElementById(src).value;     
   if(email != '')
   {
		 var emailReg = "^([a-zA-Z0-9])(([\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$";
		 var regex = new RegExp(emailReg);
		 if(regex.test(email))
				return true;
		 else 
			{        
				alert('Enter valid Email');				
				return false;
			}
		}
 }

function IncludeFooter()
{
	clientSideInclude("Footer", "Footer.html");
}

function MM_openBrWindow(theURL,winName,features)
{ 
    window.open(theURL,winName,features);
}

function IncludeSignupPgae()
{
	clientSideInclude("SignUp", "SignUp.aspx");
}

function ValidateForm(dt, dateformat)
{
	var dp = document.getElementById(dt);			
	if (dp.value != "" && isDate(dp.value, dateformat) == false)
	{
		dp.focus();
		return false;
	}	
    return true;
}

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, dateformat)
{
	var dtCh;
	if(dateformat == "MM/dd/yyyy" || dateformat == "dd/MM/yyyy")
		dtCh = "/";
	else if(dateformat == "MM-dd-yyyy" || dateformat == "dd-MM-yyyy")
		dtCh = "-";
	else if(dateformat == "MMM dd yyyy" || dateformat == "dd MMM yyyy")
		dtCh = " ";
	var daysInMonth = DaysArray(12);
	var pos1;
	var pos2;
	var strMonth;
	var strDay;
	var strYear;
	
	if(dateformat == "MM/dd/yyyy" || dateformat == "MM-dd-yyyy" || dateformat == "MMM dd yyyy")
	{			
		pos1 = dtStr.indexOf(dtCh);
		pos2 = dtStr.indexOf(dtCh,pos1+1);
		
		strMonth = dtStr.substring(0,pos1);
		if(dateformat == "MMM dd yyyy")
		strMonth = getMonthNumber(strMonth.toLowerCase());	
		strDay = dtStr.substring(pos1+1,pos2);
		strYear = dtStr.substring(pos2+1);
		strYr = strYear;
	}
	else if(dateformat == "dd/MM/yyyy" || dateformat == "dd-MM-yyyy" || dateformat == "dd MMM yyyy")
	{	
		pos1 = dtStr.indexOf(dtCh);
		pos2 = dtStr.indexOf(dtCh,pos1+1);
		
		strMonth = dtStr.substring(pos1+1,pos2);
		if(dateformat == "dd MMM yyyy")
		strMonth = getMonthNumber(strMonth.toLowerCase());	
		strDay = dtStr.substring(0,pos1);
		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 (dtStr.toLowerCase().match("circa") || dtStr.toLowerCase().match("abt") || dtStr.toLowerCase().match("aft") || dtStr.toLowerCase().match("bet") || dtStr.toLowerCase().match("bef"))
		return true;
	
	if ((pos1 == -1 || pos2 == -1) || 
			(strMonth.length < 1 || month < 1 || month > 12) ||
			(strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) ||
			(strYear.length != 4) || (dtStr.indexOf(dtCh,pos2+1)!= -1))
	{	
		alert("Entered date is not matching with date format");
		return false;
	}		
return true;
}

function getMonthNumber(Name)
{
  var month;    //Create a local variable to hold the string
 
  switch(Name)
  {
    case "jan":
      month = 1;
      break;
    case "feb":
      month = 2;
      break;
    case "mar":
      month = "3";
      break;
    case "apr":
      month = 4;
      break;
    case "may":
      month = 5;
      break;
    case "jun":
      month = 6;
      break;
    case "jul":
      month =7;
      break;
    case "aug":
      month = 8;
      break;
    case "sep":
      month = 9;
      break;
    case "oct":
      month = 10;
      break;
    case "nov":
      month = 11;
      break;
    case "dec":
      month = 12;
      break;
    default:
      month = 0;
  }
  return month.toString();
}
