// Vignette Generated Content Marker - DO NOT REMOVE
<!--

/* astrology giftguide drop-down */
function validate() {
	if (document.giftguide.sign.selectedIndex > 0) {
	
		var selectedPath = document.giftguide.sign[document.giftguide.sign.options.selectedIndex].value
		selectedPath = selectedPath.toLowerCase();
		
		var selectedSex = document.giftguide.gender[document.giftguide.gender.options.selectedIndex].value
		
		var path = "/astrology/giftguide/" + selectedPath;
		path += "/0,,600882-" + selectedSex + ",00.html"
		//alert(path);
		document.giftguide.action = path;
  	} else {
    	alert("Please select a sign!");
      	return false;
	}	
}

/* 2004 Yearly Horoscopes /astrology/overview/articles/0,,606662_607363,00.html */
function jumpTo(destination) {
	window.document.location.href = destination;
}

/* s2F */
/* need this for xhtml docs which can't have embedded JavaScript - jtanna */
function s2fSendForm () {
	var mywin = window.open ('http://www.ivillage.co.uk/s2f/ukform/1,,,00.html?s2fURL=' + escape(document.location.href)+'&s2fTitle='+escape(window.document.title)+'&s2fucid=', 's2f', 'HEIGHT=610,WIDTH=510,resizable=no,scrollbars=yes')
}

function submitIt(f) {
	if (f.email.value == "") {
		alert("Please enter your email address");
		return false;
	} else {
		if (check_address(f.email.value) == false) {
			alert("Please check your email address");
			return false;
		} else {
		return true;
		}
	}
}

//called by function submitIt
function check_address(s) {
		 /* Must have these */
    if ( s.indexOf('@') != -1 &&
		 s.indexOf('.') != -1 &&
		 
		 /* Must not have these */
		 s.indexOf(' ') == -1 &&
		 s.indexOf(',') == -1 && 
		 s.indexOf('..') == -1 && 
		 s.indexOf('@@') == -1 &&
		 s.indexOf('.@') == -1 && 
		 s.indexOf('@.') == -1 && 
		 s.search(/^www./) == -1 &&
		 s.indexOf('/') == -1 &&
		 
		 /* Must not have these */
		 s.charAt(0) != '@' && 
		 s.charAt(s.length-1) != '@' && 
		 s.charAt(0) != '.' && 
		 s.charAt(s.length-1) != '.') {
			//alert('returning true');
			return true;
	} else {
		return false;
    }
}

function SetCookieG (name,value,expires,path,domain) {
  // expires represents a value in days
  var ckToday = new Date();
  if (expires != null) { var exp = new Date(ckToday.getTime() + expires * 24 * 60 * 60 * 1000); }
  document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + exp.toGMTString() : "") + "; path=" + ((path) ? path : "/") + ((domain) ? "; domain=" + domain : "");
}


// @param frm - form object to be processed
// @param ws_auto - check form only, or check form and return true
// @return true/false
function processSage(frm, ws_auto) {
	var email = frm.email.value;
	if (!isValidEmail(email)) {
	 	alert("Please enter a valid email address");
		return false;
	}
	
	var addrs = frm.email.value.split(",");
	if (addrs.length > 1) {
		var cimsWindow = window.open('http://www.ivillage.co.uk/sorry','_top',''); 
		return false;
	}
	
	var actionUrl = "https://subscriber.ivillage.com/sagews?";
	var context = "IVILLAGEUK";
	var ws_type = frm.ws_type.value;
	var ip = "196.221.201.214";
	
	// Test if required inputs field exists
    if (!frm.txtRequiredInputs) {
        alert("DEVELOPER ERROR: Missing required inputs field.");
        return false;
    }

    if (trimSpace(frm.txtRequiredInputs.value) == "") {
        alert("DEVELOPER ERROR: Required inputs field is empty.");
        return false;
    }
	
    var requiredInputs = frm.txtRequiredInputs.value.split(" ");
	//alert("requiredInputs=" + requiredInputs);
	var tempCheck = false;
	var curObject;
	var optins="";
	var personalInfo="";
	var poptins="";
	var poptins_dates="";
	var tempDate=new Date();
	var tempDay = tempDate.getDate();
	var tempMonth = tempDate.getMonth() + 1;
	var tempYear = tempDate.getYear();
	
	// Set optin list
	if (ws_type == "optout-all") {
		// Make sure
		if (!confirm("Are you sure you want to Unsubscribe from ALL Newsletters?")) {
			return false ;
		}
		//ws_type = "optout-all";
		optins = frm.all_optout_list.value;
		//alert(optins);
	} else if (ws_type != "optout-mm" && ws_type != "optout") {
	
	    for (var i=0; i < requiredInputs.length; i++) { 
			//alert("requiredInputs: " + i + ", " + requiredInputs[i]);
			curObject = eval("frm." + requiredInputs[i]);
			
		
			// Check checkbox or select items
			if (typeof(curObject.length) != "undefined") {
			//alert("i dont wanna be in here");
				for (var j=0; j<curObject.length; j++) {
			   		if (curObject[j].checked || curObject[j].selected) {
						tempOptin = curObject[j].value;
											
						// Check for optins
						if ( ws_type.indexOf("optin") != -1 && ( tempOptin == 1046 || tempOptin == 1047 || tempOptin == 732 || tempOptin == 898 || tempOptin == 11726 || tempOptin == 11727 || tempOptin == 11728 || tempOptin == 11729 || tempOptin == 11730 || tempOptin == 11731 || tempOptin == 11732 || tempOptin == 11733 ) ) {
							poptins += "&poptinId=" + tempOptin;
							poptins_dates += "&startDay_" + tempOptin + "="  + tempDay + "&startMonth_" + tempOptin + "=" + tempMonth + "&startYear_" + tempOptin + "=" + tempYear;
							
						} else if (tempOptin == 11735 || tempOptin == 11739 || tempOptin == 11737 || tempOptin == 11738) {
							SetCookieG('iv_getgardening_'+j, tempOptin, '250', '', '.ivillage.co.uk');
							poptins += "&poptinId=" + tempOptin;
							poptins_dates += "&startDay_" + tempOptin + "="  + tempDay + "&startMonth_" + tempOptin + "=" + tempMonth + "&startYear_" + tempOptin + "=" + tempYear;
						} else {
							optins += "&optinId=" + tempOptin;
						}
						tempCheck = true;
						
					}
				}
				//alert(optins);
			} else {
				//alert("im in here");
				if (curObject.checked || curObject.selected) {
					optins = optins + "&optinId=" + curObject.value;
					//alert(optins);
					if ( ws_type.indexOf("personalized") != -1) {
						var optinId = frm.optinId.value
						poptins += "&poptinId=" + optinId;
						poptins_dates += "&startDay_" + optinId + "="  + tempDay + "&startMonth_" + optinId + "=" + tempMonth + "&startYear_" + 	optinId + "=" + tempYear;
						//alert("did you get here?");
					} 
					tempCheck = true;
					//When there are no checkboxes, just email - e.g., unsubscribe page.
				} 
			}
		}
		 
		//alert("poptins_dates=" + poptins_dates);
		
		if (!tempCheck) {
		   	alert("You must select one or more newsletters.");
			return false;
		}
	}
	
	// Check to stop processing
	if (ws_auto == "check_form_only") {
		// Requires SSDB processing
		return true
	}
	
	//alert("type is "+ws_type);

	// Handle a webservice call without any SSDB processing.
	// Set rurl value
	if (ws_type == "optin") {
	//alert("here");
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optin,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optin,00.html';
	} else if (ws_type == "optin-stopsmoking") {
		// DO WE NEED THIS ANYMORE???
		//ws_type = "submitPersonData";
		
		// Some additonal checks
		if (frm.first_name.value == "") {
			alert("You must enter a first name.");
			return false;
		}
		if (frm.last_name.value == "") {
			alert("You must enter a surname name.");
			return false;
		}
		if (frm.confirm_email.value == "") {
			alert("You must enter a confirmed email.");
			return false;
		}
		if (frm.email.value != frm.confirm_email.value) {
			alert("The email and confirmed email values do not match.");
			return false;
		}
		//personalInfo="&firstName=" + frm.first_name.value + "&lastName=" + frm.last_name.value;
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optin-stopsmoking,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optin-stopsmoking,00.html';
	} else if (ws_type == "optin-gbb") {
		ws_type = "optin";
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optin-gbb,00.html';
	} else if (ws_type == "optin-freebies") {
		ws_type = "optin";
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optin-freebies,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optin-freebies,00.html';
	} else if (ws_type == "optout-all") {
		ws_type = "optout";
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optout-all,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optout-all,00.html';
	} else if (ws_type == "optout-mm") {
		ws_type = "optout";
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optout-mm,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optout-mm,00.html';
	} else if (ws_type == "optin-personalized") {
		ws_type = "personalizedOptin";
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optin-personalized,00.html';
	} else {
		ws_type = "optout";
		optinId = frm.optinId.value;
		var rurl = 'http://www.ivillage.co.uk/newsletters/thankyou/0,,optout,00.html';
		// testing only
		//var rurl='http://devwork.ivillage.co.uk/newsletters/thankyou/0,,optout,00.html';
	}
	
	
	if (ws_type != "personalizedOptin" && ws_type != "optout") {
		// Check to reset ws_type for a challenge
		if (poptins == "") {
			ws_type = "optin";
		} else {
			ws_type = "personalizedOptin";
		}
	}
	
	var args = "r="+rurl +"&s="+ws_type + "&context="+context + optins + poptins + poptins_dates + "&email="+email + personalInfo + "&ip="+ip;
	
    var newsletter=actionUrl+args;
	//alert(newsletter);
	// Use same window to make the SAGE WS call
	var cimsWindow = window.open(newsletter,'_top',''); 
	
    return false;
}

// ===== Support Functions =====
function LTrim(txt) {
    return txt.replace(/^[\s]+/g, "");
}

function RTrim(txt) {
    return txt.replace(/[\s]+$/g, "");
}

function trimSpace(txt) {
    var tmpTxt = LTrim(txt);
    return RTrim(tmpTxt);
}

function newWin(url,name,features){
	var newWin = window.open(url,name,features);
}

//-->