
////////////////////////////////////////////////////////////////////////////
////-------------------- BEGIN RELOCATION FUNCTIONS ----------------////////
////////////////////////////////////////////////////////////////////////////

//###################################################################################################
//CLOSE AD POPUPS TO REMOVE POTENTIAL JS ERRORS
	function unloadClosure()
	{if (window.homepopup)window.homepopup.close();
	}

//###################################################################################################
//AD REDIRECT OPENING FRAME, CLOSE SELF
	function adrelocate(url)
	{
	    window.opener.location = url;
	    window.close();
	}

//###################################################################################################
//FRAME BUSTER
	setTimeout ("changePage()", 400);

	function changePage() {
		if (self.parent.frames.length != 0)
			self.parent.location=document.location;
		}

//###################################################################################################
	function validateZip(){
	
	var trouble = "", isTrouble=0,invalidZip=0;
	frm = eval(document.forms['search1']);	
	
	if (frm.zip.value == "")
	{
	trouble += 'Please enter your zip code!';
	isTrouble = 1;
	}
		
	else if (frm.zip.value.length < 5)
	{	
	trouble += 'Please complete your zipcode! \n';
	isTrouble = 1;
	}
	
	else{
		anStr='0123456789';
		for (i=0;i<frm.zip.value.length;i++)
		{
		  c = frm.zip.value.charAt(i);
		  if(anStr.indexOf(c)==-1 && c!=" " && invalidZip == 0)
		  {
		  	trouble += 'Please recheck your zipcode \n';
			isTrouble = 1;
			invalidZip = 1;
		  }
		}//end for loop
	}//end else
	
	if (isTrouble == 0)	frm.submit();
	else alert(trouble);		
	}
//###################################################################################################
	function makeover(){
	//location="http://www.janecosmetics.com/makeover/";
	makeFace = window.open('http://ad.doubleclick.net/clk;4749230;7607638;r?http://www.janecosmetics.com/makeover/default.asp', 'makeover' ,'width=500,height=500,left=150,top=150,toolbars=no,location=no,status=no');
	}
//###################################################################################################
//TRENDS REDIRECT FUNCTION
	function trends(){
	location="http://cgi.janecosmetics.com/login/middle2.asp";
	}
//###################################################################################################
//LETS TALK W/ LOGIN CHECK
	function letstalk()
	{
	  if (validateLogin()){
		  window.open("http://www.janecosmetics.com/letstalk/jane_survey.asp","letstalk","height=630,width=632,left=350,top=30,scrollbars=yes,menubar=no,toolbar=no");
	  }	
	else
		window.location = "http://cgi.janecosmetics.com/login/login.asp?RequestURL=http://www.janecosmetics.com/?letstalk";
	}//END LETS TALK W/ LOGIN CHECK
//###################################################################################################
//LETS TALK-- NO LOGIN CHECK
	function letstalkbasic(){
	window.open("http://www.janecosmetics.com/letstalk","letstalk","height=630,width=632,left=350,top=30,scrollbars=yes,menubar=no,toolbar=no");
	}//END LETS TALKBASIC FUNCTION

////////////////////////////////////////////////////////////////////////////
////---------------------- END RELOCATION FUNCTIONS ----------------////////
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
////-------------------- BEGIN ECARD FUNCTIONS ---------------------////////
////////////////////////////////////////////////////////////////////////////

//###################################################################################################
//CHECK FORM FUNCTION CALLS
	function checkform(){
	check0();
	}		
//###################################################################################################
//VALIDATE SENDERS INFORMATION
	function check0() {
	var sendername = document.myform.sendername.value;
	var youremail = document.myform.youremail.value;
	
	if (!sendername || !youremail )
	{
	  goerror();
	}
	else if (validateEmail('youremail'))
	{
	  check1();
	}
	}//END CHECK0 FUNCTION
//###################################################################################################
//VALIDATE FIRST INPUT -- BOTH ARE REQUIRED
	function check1() {
	var name1 = document.myform.name1.value;
	var email1 = document.myform.email1.value;
	
	if (!name1 || !email1 )
	{
	  goerror();
	}
	
	else if((email1) && (validateEmail('email1')))
	{
	  checkInputs('2');
	}
	}//END VALIDATE FIRST INPUT FUNCTION
//###################################################################################################
//VALIDATE INPUTS
	function checkInputs(num) {
	var name,email;
	var inrange = (num<=5);
	
	if (inrange)
	{
	
	email = eval("document.myform.email" + num +".value");
	name = eval("document.myform.name" + num +".value");
	var thisemail = "email" + num;
	num++;	
		
		if ((name && !email) || (!name && email)) {
		  goerror();
		}	
		else if ((email) && (validateEmail(thisemail)))
		{ 	     
		  checkInputs(num);
		}		  
		else if(!email && !name)
		{	  
		  checkInputs(num);	
		}
	}
	
	else
	{
	  document.forms['myform'].submit();
	}	
	}//END CHECK INPUTS FUNCTION	
//###################################################################################################
//ERROR ALERT TEXT
	function goerror() {
	  alert("Please make sure all the required fields are filled in!");
	}
//###################################################################################################
	function validateEmail(whichemail){

	var thisemail = eval("document.myform." + whichemail);
	var invalidEmail;
	
	//designer output for alert boxes
	if (whichemail == "youremail") alertemail = "your E-mail";
	else alertemail = "recipient's E-mail " + whichemail.substring(5,whichemail.length);
	
	
	if ((thisemail.value.indexOf('@',0)==-1 || thisemail.value.indexOf('www.',0)==0 || thisemail.value.indexOf('.',0)==-1))
	{	alert("Please recheck " + alertemail);
		return false;
	}
					
	else {
		anStr='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-@._';
		for (i=0;i<thisemail.value.length;i++){
			
			c = thisemail.value.charAt(i);
			if(anStr.indexOf(c)==-1 && c!=" " && invalidEmail == 0){
			  
			  invalidEmail = 1;
			  alert("Please recheck " + alertemail);
			  return false;
			}
		}
	}
	return true;
	}//end validateEmail function
//###################################################################################################
//FUNCTION TO INPUT FORM VALUES FROM COOKIES
	function openEcard(){
	var sEmailAddress,sName,sID;
		
		if(document.cookie == null)
		{
		  document.write("there are no cookies here")
		}
		else
		{
			var cEmailAddress,cName,cID;
			
			cEmailAddress = "USEREMAIL";
			cName = "FNAME";
			cID = "USERID";
		}
		thisCookie = document.cookie.split("&")
		for(i=0; i<thisCookie.length; i++)
			  {
			  	if (thisCookie[i].split("=")[0] == cEmailAddress){
				sEmailAddress = unescape(thisCookie[i].split("=")[1]);
				sEmailAddress = unescape(sEmailAddress.split(";")[0]);
				}
				else if (thisCookie[i].split("=")[0] == cName){
				sName = unescape(thisCookie[i].split("=")[1]);
				}
				else if (thisCookie[i].split("=")[0] == cID){
				sID = unescape(thisCookie[i].split("=")[1]);
				}
			  }
		document.myform.sendername.value  = sName;
		document.myform.youremail.value = sEmailAddress;
		document.myform.user_id.value = sID;
	}//END OPENECARD FUNCTION
//###################################################################################################
//INPUT CROSS BROWSER EQUALIZATION FUNCTIONS
	function writeInput(size,name,type){
	if(type == "")type="text";
	
	if (document.layers) size = eval(size - 10);
	document.write("<input type=\"" + type + "\" class=\"noBorder\" size=\"" + size + "\" name=\"" + name + "\">")
	}
	
	function writeInput2(size,name,type){
	if(type == "")type="text";
	
	if (document.layers) size = eval(size - 10);
	document.write("<input type=\"" + type + "\" class=\"border2\" size=\"" + size + "\" name=\"" + name + "\">")
	}
		
	function writeTextArea(rows,cols,name){
	if (document.layers) cols = eval(cols - 26);
	document.write("<textarea class='noBorder' rows='" + rows + "' cols='" + cols + "' name='" + name + "' wrap='true'></textarea> ");
	}
	
	function writeTextArea2(rows,cols,name){
	if (document.layers) cols = eval(cols - 26);
	document.write("<textarea class='border2' rows='" + rows + "' cols='" + cols + "' name='" + name + "' wrap='true'></textarea> ");
	}
	
		
//###################################################################################################	
////////////////////////////////////////////////////////////////////////////
///////----------------- END ECARD FUNCTIONS -----------------------////////
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
///////----------------- BEGIN POLL FUNCTIONS ----------------------////////
////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////
// WRITE FORM TAGS FOR POLL
	function writePollForm(URL){
	
	var nVersion = parseInt(navigator.appVersion) 
	var isNS = (navigator.appName == "Netscape"); 
	if((nVersion <= 4)&&(isNS == true)) 
	{ 
	document.write ("<form name='dpoll' action=javascript:pollResults('" + URL + "','popuppoll','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=200,height=530,top=100,screenX=300,screenY=350') method='post' target='popuppoll'>"); 
	}
	else
	{ 
	document.write ("<form name='dpoll' action='" + URL + "' method='post' target='popuppoll'>"); 
	}
	
	}// end function
//###################################################################################################
//  POPUP POLL RESULTS
	function pollResults (earl, name, widgets, specialsURL) 
	{
	var url = earl;
	popupWin = window.open(url, name, widgets);
	popupWin.opener.top.name = "pollresults";
	popupWin.focus();
	}
//###################################################################################################

////////////////////////////////////////////////////////////////////////////
///////------------------ END POLL FUNCTIONS -----------------------////////
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
///////----------------- BEGIN SELECT MENU FUNCTIONS ---------------////////
////////////////////////////////////////////////////////////////////////////

//###################################################################################################
//function for product menu dashes... browser and platform specified
function writeDashes(){

var whatToWrite = "<option value=\"#\">";
lineStyle = "_";
  
  //PC SPECIFIC
  if (navigator.platform == "Win32") numDashes=26;
  //if not a pc (most likely MAC)
  else
  {
     if(document.all) numDashes = 29;  
     else numDashes = 25;  
  }	

 for(i=0;i <= numDashes; i++) whatToWrite += lineStyle;
 whatToWrite += "</option>";
 document.write(whatToWrite)	
}//END WRITEDASHES FUNCTION
//###################################################################################################
//function for product select menu
	function menuChange(selectVar){
	
	locationValue = eval("document.forms['productdrop']." + selectVar + ".options[document.forms['productdrop']." + selectVar + ".selectedIndex].value");
	
	  if (locationValue != "#"){
	    location = 'http:\/\/cgi.janecosmetics.com' + locationValue;
	    //alert(locationValue);
	  }	
	}
//###################################################################################################

////////////////////////////////////////////////////////////////////////////
///////----------------- END SELECT MENU FUNCTIONS ----------  -----////////
////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
///////----------------- BEGIN LOGIN - COOKIE FUNCTIONS ------------////////
////////////////////////////////////////////////////////////////////////////

//###################################################################################################
//LOGIN CHECK FUNCTION w/ REDIRECT CAPABILITIES
	function logincheck(wheretogo)
	{
	if (validateLogin())  window.location = wheretogo;	
	else  window.location = "http://cgi.janecosmetics.com/login/login.asp?RequestURL=http://stagewww.janecosmetics.com" + wheretogo;
	}//END LOGIN CHECK FUNCTION
//###################################################################################################
// returns First Name element of UserInfoArray
	// set "janelogin" cookie to UserInfoArray
	var janeCookie = document.cookie;
	var UserInfoArray = getCookie("janelogin");	
	
	function validateLogin()
	{	
		if(UserInfoArray != null)	
		{	
			if (getUserCookie(UserInfoArray, "LOGIN") == "1") 
				return true;
			else 
				return false;
		}
		else return false;
	}
//###################################################################################################

	
	// general cookie getting function for "ccsCookie"
	function getCookie(name)
	{	var index = janeCookie.indexOf(name + "=");
		if (index == -1) return null;
		index = janeCookie.indexOf("=", index) + 1;
		var endstr = janeCookie.indexOf(";", index);
		if (endstr == -1) endstr = janeCookie.length;
		return unescape(janeCookie.substring(index, endstr));
	}
//###################################################################################################
// get JANE cookie and return values
	function getUserCookie(toSplit, cookieName)
	{	var cookies = toSplit.split('&'); 
		var cookiePieces;
		var i = -1;
		while (cookies[++i])
		{	cookiePieces = cookies[i].split('=');
			if (cookiePieces[0].substring(0,1) == ' ')
				cookiePieces[0] = cookiePieces[0].substring(1, cookiePieces[0].length);
			if (cookiePieces[0] == cookieName)
				return ""+unescape(cookiePieces[1]);
		}
		return "";
	}
//###################################################################################################

////////////////////////////////////////////////////////////////////////////
///////------------------- END LOGIN - COOKIE FUNCTIONS ------------////////
////////////////////////////////////////////////////////////////////////////

//###################################################################################################
//POPUP FUNCTION
	function popup(url, name,width,height)	{ 		
	popit = window.open(url,name,"height="+height+",width="+width+",left=50,top=150,scrollbars=yes,menubar=no,toolbar=no");
	  }	
//###################################################################################

