// JScript source code
function MessagePopUp( strMessage, PopupWidth, PopupHeight )
{
	var winl = (screen.width - PopupWidth)/2;
	var wint = (screen.height - PopupHeight)/2;
	w1=window.open('','w1','width='+PopupWidth+',height='+PopupHeight+',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,top='+winl+',left='+wint);
    w1.document.open();
	w1.document.write("<html><head><title>Email Address Error</title><META HTTP-EQUIV='Pragma' CONTENT='no-cache'><META HTTP-EQUIV='Expires' CONTENT='-1'></head><body>");
    w1.document.write('<table border = "0" cellspacing = "0" cellpadding = "0" width = "100%" height = "100%" style="background: #f7f3e7; border: 2px solid #e5dfcb; color: #46290c;">');
    w1.document.write('  <tr height = "100%" valign = "top">');
    w1.document.write('    <td>');
    w1.document.write(strMessage);
    w1.document.write('    </td>');
    w1.document.write('  </tr>');
    w1.document.write('  <tr>');
    w1.document.write('    <td align = "center" >');
    w1.document.write('      <font face = "Verdana" size = "2">');
    w1.document.write('        <a style="color: #903E1E;" href = "#" onclick = "javascript:window.close();">[Close]</a><br>&nbsp;');
    w1.document.write('      </font>');
    w1.document.write('    </td>' );
    w1.document.write('  </tr>' );
    w1.document.write('</table>');
	w1.document.write('</body></html>');
	w1.document.close();
	w1.focus();
} //function MessagePopUp( strMessage, PopupWidth, PopupHeight )


// JScript source code
function ValidateEmail( strEmail )
{
   /*
   Must contain @ and .
   Must not contain space [ ] ( ) { } ? + ^ > < % ~ : = , | \ # $ * " ` ' ! / & ;
   Must not contain any characters <  32 ascii 
   Must not contain any characters > 126 ascii 
   Must not start with @ 
   Must not contain more than 1 @ 
   Must not start with . 
   Must contain a . after @
   */
      
   var
      strBlue2B      ,
      strRed2B       ,
      strRed2        ,
      strGreen2B     ,
      strColor       ,
      strEmailToCheck,
      strInvalidChars,
      strMailByChars ,
      strErrorMessage              //String
      
   var
      chrCurrentChar;              //Char
      
   var
      i, j,
      atsCounter  ,
      ErrorCounter,
      dotCounter  ;                //Integer
      
   var
      HasInvalidChars   ,
      PreviousWasADot   ,
      HasConsecutiveDots           //Boolean
      

   //Initial values:
   strBlue2B          = "<Font Face = 'Verdana' Size = '1' Color = #0000FF><b>";
   strGreen2B         = "<Font Face = 'Verdana' Size = '1' Color = #009966><b>";
   strRed2B           = "<Font Face = 'Verdana' Size = '1' Color = #FF0000><b>";
   strRed2            = "<Font Face = 'Verdana' Size = '1' Color = #46290C>"   ;
   strEmailToCheck    = new String( strEmail );
   strInvalidChars    = new String( "%[](){}?+^><~:=,;|\\#$*\"`'!/& " );
   strMailByChars     = new String( "" );
   strErrorMessage    = "";
   atsCounter         = 0 ;
   ErrorCounter       = 0 ;
   dotCounter         = 0 ;
   HasInvalidChars    = false;
   HasConsecutiveDots = false;
   PreviousWasADot    = false;
   
   //Check Email:
   for ( i = 0; i < strEmailToCheck.length; i++ )
   {
      chrCurrentChar = strEmailToCheck.charAt( i );
      
      if ( strInvalidChars.indexOf( chrCurrentChar, 0 ) >= 0 || chrCurrentChar.charCodeAt( 0 ) < 32 || chrCurrentChar.charCodeAt( 0 ) > 126 )
      {
         strMailByChars += strRed2B + chrCurrentChar + "</b></Font>";
         HasInvalidChars = true;
      }
      else
      {
         switch( chrCurrentChar )
         {
            case '@':
               atsCounter++;
               strMailByChars += strBlue2B + chrCurrentChar + "</b></Font>"
            break;
            case '.':
               //Count dots after '@':
               if ( atsCounter > 0 ) dotCounter++;
               
               //Color:
               if ( PreviousWasADot ) //Consecutive dots
               {
                  strColor           = strRed2B;
                  HasConsecutiveDots = true;
               }
               else if ( i == 0 || i == strEmailToCheck.length - 1 )
               {
                  strColor = strRed2B;
               }
               else
               {
                  strColor = strGreen2B;
               }
               strMailByChars += strColor + chrCurrentChar + "</b></Font>";
            break; //of: case '.'
            default:
               strMailByChars += chrCurrentChar;
         } //switch( chrCurrentChar )
         
         //For consecutive dots:
         if ( chrCurrentChar == '.' )
         {
            PreviousWasADot = true;
         }
         else
         {
            PreviousWasADot = false;
         }
      } //else of: if ( strInvalidChars.indexOf( chrCurrentChar, 0 ) >= 0 )
      
   } //for ( i = 0; i < strEmailToCheck.length; i++ )
   
   //Must have an '@':
   if ( atsCounter < 1 )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address must have an '@' symbol </Font><Br>";
   }
   
   //Check for multiple '@':
   if ( atsCounter > 1 )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address can only have one '@' symbol </Font><Br>";
   }
   
   //cannot start with '@':
   if ( strEmailToCheck.charAt( 0 ) == '@' )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address cannot start with an '@' symbol </Font><Br>";
   }

   //cannot end with '@':
   if ( strEmailToCheck.charAt( strEmailToCheck.length - 1 ) == '@' )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address cannot end with an '@' symbol </Font><Br>";
   }
   
   //cannot start with '.':
   if ( strEmailToCheck.charAt( 0 ) == '.' )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address cannot start with a dot </Font><Br>";
   }

   //cannot end with '.':
   if ( strEmailToCheck.charAt( strEmailToCheck.length - 1 ) == '.' )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address cannot end with a dot </Font><Br>";
   }
   
   //Must have at least one dot after '@':
   if ( dotCounter < 1 )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address must have at least one dot after the '@' symbol </Font><Br>";
   }
   
   //cannot have consecutive dots:
   if ( HasConsecutiveDots )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email address cannot have consecutive dots</Font><Br>";
   }
   
   //Invalid characters:
   if ( HasInvalidChars )
   {
      ErrorCounter++;
      strErrorMessage += strRed2 + ErrorCounter.toString() + ". Email has invalid characters (Shown in red)</Font><Br>";
   }
   
   //Show email, if there are errors.
   if ( ErrorCounter > 0 )
   {
      strErrorMessage += "<Br><Font Face = 'Verdana' Size = '1'><b>Email:</b>" + strMailByChars + "</Font>";
   }
   
   return strErrorMessage;
} //function ValidateEmail( strEmail )

function VerifyEmail( strEmail )
{
   var
      strErrorMessage              //String
   //Clean spaces:
   if ( strEmail.toUpperCase() != "ENTER YOUR EMAIL" )
   {
      strEmail                           = RemoveAllSpaces( strEmail );
      //frmemaildata.txtemailaddress.value = strEmail;
   }

   //Validate:
   strErrorMessage = ValidateEmail( strEmail );
   
   if ( strErrorMessage != "")
   {
      strErrorMessage = "<p style='display: block; margin-top: 0px; text-align: center; background: #e5dfcb; font: bold 11px Verdana, Tahoma, Arial, sans-serif; margin-bottom: 10px; height: 16px;'> This email address has some errors:</p><p style='display: block; padding: 0px 10px;'>" + strErrorMessage + "</p>";
      MessagePopUp( strErrorMessage, 460, 225 ); //Common/JScript/Screen.Js
     return false;
   }
   else
   {
      return true;
   }
} //function VerifyEmail( strEmail )

function RemoveAllSpaces( strData )
{
   var
      strResult;                   //String

   var
      chrCurrentChar;              //Char
      
   var
      i                            //Integer
    
   //Initial values:
   strResult = "";
     
   for ( i = 0; i < strData.length; i++ )
   {
      chrCurrentChar = strData.charAt( i );
      if ( chrCurrentChar != ' ' ) strResult += chrCurrentChar;
   } //for ( i = 0; i < strData.length; i++ )
   
   return strResult;
} //function RemoveAllSpaces( strData )




function openWin(URL, wdh, hgt, scroll, resize) 
{
	var tb			= "no"  //toolbars
	var mb			= "no"  //menubars
	var st			= "no"  //status
	var sb
	var re
	if(resize != 'yes' && resize != 'no') 
		re =  "yes";
	else
		re = resize;
	if (scroll != 'yes' && scroll != 'no')
		sb = "yes"; 
	 else 
		sb = scroll;
	URL = URL.replace(/\s/g, "+");
	if (hgt >= screen.availHeight)
	{
		hgt = screen.availHeight - 100;
	}
	var h = hgt
	var w = wdh
	var winl = (screen.width - w)/2;
	var wint = (screen.availHeight - h)/2;
	strWindow = "width="+w+",height="+h+",top="+wint+",left="+winl;
	strWindow = strWindow+",toolbar="+tb+",menubar="+mb+",scrollbars="+sb;
	strWindow = strWindow+",status="+st+",resizable="+re;
	window.open(URL,"newwindow",strWindow);	
}
function emailCheck(type)
	{
	var EmailOk  = true
	var Temp     = document.emailForm.emailAddress.value
	var AtSym    = Temp.indexOf('@')
	var Period   = Temp.lastIndexOf('.')
	var Space    = Temp.indexOf(' ')
	var Length   = Temp.length - 1   // Array is from 0 to length-1

	if ((AtSym < 1) ||                     // '@' cannot be in first position
	    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    (Period == Length ) ||             // Must be atleast one valid char after '.'
	    (Space  != -1))                    // No empty spaces permitted
	   {
	      EmailOk = false;
	      alert('Please enter a valid e-mail address.');
	      return false;
	   }
		if(type == 1)
		{
		document.emailForm.submit();
		}
	}

function showCustomPopUp(thisUrl,thisName,theseParams)
{
	remote = open(thisUrl, thisName, theseParams);
}


//	verisign POP-UP WINDOW
function popUp(url)
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function jump(url)
{
	if (url != "" && url != null)
	{
		self.location.href = url;
	}
}
function popNewsletter(URL) {
	var tb = "no"	//toolbars
	var mb = "no"	//menubars
	var st = "no"	//status
	var re = "no"	//resizable
	var sb = "no"	//scrollbars
	var h = "225"	//pop window width
	var w = "460"	//pop window height
	var winl = (screen.width - w)/2;
	var wint = (screen.height - h)/2;
	if (!URL)
	{
		var URL	= "https://www.totalbedroom.com/newsletter_popup.php"
	}
	//var URL	= "/newsletter_popup.php"
	var f = document.frmEmailData;
	var email = f.txtEmailAddress.value;
	URL = URL + '?newsemail=' + email
	strWindow	= "width="+w+",height="+h+",top="+wint+",left="+winl;
	strWindow	= strWindow+",toolbar="+tb+",menubar="+mb+",scrollbars="+sb;
	strWindow	= strWindow+",status="+st+",resizable="+re;
	w2=window.open(URL,"newwindow",strWindow);
	w2.focus();
}
function emailCheck(field)
{
	var Temp     = field;
	var AtSym    = Temp.value.indexOf('@');
	var Period   = Temp.value.lastIndexOf('.');
	var Space    = Temp.value.indexOf(' ');
	var Length   = Temp.value.length - 1;
	
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1))
	{  
		alert('Please enter a valid e-mail address.');
		return false;
	}
	else {
		return true;
	}
}
function submitCheck()
{
	if (document.emailForm.toAddr.value == '' || document.emailForm.fromAddr.value == '')
	{
		alert('You must enter both e-mail addresses.');
	}
	else if(document.emailForm.toName.value == '')
	{
		alert("You must enter your friend's name.");
	}
	else
	{
		if (emailCheck(document.emailForm.toAddr) && emailCheck(document.emailForm.fromAddr))
		{
			document.emailForm.submit();
		}
	}
}