function linkedin(title,summary,source,page) {
	var url = 'http://www.linkedin.com/shareArticle?mini=true&url=' + page + '&title=' + title + '&summary=' + summary + '&source=' + source + '';
	popup(520,570,0,0,url,"LinkedIn",false,false,false,false);
}

var current_featured = 0;
var featured_interval = 0;
var max_featured = 1;

function playPauseFeatured(max) {
	max_featured = max;
	if (featured_interval > 0) {
		clearInterval(featured_interval);
		featured_interval = 0;
		writeLayer("play_button","PLAY");
	} else {
		featured_interval = setInterval("nextFeatured()", 20000);
		writeLayer("play_button","PAUSE");
	}
}

function nextFeatured() {
	displayLayer("featured_" + current_featured,false);
	if (current_featured == max_featured - 1) {
		current_featured = 0;
	} else {
		current_featured++;
	}
	displayLayer("featured_" + current_featured,true);
}


function printPage() {
	window.print();
}

function pressEnter(e,nameForm,nextField,validateBy)
{
	var keynum;
	var keychar;
	
	if (window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if (e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	//keychar = String.fromCharCode(keynum);
	if (keynum == 13)
	{
		if (nextField != "")
		{
			eval('document.forms["' + nameForm + '"]["' + nextField + '"].focus();');
		}
		else
		{
			if (validateBy == "")
			{
				eval('document.forms["' + nameForm + '"].submit();');
			}
			else
			{
				eval(validateBy);
			}
		}
	}
}

function rate(value) {
	document.forms["formrate"]["recommendation_rate"].value = value;
	document.forms["formrate"].submit();
}

function sendRecommend() {
	var errors = "";
	
	if (!isValidEmail(document.forms["formrecommend"]["email"].value)) {
		alert("Please write a valid email address.")
	} else {
		document.forms["formrecommend"].submit();
	}
}

function sendComment() {
	var errors = "";
	
	if (document.forms["formcomment"]["comment_text"].value == "") {
		alert("Please write your comments.")
	} else {
		document.forms["formcomment"].submit();
	}
}

function sendCommentunreg() {
	var errors = "";
	var commentId=document.forms["formcomment"]["comment_article_id"].value;
	var commentText=document.forms["formcomment"]["comment_text"].value;
	if (document.forms["formcomment"]["comment_text"].value == "") {
		alert("Please write your comments.")
	} else {
		window.open ("http://www.peoplematters.in/templates/unreg_popup.php?CommentId="+commentId+"&commentText="+commentText,"mywindow","menubar=1,resizable=1,width=340,height=220,left=340px,top=250px"); 
	}
}


function vote() {
	var errors = "";
	
	//if (document.forms["formpoll"]["result_member_id"]) {
		var options = document.forms["formpoll"]["result_answer_id"];
		var answered = false;
		for (var i=0; i<options.length; i++) {
			if (options[i].checked) answered = true;
		}
		if (!answered) {
			alert("Please choose an answer.");
		} else {
			document.forms["formpoll"].submit();
		}
	//} else {
	//	alert("You need to be a register member to vote.");
	//}		
}

function logout() {
	document.forms["formlogout"].submit();
}

function checkLogin() {
	var errors = "";
	
	if (document.forms["formlogin"]["member_email"].value == "") {
		errors += "Email\n";
	}
	if (document.forms["formlogin"]["member_password"].value == "") {
		errors += "Password\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["formlogin"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}

function checkLogin2() {
	var errors = "";
	
	if (document.forms["login_form"]["member_email"].value == "") {
		errors += "Email\n";
	}
	if (document.forms["login_form"]["member_password"].value == "") {
		errors += "Password\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["login_form"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}

function checknewsletter() {
	var errors = "";
	
	if (document.forms["newsletter_form"]["newslet_name"].value == "") {
		errors += "Name\n";
	}
	if (document.forms["newsletter_form"]["newslet_email"].value == "") {
		errors += "Email\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["newsletter_form"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}


function checkParticipate()
{
	var errors = "";
		
	if (document.forms["formparticipate"]["name"].value == "") {
		errors += "Name\n";
	}
	if (!isValidEmail(document.forms["formparticipate"]["email"].value)) {
		errors += "Email\n";
	}
	if (document.forms["formparticipate"]["subject"].value == "") {
		errors += "Subject\n";
	}
	if (document.forms["formparticipate"]["comments"].value == "") {
		errors += "Comments\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["formparticipate"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}

function checkForgotten()
{
	var errors = "";
		
	if (!isValidEmail(document.forms["formpassword"]["member_email"].value)) {
		errors += "Email\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["formpassword"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}

function checkContact()
{
	var errors = "";
		
	if (document.forms["formcontact"]["name"].value == "") {
		errors += "Name\n";
	}
	if (!isValidEmail(document.forms["formcontact"]["email"].value)) {
		errors += "Email\n";
	}
	if (document.forms["formcontact"]["subject"].value == "") {
		errors += "Subject\n";
	}
	if (document.forms["formcontact"]["comments"].value == "") {
		errors += "Comments\n";
	}
	
	if (errors == "") {
		//return true;
		document.forms["formcontact"].submit();
	} else {
		alert("Please review the following information:\n\n" + errors);
		//return false;
	}
}

function popup(w,h,t,l,url,winName,status,toolBar,scrollBars,resizable) {
	if (scrollBars == undefined) scrollBars = "auto";
	if (resizable == undefined) resizable = "no";
  	var sWid = screen.width;
  	var sHi = screen.height;
	var wid = w;
	var hi = h;
	if ((t == 0) && (l == 0)) {
		var tp = (sHi/2)-(hi/2);
		var lft = (sWid/2)-(wid/2);
	} else {
		var tp = t;
		var lft = l;	
	}
	if (scroll && document.all && (navigator.userAgent.indexOf("Mac") > -1)) wid = wid+17;
	newwin=window.open(url,winName,"width=" + wid + ",height=" + hi + ",status=" + status + ",scrollbars=" + scrollBars + ",toolbar=" + toolBar + ",resizable=" + resizable + ", top = "+ tp +", left ="+ lft + ", screenX=" + lft +", screenY= "+tp);
	newwin.focus();
}

function changeClassName(name, className){
	var obj = document.getElementById(name);
	obj.className = className;
}


function writeLayer(name, txt){
	var layer = document.getElementById(name);
	layer.innerHTML = txt;
}

function displayLayer(name, visible){
	var foc = document.getElementById(name);
	if (foc) {
		if (visible) {
			foc.style.display='block';
		} else {
			foc.style.display='none';
		}
	}
}

function toggleLayer(name){
	var foc = document.getElementById(name);
	if (foc) {
		if ((foc.style.display=='')  || (foc.style.display=='block')) {
			foc.style.display='none';
		} else {
			foc.style.display='block';
		}
	}
}

function setStyle(name, property, value){
	var foc = document.getElementById(name);
	if (foc) {
		foc.style[property] = value;
	}
}

function sendPayment() {
	document.forms.formpayment.submit();
}

function checkSubscribe(validate) {
	// do form validation here
	var errors = "";
	
	if (document.forms.formsubscribe.member_email) {
		//var username = document.forms.formsubscribe.member_username.value;
		//var password = document.forms.formsubscribe.member_password.value;
		//var confirm = document.forms.formsubscribe.confirm.value;
		var firstname = document.forms.formsubscribe.member_firstname.value;
		var surname = document.forms.formsubscribe.member_surname.value;
		var email = document.forms.formsubscribe.member_email.value;
		var company = document.forms.formsubscribe.member_company.value;
		var designation = document.forms.formsubscribe.member_designation.value;
		
		/*
		 if (validate == "username") {
			if ((username != "") && (isValidUsername(username))) {
				existUsernameSubscribing(username);
			} else {
				alert("Please enter a correct Username:\n\n Must be minimun 3 and maximun 12 characters.\n Must begin with an alphabet.\n Only alphabets, numbers and underscore can be used.");
			}
			return;
	
		} else
		*/
		if (validate == "email") {
			if ((email != "") && (isValidEmail(email))) {
				existEmailSubscribing(email);
			} else {
				alert("Please enter a correct Email");
			}
			return;
			
		} else {
			
			//if (password != "") {
//				if (!isValidPassword(password)) {
//					errors += "Password (must be 6 characters minimun)\n";
//				}
//				if (password != confirm) {
//					errors += "Password confirmation\n";
//				}
//			} else {
//				errors += "Password\n";
//			}
			
			if (!isValidName(firstname)) {
				errors += "Name (only alphabets with no spaces, use '-')\n";
			}
			if (!isValidName(surname)) {
				errors += "Lastname (only alphabets with no spaces, use '-')\n";
			}
			if (!isValidEmail(email)) {
				errors += "Email address\n";
			}
			if (company == "") {
				errors += "Company\n";
			}
			if (designation == "") {
				errors += "Designation\n";
			}
		}
		
		document.forms.formsubscribe.name.value = firstname + " " + surname;
		document.forms.formsubscribe.email.value = email;
		document.forms.formsubscribe.phone.value = telephone;
		
		document.forms.formsubscribe.ship_name.value = firstname + " " + surname;
		document.forms.formsubscribe.ship_email.value = email;
		document.forms.formsubscribe.ship_phone.value = telephone;
	}
	
	var telephone = document.forms.formsubscribe.member_telephone.value;
	var address1 = document.forms.formsubscribe.member_address1.value;
	var address2 = document.forms.formsubscribe.member_address2.value;
	var postcode = document.forms.formsubscribe.member_postcode.value;
	var city = document.forms.formsubscribe.member_city.value;
	var state = document.forms.formsubscribe.state.value;
	
	if ((telephone == "") || (telephone.length < 5)) {
		errors += "Telephone\n";
	}
	if (address1 == "") {
		errors += "Address 1\n";
	}
	if (postcode == "") {
		errors += "Postcode\n";
	}
	if (city == "") {
		errors += "City\n";
	}
	
	if (state == "") {
		errors += "State\n";
	}
	
	document.forms.formsubscribe.address.value = address1 + ", " + address2;
	document.forms.formsubscribe.city.value = city;
	document.forms.formsubscribe.postal_code.value = postcode;
	
	document.forms.formsubscribe.ship_address.value = address1 + ", " + address2;
	document.forms.formsubscribe.ship_city.value = city;
	document.forms.formsubscribe.ship_postal_code.value = postcode;
	
	if (errors == "") {
		document.forms.formsubscribe.submit();

	} else {
		alert("Please review the following information:\n\n" + errors);
	}
}

function checkProfile(validate) {
	// do form validation here
	//var username = document.forms.formprofile.member_username.value;
	var password = document.forms.formprofile.member_password.value;
	var confirm = document.forms.formprofile.confirm.value;
	var firstname = document.forms.formprofile.member_firstname.value;
	var surname = document.forms.formprofile.member_surname.value;
	var email = document.forms.formprofile.member_email.value;
	var telephone = document.forms.formprofile.member_telephone.value;
	var company = document.forms.formprofile.member_company.value;
	var designation = document.forms.formprofile.member_designation.value;
	
	/*
	if (validate == "username") {
		if ((username != "") && (isValidUsername(username))) {
			existUsernameEditing(username);
		} else {
			alert("Please enter a correct Username:\n\n Must be minimun 3 and maximun 12 characters.\n Must begin with an alphabet.\n Only alphabets, numbers and underscore can be used.");
		}

	} else
	*/
	if (validate == "email") {
		if ((email != "") && (isValidEmail(email))) {
			existEmailEditing(email);
		} else {
			alert("Please enter a correct Email");
		}
		
	} else {
		var errors = "";
		
		if (password != "") {
			if (!isValidPassword(password)) {
				errors += "Password (must be 6 characters minimun)\n";
			}
			if (password != confirm) {
				errors += "Password confirmation\n";
			}
		}
		if (!isValidName(firstname)) {
			errors += "Name (only alphabets with no spaces, use '-')\n";
		}
		if (!isValidName(surname)) {
			errors += "Lastname (only alphabets with no spaces, use '-')\n";
		}
		if (!isValidEmail(email)) {
			errors += "Email address\n";
		}
		if (company == "") {
			errors += "Company\n";
		}
		if (designation == "") {
			errors += "Designation\n";
		}
		if ((telephone == "") || (telephone.length < 5)) {
			errors += "Telephone\n";
		}
		
		if (document.forms.formprofile.member_country_id) {
			var address1 = document.forms.formprofile.member_address1.value;
			var address2 = document.forms.formprofile.member_address2.value;
			var postcode = document.forms.formprofile.member_postcode.value;
			var city = document.forms.formprofile.member_city.value;
			
			if (address1 == "") {
				errors += "Address 1\n";
			}
			if (postcode == "") {
				errors += "Postcode\n";
			}
			if (city == "") {
				errors += "City\n";
			}
		}
		
		if (errors == "") {
			document.forms.formprofile.submit();
		} else {
			alert("Please review the following information:\n\n" + errors);
		}
	}
}

function checkRegister(validate) {
	// do form validation here
	//var username = document.forms.formregister.member_username.value;
	var password = document.forms.formregister.member_password.value;
	var confirm = document.forms.formregister.confirm.value;
	var firstname = document.forms.formregister.member_firstname.value;
	var surname = document.forms.formregister.member_surname.value;
	var email = document.forms.formregister.member_email.value;
	var telephone = document.forms.formregister.member_telephone.value;
	var company = document.forms.formregister.member_company.value;
	var designation = document.forms.formregister.member_designation.value;
	
	/*
	if (validate == "username") {
		if ((username != "") && (isValidUsername(username))) {
			existUsername(username);
		} else {
			alert("Please enter a correct Username:\n\n Must be minimun 3 and maximun 12 characters.\n Must begin with an alphabet.\n Only alphabets, numbers and underscore can be used.");
		}
	} else
	*/
	if (validate == "email") {
		if ((email != "") && (isValidEmail(email))) {
			existEmail(email);
		} else {
			alert("Please enter a correct Email");
		}
		
	} else {
		var errors = "";
		
		if (password != "") {
			if (!isValidPassword(password)) {
				errors += "Password (must be 6 characters minimun)\n";
			}
			if (password != confirm) {
				errors += "Password confirmation\n";
			}
		} else {
			errors += "Password\n";
		}
		if (!isValidName(firstname)) {
			errors += "Name (only alphabets with no spaces, use '-')\n";
		}
		if (!isValidName(surname)) {
			errors += "Lastname (only alphabets with no spaces, use '-')\n";
		}
		if (company == "") {
			errors += "Company\n";
		}
		if (designation == "") {
			errors += "Designation\n";
		}
		if ((telephone == "") || (telephone.length < 5)) {
			errors += "Telephone\n";
		}
		
		if (errors == "") {
			document.forms.formregister.submit();
		} else {
			alert("Please review the following information:\n\n" + errors);
		}
	}
}

function checkRegister_offer(validate) {
	// do form validation here
	var title = document.forms.formregister.member_title.value;
	var firstname = document.forms.formregister.member_firstname.value;
	var lastname = document.forms.formregister.member_lastname.value;
	var email = document.forms.formregister.member_email.value;
	var designation = document.forms.formregister.member_designation.value;
	var organization = document.forms.formregister.member_organization.value;
	
	var address = document.forms.formregister.member_address.value;
	var city = document.forms.formregister.member_city.value;
	var state = document.forms.formregister.member_state.value;
	var pin = document.forms.formregister.member_pin.value;
	var telephone = document.forms.formregister.member_telephone.value;
	
	
		var errors = "";
		if (!isValidEmail(email)) {
			//existEmailOffer(email);
			errors += "Enter valid email-id\n";
		} 
	
		if (title == "") {
			errors += "Select Title\n";
		}
		if (!isValidName(firstname)) {
			errors += "Name (only alphabets with no spaces, use '-')\n";
		}
		if (!isValidName(lastname)) {
			errors += "Lastname (only alphabets with no spaces, use '-')\n";
		}
		if (designation == "") {
			errors += "Designation\n";
		}
		if (organization == "") {
			errors += "Organization\n";
		}
		if (address == "") {
			errors += "Address\n";
		}
		if (city == "") {
			errors += "City\n";
		}
		if (state == "") {
			errors += "State\n";
		}
		
		if (pin == "")  {
			errors += "Pin Code\n";
		}
		if ((telephone == "") || (telephone.length < 5)) {
			errors += "Telephone\n";
		}
		if (errors == "") {
			document.forms.formregister.submit();
		} else {
			alert("Please review the following information:\n\n" + errors);
		}
	
}
function existEmailOffer(email) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existemail', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if ((result != 1) || (result == "")) {
				alert("Your are not eligible for this contest.\r\n Subscribe to participate");
			} else {
				checkRegister_offer("");
			}			
		}
	}
	xmlhttp.send('email=' + email);
}
function existEmail(email) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existemail', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Email already exist in the database, if you forgot your password please click on reset password.");
			} else {
				checkRegister("");
			}			
		}
	}
	xmlhttp.send('email=' + email);
}

function existEmailSubscribing(email) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existemail', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Email already exist in the database, if you forgot your password please click on reset password.");
			} else {
				checkSubscribe("");
			}			
		}
	}
	xmlhttp.send('email=' + email);
}

function existUsernameSubscribing(username) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existusername', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Username already exists in the database, please try a different one.");
			} else {
				checkSubscribe("email");
			}			
		}
	}
	xmlhttp.send('username=' + username);
}

function existEmailEditing(email) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existemail_editing', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Email already exists in the database, please try a different one.");
			} else {
				checkProfile("");
			}			
		}
	}
	xmlhttp.send('email=' + email);
}

function existUsernameEditing(username) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existusername_editing', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Username already exists in the database, please try a different one.");
			} else {
				checkProfile("email");
			}			
		}
	}
	xmlhttp.send('username=' + username);
}

function existUsername(username) {
	var xmlhttp = InstanceXMLHttpRequest();
	xmlhttp.open('POST', '/ajax?method=existusername', true);

	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	xmlhttp.onreadystatechange = function() {		
		if (xmlhttp.readyState == 4) {
			//alert(xmlhttp.responseText);
			var result = parseInt(xmlhttp.responseText);
			if (!isNaN(result) && (result > 0)) {
				alert("Username already exists in the database, please try a different one.");
			} else {
				checkRegister("email");
			}			
		}
	}
	xmlhttp.send('username=' + username);
}

function InstanceXMLHttpRequest() {
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	return req;
}

function isValidEmail(email) {
	//var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
	var re = /^[\w\+\\'\.-]+@[\w\\'\.-]+\.[a-zA-Z]{2,}$/;
	return (re.test(email.toLowerCase()));
}


function isValidName(value) {
	re = /^[a-zA-Z-]+$/;
	return (re.test(value.toLowerCase()));
}

function isValidUsername(value) {
	if ((value.length < 3) || (value.length > 12)) {
		return false;
	} else {
		re = /^[a-zA-Z]\w+$/;
		return (re.test(value.toLowerCase()));
	}
}

function isValidUsernamePassword(value) {
	re = /^\w+$/;
	return (re.test(value.toLowerCase()));
}

function isValidPassword(value) {
	if (value.length < 6) {
		return false;
	} else {
		if (value != "") {
			return true;
		} else {
			return false;
		}
		//re = /^\w+$/;
		//return (re.test(value.toLowerCase()));
	}
}


String.prototype.trim = function (){
	return this.replace(/(^\s+)/g, "").replace(/(\s+$)/g, "");
}

function isValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/

   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-)\d{4}\1\d{1,2}$/

   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/

   }
   if ( reg1.test(dateStr) == false ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

function openpopup(popurl,name){
	winPops=window.open(popurl, "","width=840,height=640,scrollbars,resizable")
}

function sendnewsletters() {
    M.byId('msg-box').innerHTML = '';
    if(M.byId('email').value == '') {
        M.byId('msg-box').style.display = 'block';
        M.byId('msg-box').innerHTML = "Enter email";
        return false;
    }
    if(!M.isEmail(M.byId('email').value.toString())) {
        M.byId('msg-box').style.display = 'block';
        M.byId('msg-box').innerHTML = "Enter valid email";
        return false;
    }
	M.byId('msg-box').innerHTML = "<span><img src=\"/support/tej_images/loader.gif\" /></span>";    
    s = "page=newsletters";
    s+="&member_email="+M.byId('email').value;
    M.AJAX.request({
        target:'/newsletter',
        query:s,
        method:'POST',
        onSuccess:function(msg) {
            M.byId('msg-box').style.display = 'block';
            if(msg == 'done') {
                M.byId('msg-box').innerHTML = '<span><img src=\"/support/tej_images/correct_new_small.png\" /></span>&nbsp;Subscribed Successfully';
            } else if(msg == 'error') {
                M.byId('msg-box').innerHTML = '<span><img src=\"/support/tej_images/wrong_new_small.png\" /></span>&nbsp;Error !';
            } else {
                M.byId('msg-box').innerHTML = '<span><img src=\"/support/tej_images/wrong_new_small.png\" /></span>&nbsp;Failed !'
            }
        },
        onFailed:function(msg){
            
        }
    });
    return false;
}
