var sCurrentMenuCode = '';
function menuActivateThis(sMenuCode){
	//hide previous - if any
	if (sCurrentMenuCode!='') {
		try{document.getElementById('sub_'+ sCurrentMenuCode).style.visibility='hidden';}catch(error){}
		try{document.getElementById('menu_'+ sCurrentMenuCode).className=sCurrentMenuCode + '_off';}catch(error){}
	}

	//show current
	try{document.getElementById('sub_'+ sMenuCode).style.visibility='visible';}catch(error){}
	try{document.getElementById('menu_'+ sMenuCode).className=sMenuCode + '_over';}catch(error){}
	
	//save current for next time
	sCurrentMenuCode = sMenuCode


}

function menuDeactivateAll(){
	if (sCurrentMenuCode!='') {
		try{document.getElementById('sub_'+ sCurrentMenuCode).style.visibility='hidden';}catch(error){}
		try{document.getElementById('menu_'+ sCurrentMenuCode).className=sCurrentMenuCode + '_off';}catch(error){}
		sCurrentMenuCode='';
	}
}



function sendVote(){
	for (var j=0;j<frmVote.iChoiseID.length;j++){if (frmVote.iChoiseID[j].checked) {frmVote.action='/svc/vote/doVote.asp'; frmVote.submit(); return; }}	
	alert('Για να ψηφίσετε επιλέξτε μιά από τις παραπάνω επιλογές.')	
}

function doSelectDiet(){
	var iClass = document.getElementById('dietSelectClass').value
	var iCal = document.getElementById('dietSelectCal').value
	document.location.href='/svc/myDiet/?cls=' + iClass + '&cal=' + iCal
}

function doSelectCalCalc(){
	document.getElementById('frmCalCalc').submit()
}

function doSelectCalCalc_changeMinSelector(){
	if (document.getElementById('renderMinSelector').selectedIndex>0){
		document.getElementById('renderCalSelector').selectedIndex=0
	}
}
function doSelectCalCalc_changeCalSelector(){
	if (document.getElementById('renderCalSelector').selectedIndex>0){
		document.getElementById('renderMinSelector').selectedIndex=0
	}
}

function doSelectSyntCalc(){
	if (document.getElementById('renderSyntCat').selectedIndex>0){document.location.href='/svc/healthyGourme/?iSyntCatIndex=' + document.getElementById('renderSyntCat').value}
}

function doSelectCalIMB(){
	document.getElementById('frmCalIMB').submit()
}

function doPsychoTestSelSex(iSexId){
	document.location.href='?iSexId=' + iSexId
}

function PrintMe(){
	var sLink = document.location.href
	if (sLink.indexOf('?')<0){sLink = sLink + '?'} else {sLink = sLink + '&'}
	var wndPrint = window.open(sLink+'mode=print', '_blank');
}
function EmailMe(){
	document.location.href='/svc/send/?title=' + document.title + '&url=' + document.location
}
function doSelectIssue(oS){
	var iEntId = oS.value;
	var sURL = iEntId.substring(iEntId.length-3, iEntId.length)
	document.location.href='/html/ent/' + sURL + '/ent.' + iEntId + '.asp'
}

function doSelectHealthSubCategory(oSel){
	if (oSel.selectedIndex>0){ document.location.href='/category.asp?catId=' + oSel.value}
}

function doSelectChildHealthSubCategory(oS){
	var iEntId = oS.value;
	var sURL = iEntId.substring(iEntId.length-3, iEntId.length)
	document.location.href='/html/ent/' + sURL + '/ent.' + iEntId + '.asp'
	
}



function Trim(strInputString){
	strInputString = strInputString + ' '
	objRegExp = /(^ +)|( +$)/g
	return strInputString.replace(objRegExp, "");
}
function blnValidEmail(strInputString){
	var objRegExp = /(^[^@]+@[^@]+\..+$)/gi
	if (objRegExp.test(strInputString)) {return true;} else {return false;}
}
function blnValidLatinString(strInputString){
	var objRegExp = /(^[a-z0-9]+$)/gi
	if (objRegExp.test(strInputString)) {return true;} else {return false;}
}

function doSendFriends(){
document.getElementById('txtName').value = Trim(document.getElementById('txtName').value)
document.getElementById('txtEmail').value = Trim(document.getElementById('txtEmail').value)
document.getElementById('txtEmails').value = Trim(document.getElementById('txtEmails').value)

if (document.getElementById('txtName').value.length<3) {alert('Πρέπει να συμπληρώσετε το όνομά σας.'); document.getElementById('txtName').focus(); return}
if (!blnValidEmail(document.getElementById('txtEmail').value)) {alert('Το e-mail σας δεν είναι σωστό.'); document.getElementById('txtEmail').focus(); return}
if (document.getElementById('txtEmails').value.length<5) {alert('Πρέπει να συμπληρώσετε τα email των φίλων σας.'); document.getElementById('txtEmails').focus(); return}

document.getElementById('btnSubmit').disabled=true;
document.getElementById('frmUI').submit();

}

function doRegister(){
	document.getElementById('RegForm').action='doRegistration.asp';
	document.getElementById('RegForm').submit();
}

function doSignIn(){
	document.getElementById('RegForm').action='doLogin.asp';
	document.getElementById('RegForm').submit();
}


function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

function doSubmitReview(){
	
document.getElementById('txtName').value = Trim(document.getElementById('txtName').value)
document.getElementById('txtEmail').value = Trim(document.getElementById('txtEmail').value)

if (document.getElementById('txtName').value.length<3) {alert('Πρέπει να συμπληρώσετε το όνομά σας.'); document.getElementById('txtName').focus(); return}
if (!blnValidEmail(document.getElementById('txtEmail').value)) {alert('Το e-mail σας δεν είναι σωστό.'); document.getElementById('txtEmail').focus(); return}
if (document.getElementById('txtReview').value.length<5) {alert('Πρέπει να συμπληρώσετε το μήνυμά σας.'); document.getElementById('txtReview').focus(); return}



document.getElementById('frmReview').action='/svc/postReview/send.asp'; 
document.getElementById('btnSubmit').disabled=true;
document.getElementById('frmReview').submit();
}

function doSubmitReviewByEntityId(iId){
	
document.getElementById('txtName_' + iId).value = Trim(document.getElementById('txtName_' + iId).value)
document.getElementById('txtEmail_' + iId).value = Trim(document.getElementById('txtEmail_' + iId).value)

if (document.getElementById('txtName_' + iId).value.length<3) {alert('Πρέπει να συμπληρώσετε το όνομά σας.'); document.getElementById('txtName_' + iId).focus(); return}
if (!blnValidEmail(document.getElementById('txtEmail_' + iId).value)) {alert('Το e-mail σας δεν είναι σωστό.'); document.getElementById('txtEmail_' + iId).focus(); return}
if (document.getElementById('txtReview_' + iId).value.length<5) {alert('Πρέπει να συμπληρώσετε το μήνυμά σας.'); document.getElementById('txtReview_' + iId).focus(); return}



document.getElementById('frmReview_' + iId).action='/svc/postReview/send.asp?id=' + iId; 
document.getElementById('btnSubmit_' + iId).disabled=true;
document.getElementById('frmReview_' + iId).submit();
}

function showBigCover(sFileName){
sFileName = 'http://cov.vita.gr/' + sFileName.substr(0,2) + '/' + sFileName + '_b.jpg'

var iWidth=500;
var iHeight=600;
var iLeft = (((window.screen.availWidth-iWidth)/2));
var iTop = (((window.screen.availHeight-iHeight)/2))
if (iTop<30) {iTop=1}
if (iLeft<30) {iLeft=1}

window.open(sFileName, "_blank", 'top=' + iTop + ', left=' + iLeft + ', width=' + iWidth + ', height=' + iHeight + ', location=no, address=no, scrollbars=yes, resizable=yes, status=no')
}