// for modal message
messageObj = new DHTML_modalMessage();
messageObj.setShadowOffset(5);	

function displayContactForm(){
	messageObj.setSize(311,364);
	messageObj.setSource('contactform.inc');	
	messageObj.setShadowDivVisible(false);	
	messageObj.display();
}
function closeContactForm() {
	messageObj.close();	
}

// for onload pop up

function displayPopForm(){
	messageObj.setSize(475,375);
	messageObj.setSource('popupMybabysworld.html');	
	messageObj.setShadowDivVisible(false);	
	messageObj.display();
}
function closePopForm() {
	messageObj.close();	
}



/////////////////////////jj contest ///////////////////////////////

function displayContestForm(){

	var date = new Date();
	var nemesis_temp = date.getTime();
	var nemesis = (parseInt(nemesis_temp) / 1000);

	//if(getcookie('jjcontest') == null || (getcookie('jjcontest') != 'registered' && (parseInt(nemesis) > (parseInt(getcookie('jjcontest')) + 86400))) ){

		messageObj.setSize(659,654);
		messageObj.setSource('jj_mbw_contest/popContest.html');	
		messageObj.setShadowDivVisible(false);	
		messageObj.display();

	//}
}



function displayThankYou(which){
	
		messageObj.setSize(795,509);
		
		if(which == 'preg'){
			messageObj.setSource('jj_mbw_contest/gender.html');	
		} else{
			messageObj.setSource('jj_mbw_contest/horroscope.html');	
		}
		messageObj.setShadowDivVisible(false);	
		messageObj.display();
}

function remindLater(){
	newcookie('jjcontest');
	closePopForm();
}


//to retrieve a cookie
function getcookie(name) {
	name= name+"="
	cookiestring=document.cookie+";";
	if (cookiestring.indexOf(name,0)==-1) {
		return null;
	} else {
		start=cookiestring.indexOf(name,0)+name.length;
		numchar=cookiestring.indexOf(";",start)-start;
		return unescape(cookiestring.substr(start,numchar));
	}
}



function newcookie(name) {
	
	var date = new Date();
	var nemesis_temp = date.getTime();
	var nemesis = (parseInt(nemesis_temp) / 1000);
	document.cookie = name+"="+escape(nemesis)+";path=/";
	
}

function new_eternal_cookie(name) {
	death = new Date();
	death.setDate(death.getDate() + 500);
	document.cookie = name+"="+escape('registered')+"; expires="+death.toUTCString()+";path=/";
	
}

function submitJohnsonTool3() {
		
		var f=document.jf3;
		var a;
		if((f.pdd.selectedIndex>0 && f.pmm.selectedIndex>0 && f.pyy.selectedIndex>0) || (f.cdd.selectedIndex>0 && f.cmm.selectedIndex>0 && f.cyy.selectedIndex)) {
			if(f.name.value!='') {
				if(f.email.value!='') {
					if(isEmail(f.email.value)) {
						a = new sack();
						a.requestFile = 'johnson_enroll_contest.php';
						a.setVar('email',f.email.value);
						a.setVar('dtp',f.pyy.options[f.pyy.selectedIndex].value+'-'+f.pmm.options[f.pmm.selectedIndex].value+'-'+f.pdd.options[f.pdd.selectedIndex].value+' 00:00:00');
						a.setVar('dtc',f.cyy.options[f.cyy.selectedIndex].value+'-'+f.cmm.options[f.cmm.selectedIndex].value+'-'+f.cdd.options[f.cdd.selectedIndex].value+' 00:00:00');
						a.setVar('name',f.name.value);
						if(f.getads.checked) a.setVar('accept','Y'); else a.setVar('accept','N');
						a.onCompletion = function(){ eval(a.response); }
						a.runAJAX();	
						
					} else alert('Πρέπει να συμπληρώσετε σωστά το e-mail σας!');
				} else alert('Πρέπει να συμπληρώσετε το e-mail σας!');
			} else alert('Πρέπει να συμπληρώσετε το ονοματεπώνυμο σας!');
		} else alert('Πρέπει να συμπληρώσετε μία από τις δύο ημερομηνίες!');
		
	}

//////////////////////////// jj contest ends //////



//////////////////////////// game subscribe ////////////

function subscribeGame(which) {
		
		var f=document.jf4;
		var a;
		var nemesis = false;
		
		if(which == 'horroscope'){
			if(f.cdd.selectedIndex>0 && f.cmm.selectedIndex>0 && f.cyy.selectedIndex) {
				nemesis = true;
			}
		}
		
		if(which == 'gender'){
			if(f.pdd.selectedIndex>0 && f.pmm.selectedIndex>0 && f.pyy.selectedIndex) {
				nemesis = true;
				
			}
		}
		if(nemesis == true){

			if(f.name.value!='') {
				if(f.email.value!='') {
					if(isEmail(f.email.value)) {
						a = new sack();
						a.requestFile = 'mbw_enroll_game.php';
						a.setVar('email',f.email.value);
							
						if(which == 'horroscope'){
							a.setVar('dtc',f.cyy.options[f.cyy.selectedIndex].value+'-'+f.cmm.options[f.cmm.selectedIndex].value+'-'+f.cdd.options[f.cdd.selectedIndex].value+' 00:00:00');
							if(f.cdd2.selectedIndex>0 && f.cmm2.selectedIndex>0 && f.cyy2.selectedIndex) {
								a.setVar('dtc2',f.cyy2.options[f.cyy.selectedIndex].value+'-'+f.cmm2.options[f.cmm2.selectedIndex].value+'-'+f.cdd2.options[f.cdd2.selectedIndex].value+' 00:00:00');
							}
						} else if (which == 'gender'){
							a.setVar('dtp',f.pyy.options[f.pyy.selectedIndex].value+'-'+f.pmm.options[f.pmm.selectedIndex].value+'-'+f.pdd.options[f.pdd.selectedIndex].value+' 00:00:00');
						}
					
						a.setVar('name',f.name.value);
						if(f.getads.checked) a.setVar('accept','Y'); else a.setVar('accept','N');
						a.onCompletion = function(){ eval(a.response); }
						a.runAJAX();	
						
					} else alert('Πρέπει να συμπληρώσετε σωστά το e-mail σας!');
				} else alert('Πρέπει να συμπληρώσετε το e-mail σας!');
			} else alert('Πρέπει να συμπληρώσετε το ονοματεπώνυμο σας!');
		} else alert('Πρέπει να συμπληρώσετε την ημερομηνία!');
		
	}

function allReadyRegistered(){
	new_eternal_cookie('game_member');
	closePopForm();
}

function displayGameForm(which){

	var date = new Date();
	var nemesis_temp = date.getTime();
	
	if(getcookie('game_member') == null || (getcookie('game_member') != 'registered' )){

		messageObj.setSize(783,637);
	
	if (which == 'horroscope'){
		messageObj.setSource('mbw_games/popHorroscope.html');
	
	} else if (which == 'gender')
	{
			messageObj.setSource('mbw_games/popBorG.html');
	}
		messageObj.setShadowDivVisible(false);	
		messageObj.display();
	}
}	
	
//////////////////////////// game subscribe ends //////

function displaySend2FriendForm(aid){
	messageObj.setSize(275,343);
	messageObj.setSource('send2friend.inc');	
	messageObj.setShadowDivVisible(false);	
	messageObj.display();
	setTimeout('populateS2F('+aid+')',1000);
}
function populateS2F(aid) {
	if(document.send2friendform) {
		document.send2friendform.artid.value=aid;
		document.send2friendform.msg.value='Είδα κάτι ενδιαφέρον στο www.myworld.gr!\nΔες το κι εσύ: http://www.myworld.gr/site/content.php?artid='+aid;
	} else setTimeout('populateS2F('+aid+')',1000);	
}
function closeSend2FriendForm() {
	messageObj.close();	
}

function displayRegForm(){
	messageObj.setSize(370,382);
	messageObj.setSource('register.htm');	
	messageObj.setShadowDivVisible(false);	
	messageObj.display();
}
function closeRegForm() {
	messageObj.close();	
}

function go_contact() {
	var a,f;
	f=document.contactform;
	if(f.fname.value=='' || f.lname.value=='' || f.email.value=='' || f.age.value=='' || f.msg.value=='') {
		alert('πρέπει να συμπληρώσετε όλα τα πεδία!');
		return;
	}
	a = new sack();
	a.requestFile = 'contact.php';
	a.setVar('fname',f.fname.value);
	a.setVar('lname',f.lname.value);
	a.setVar('email',f.email.value);
	a.setVar('age',f.age.value);
	a.setVar('msg',f.msg.value);
	a.onCompletion = function(){ document.getElementById('contactdiv').innerHTML=a.response;}
	a.runAJAX();
}

function go_send2friend() {
	var a,f;
	f=document.send2friendform;
	if(f.name1.value=='' || f.name1.value=='Ονομ/νυμο' || f.name2.value=='' || f.name2.value=='Ονομ/νυμο' || f.email1.value=='' || f.email2.value=='' || f.email1.value=='e-mail' || f.email2.value=='e-mail' || f.msg.value=='') {
		alert('πρέπει να συμπληρώσετε όλα τα πεδία!');
		return;
	}
	a = new sack();
	a.requestFile = 'send2friend.php';
	a.setVar('name1',f.name1.value);
	a.setVar('name2',f.name2.value);
	a.setVar('email1',f.email1.value);
	a.setVar('email2',f.email2.value);
	a.setVar('msg',f.msg.value);
	a.onCompletion = function(){ document.getElementById('send2fdiv').innerHTML=a.response;}
	a.runAJAX();
}

function go_login() {
	var a,f;
	f=document.loginfrm;
	if(f.pass.value=='' || f.email.value=='') {
		alert('πρέπει να συμπληρώσετε όλα τα πεδία!');
		return;
	}
	a = new sack();
	a.requestFile = 'login.php';
	a.setVar('email',f.email.value);
	a.setVar('pass',f.pass.value);
	a.onCompletion = function(){ document.getElementById('logindiv').innerHTML=a.response;}
	a.runAJAX();	
}

function doRegSubmit() {
	f=document.rf;
	if(mytrim2(f.fname.value)=='' || mytrim2(f.lname.value)=='' || mytrim2(f.email.value)=='' || mytrim2(f.area.value)=='' || mytrim2(f.pass.value)=='' || mytrim2(f.city.value)=='' || (!f.sex[0].checked && !f.sex[1].checked)) alert('πρέπει να συμπληρώσετε τα υποχρεωτικά πεδία!');
	else go_register();	
}
function mytrim2(str) {
	return str.replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1');
}
	
function go_register() {
	var a,f;
	f=document.rf;
	if(f.fname.value=='' || f.lname.value=='' || f.email.value=='' || f.pass.value=='' || f.city.value=='') {
		alert('πρέπει να συμπληρώσετε όλα τα πεδία!');
		return;
	}
	a = new sack();
	a.requestFile = 'register.php';
	a.setVar('fname',f.fname.value);
	a.setVar('lname',f.lname.value);
	a.setVar('email',f.email.value);
	a.setVar('byear',f.ayea.value);
	a.setVar('pass',f.pass.value);
	a.setVar('gender',f.sex[0].checked?'f':'m');
	a.setVar('mobile',f.mobile.value);
	a.setVar('city',f.city.value);
	a.setVar('area',f.area.value);
	a.setVar('getnewsletter',f.newsletter.checked?'Y':'N');
	
	a.onCompletion = function(){ document.getElementById('regformdiv').innerHTML=a.response;}
	a.runAJAX();
}

// ADTV 
	var flipper_timeout;
	var flipper=-1;
	
	function flipper_show(iflip) {
		if(document.getElementById(flippers[iflip])) document.getElementById(flippers[iflip]).style.visibility="visible";
		if(document.getElementById('adtv_link_'+iflip)) document.getElementById('adtv_link_'+iflip).className='selected';			
	}
	function flipper_hide(iflip) {
		if(document.getElementById(flippers[iflip]))document.getElementById(flippers[iflip]).style.visibility="hidden";
		if(document.getElementById('adtv_link_'+iflip)) document.getElementById('adtv_link_'+iflip).className='';			
	}	
	function flipper_start() { 
		try {
				if (flipper_max>0) {
					flipper_hide(flipper);
					if (flipper<flipper_max) flipper++;	else flipper=0; 
					flipper_show(flipper);
					flipper_timeout=setTimeout("flipper_start()",7000);	
				} 
		} catch(ex) { }
	}
	
	function flipper_isrunning() {
		if(document.getElementById('adtv_pause_link')) return (document.getElementById('adtv_pause_link').className=='pause');
		return false;
	}
	
	function flipper_pause() {
		if(document.getElementById('adtv_pause_link')) {
			if(flipper_isrunning()) {	
				clearTimeout(flipper_timeout);
				document.getElementById('adtv_pause_link').className='play';
			} else {
				document.getElementById('adtv_pause_link').className='pause';
				flipper_start();				
			}
		}
	}

	function flipper_next() {
		if (flipper_max) { 
			if (flipper_max>0) {
				flipper_hide(flipper);
				if (flipper<flipper_max) flipper++;	else flipper=0; 
				flipper_show(flipper);
				if(flipper_isrunning()) {
					clearTimeout(flipper_timeout);
					flipper_timeout=setTimeout("flipper_start()",7000);	
				}
			} 
		}
	}
	
	function flipper_prev() {
		if (flipper_max) { 
			if (flipper_max>0) {
				flipper_hide(flipper);
				if (flipper>0) flipper--;	else flipper=flipper_max; 
				flipper_show(flipper);
				if(flipper_isrunning()) {
					clearTimeout(flipper_timeout);
					flipper_timeout=setTimeout("flipper_start()",7000);	
				}
			} 
		} 
	}
	
	function flipper_move(iflip) {
		if(flipper_isrunning()) clearTimeout(flipper_timeout);
		flipper_hide(flipper);
		flipper=iflip;
		flipper_show(flipper);
		if(flipper_isrunning()) flipper_timeout=setTimeout("flipper_start()",7000);	
	}
	
	flipper_start();
	
	function mouseX(e) {
		if(e) return e.clientX;
		else if(window.event) return window.event.pageX;
		else return 0;
	}
	
	var currsubmenu;
	function opensubmenu(cid,e) {
		var d=document.getElementById('subcat_'+cid);
		if(d) {
			if(currsubmenu) currsubmenu.style.visibility='hidden';
			if(currsubmenu!=d) {
				d.style.visibility='visible';
				d.style.left=(mouseX(e)-30)+'px';
				currsubmenu=d;
			} else currsubmenu=null;
		} else if(currsubmenu) {
			currsubmenu.style.visibility='hidden';
			currsubmenu=null;
		}
	}

	var tohide,hideto;
	function hidesubmenu(o){
		if(o) {
			if(hideto) clearTimeout(hideto);
			tohide=o;
			hideto=setTimeout('hidesubmenu_t()',1000);
		}
	}	
	function hidesubmenu_t(){
		if(tohide) {
			tohide.style.visibility='hidden';
			tohide=null;
		}
	}
	
	var currartsmenu;
	function openartsmenu(cid,e) {
		var d=document.getElementById('darts_'+cid);
		if(d) {
			if(currartsmenu) currartsmenu.style.visibility='hidden';
			if(currartsmenu!=d) {
				d.style.visibility='visible';
				if (cid==0)
					d.style.left='2px';
				else if (cid==1)
					d.style.left='215px';
				else if (cid==2)
					d.style.left='428px';
				else if (cid==3)	
					d.style.left='640px';		
				else if (cid==4)
					d.style.left='854px';
						
				currartsmenu=d;
			} else currartsmenu=null;
		} else if(currartsmenu) {
			currartsmenu.style.visibility='hidden';
			currartsmenu=null;
		}
	}

	var tohidearts,hidetoarts;
	function hideartsmenu(o){
		if(o) {
			if(hidetoarts) clearTimeout(hidetoarts);
			tohidearts=o;
			hidetoarts=setTimeout('hideartsmenu_t()',1000);
		}
	}	
	
	function submitJohnsonTool() {
		var f=document.jf;
		var a;
		if((f.pdd.selectedIndex>0 && f.pmm.selectedIndex>0 && f.pyy.selectedIndex>0) || (f.cdd.selectedIndex>0 && f.cmm.selectedIndex>0 && f.cyy.selectedIndex)) {
			if(f.email.value!='') {
				if(isEmail(f.email.value)) {
					a = new sack();
					a.requestFile = 'johnson_enroll.php';
					a.setVar('email',f.email.value);
					a.setVar('dtp',f.pyy.options[f.pyy.selectedIndex].value+'-'+f.pmm.options[f.pmm.selectedIndex].value+'-'+f.pdd.options[f.pdd.selectedIndex].value+' 00:00:00');
					a.setVar('dtc',f.cyy.options[f.cyy.selectedIndex].value+'-'+f.cmm.options[f.cmm.selectedIndex].value+'-'+f.cdd.options[f.cdd.selectedIndex].value+' 00:00:00');
					if(f.getads.checked) a.setVar('accept','Y'); else a.setVar('accept','N');
					a.onCompletion = function(){ eval(a.response); }
					a.runAJAX();	
					
				} else alert('Πρέπει να συμπληρώσετε σωστά το e-mail σας!');
			} else alert('Πρέπει να συμπληρώσετε το e-mail σας!');
		} else alert('Πρέπει να συμπληρώσετε μία από τις δύο ημερομηνίες!');
		
	}
	
	function submitJohnsonTool2() {
		var f2=document.jf2;
		var a;
			
		if(f2.cdd.selectedIndex>0 && f2.cmm.selectedIndex>0 && f2.cyy.selectedIndex) {
			if(f2.email.value!='') {
				if(isEmail(f2.email.value)) {
					a = new sack();
					a.requestFile = 'johnson_birth_enroll.php';
					a.setVar('email',f2.email.value);
					a.setVar('dtc',f2.cyy.options[f2.cyy.selectedIndex].value+'-'+f2.cmm.options[f2.cmm.selectedIndex].value+'-'+f2.cdd.options[f2.cdd.selectedIndex].value+' 00:00:00');
					if(f2.getads.checked) a.setVar('accept','Y'); else a.setVar('accept','N');
					a.onCompletion = function(){ eval(a.response); }
					a.runAJAX();
					
				} else alert('Πρέπει να συμπληρώσετε σωστά το e-mail σας!');
			} else alert('Πρέπει να συμπληρώσετε το e-mail σας!');
		} else alert('Πρέπει να συμπληρώσετε την ημερομηνία!');  
	}
	
	
	function showZDates() {
		document.getElementById('jj_zodiac_menudiv').style.display='block';
		document.getElementById('jj_zodiac_buttondiv').style.display='none';
	}
	
	function hideZDates() {
		document.getElementById('jj_zodiac_menudiv').style.display='none';
		document.getElementById('jj_zodiac_buttondiv').style.display='block';
	}	
	
	
//////////////   flash game height fix /////////////////

	function flashHeightToggle(){
			
		if (document.getElementById('midcol').style.height == '1270px' ){
		
			document.getElementById('midcol').style.height = '3170px';
			document.getElementById('threecol').style.height = '3170px';
			document.getElementById('flas_cont').style.height = '3000px';
		}
		
		else{
			document.getElementById('midcol').style.height = '1270px';
			document.getElementById('threecol').style.height = '1270px';
			document.getElementById('flas_cont').style.height = '1100px';
		}
	
	
	}

	//////////////   flash game height fix ends /////////////////
	
	///// set flash to opaque //////////

	function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='opaque'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='opaque' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'opaque');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='opaque' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='opaque' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
}
