var bIsIE   = (document.all) ? true : false;
var bIsDOM  = (document.getElementById) ? true : false;

if(document.images) {
	postoff = new Image
	poston = new Image
	postoff.src = 'images/left_but_popular_posts.gif'
	poston.src = 'images/left_but_popular_posts_on.gif'

	commoff = new Image
	common = new Image
	commoff.src = 'images/left_but_recent_comments.gif'
	common.src = 'images/left_but_recent_comments_on.gif'

	archiveoff = new Image
	archiveon = new Image
	archiveoff.src = 'images/left_but_archive_dates.gif'
	archiveon.src = 'images/left_but_archive_dates_on.gif'

	pregnantoff = new Image
	pregnanton = new Image
	pregnantoff.src = 'images/menu_get_pregnant.gif'
	pregnanton.src = 'images/menu_get_pregnant_roll.gif'
}


function dropdown_posts() {
	if(document.getElementById('popular_posts').style.display=='block') {
		document.getElementById('popular_posts').style.display='none';
		document.post.src=postoff.src
	} else {
		document.getElementById('popular_posts').style.display='block';
		document.getElementById('recent_comments').style.display='none';
		document.getElementById('archive').style.display='none';
		document.post.src=poston.src
		document.comm.src=commoff.src
		document.archive.src=archiveoff.src
	}
}

function dropdown_comments() {
	if(document.getElementById('recent_comments').style.display=='block') {
		document.getElementById('recent_comments').style.display='none';
		document.comm.src=commoff.src
	} else {
		document.getElementById('recent_comments').style.display='block';
		document.getElementById('popular_posts').style.display='none';
		document.getElementById('archive').style.display='none';
		document.comm.src=common.src
		document.post.src=postoff.src
		document.archive.src=archiveoff.src
	}
}

function dropdown_archive() {
	if(document.getElementById('archive').style.display=='block') {
		document.getElementById('archive').style.display='none';
		document.archive.src=archiveoff.src
	} else {
		document.getElementById('archive').style.display='block';
		document.getElementById('popular_posts').style.display='none';
		document.getElementById('recent_comments').style.display='none';
		document.archive.src=archiveon.src
		document.post.src=postoff.src
		document.comm.src=commoff.src
	}
}


function roll()
	{
		document.pregnant.src=pregnanton.src;
		//alert(document.pregnant.src);
	}

function isEmail(str) {
  var supported = 0;
  if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function validateForm(frm)
 {
 	if(frm.name.value == "") {alert("Please enter name"); frm.name.focus(); return false;}
	else if(frm.email.value == "0" || !isEmail( frm.email.value )) {alert("Please enter email"); frm.email.focus(); return false;}
	else if(frm.comment.value == "") {alert("Please enter comment"); frm.comment.focus(); return false;}
	else return true;
 }

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300,left = 320,top = 272');");
}

function popUp_flash(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=277,left = 320,top = 272');");
}

function popUp_product(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=400,left = 320,top = 272');");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
		if ((obj=MM_findObj(args[i]))!=null)
		{   v=args[i+2];
			if (obj.style)
			{
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v;
			}
			if (obj.visibility!=v)
				obj.visibility=v;
		}
}


function hideAll(SelectedMenu){
	MM_showHideLayers('submenu_toiveena-vauva.php','','hide','submenu_olenko-raskaana.php','','hide','submenu_clearblue-ovulaatio-ja-hedelmallisyystuotteet.php','','hide','submenu_lasketun-ajan-laskuri.php','','hide');
}


var timerID = null;
var timerOn = false;
var timecount = 200;

function startTime() {
       if (timerOn == false) {
              timerID = setTimeout( "hideAll()" , timecount);
              timerOn = true;
       }
}


function stopTime() {
       if (timerOn) {
  	        clearTimeout(timerID);
              timerID = null;
              timerOn = false;
       }
}


function setImgSrc( ImgObj, Filename ){
	if( !ImgObj ) return false;
	ImgObj.src = Filename;
}


function collapseDiv( BoxName, Status ){
	if( !(Box=MM_findObj(BoxName)) )
		return false;

	if( Status ){
		if( Status == "show" )
			Box.style.display = "block";
		else
			Box.style.display = "none";
	}
	else{
		if(Box.style.display == "block"){
			Box.style.display = "none";
		}
		else{
			Box.style.display = "block";
		}
	}
}

function Submit_SmileForm(formid){
	document.getElementById(formid).submit();
}


var di_latest = "";
function open_div(di)
{
	if(document.getElementById("div_"+di).style.display=='block') {
		document.getElementById("div_"+di).style.display='none';
	} else {
		document.getElementById("div_"+di).style.display='block';
		if ((di_latest!="")&&(di_latest!=di))	document.getElementById("div_"+di_latest).style.display='none';
	}
	di_latest = di;
}

function quick_link()
{
	document.getElementById("div_6").style.display = "block";
	document.getElementById("div_7").style.display = "none";
	di_latest = "6";
}

function checkResult(showDate){
	if(showDate.text_box.value == "")
		{
			alert("Please enter the date in:\nWhen was the first day of your last period?");
			return false;
		} else {
			return true;
		}
}

function showResult(forms){
	//document.getElementById(forms).submit();
	forms.submit();
	//document.showDate.submit();
}

function test(forms){

		if(showDate.text_box_day.value == "--")
		{
			alert("Täytä pakolliset kentät.");
		} 
		else if(showDate.text_box_month.value == "--")
		{
			alert("Täytä pakolliset kentät.");
		}
		else if(showDate.text_box_year.value == "--")
		{
			alert("Täytä pakolliset kentät.");
		} 
		else
		{
			forms.submit();
		}

}

function whenToStart(forms){

		if(showDate.how_long.value == "---")
		{
			alert("Täytä pakolliset kentät.");
		} else {
			forms.submit();
		}
}

////////////////////////////
function SubmitSearch(){
  document.search_form.submit();
}

function clearBox()
	{
		if (document.search_form.txt_search.value == "Etsi") {
			document.search_form.txt_search.value = "";
			return false;
			}
	}

function MM_Refresh() {
	window.location.reload();
}


function downloadme(x){

    myTempWindow = window.open(x,'','left=10000,screenX=10000');

    myTempWindow.document.execCommand('SaveAs','null',x);

    myTempWindow.close();

}

function getVar(name)
{
	get_string = document.location.search;
	return_value = '';

	do
	{ //This loop is made to catch all instances of any get variable.
		name_index = get_string.indexOf(name + '=');

		if(name_index != -1)
		{
			get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);

			end_of_value = get_string.indexOf('&');
			if(end_of_value != -1)
				value = get_string.substr(0, end_of_value);
			else
				value = get_string;

			if(return_value == '' || value == '')
				return_value += value;
			else
				return_value += ', ' + value;
		}
	}
	while(name_index != -1)

	//Restores all the blank spaces.
	space = return_value.indexOf('+');
	while(space != -1)
	{
		return_value = return_value.substr(0, space) + ' ' +
		return_value.substr(space + 1, return_value.length);

		space = return_value.indexOf('+');
	}

	return(return_value);
}
