﻿function ModulePrintPage() {
  lochref = '' + this.location;
	if (lochref.indexOf('?') > 0) {
		lochref = '?' + lochref.substring((lochref.indexOf('?')) + 1);
	} else {
		lochref = '';
	}

	w_width = 790;
	w_height = 500;
	if (screen) {
		w_left = (screen.availWidth - w_width)/2;
		w_top = ((screen.availHeight - w_height)/2)-20;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=no,scrollbars=yes';

	fparam = 'print_mod.php'+lochref;
  window.showPrintWindow = open(fparam, 'showPrintWindow', theWindowParam);
	setTimeout('if(showPrintWindow&&!showPrintWindow.closed)showPrintWindow.focus()',100);
}

function VerifyItemPurchasing(theCredits,theUrl)
{
	if (window.confirm('Για να αποκτήσετε πρόσβαση θα σας αφαιρεθούν ' +theCredits+ 'βαθμοί. Θέλετε να συνεχίσετε;')) {
		actionFileAndParams = theUrl;
		location.replace(actionFileAndParams);
	}
}


function ValidateForgotPasswordForm(theForm) {
  var email = theForm.email.value;
	
	if (!email) {
		alert("Πρέπει να γράψετε το email σας.");
		return false;
	} else if ((email.indexOf('@') == -1) || (email.indexOf('.') == -1)) {
		alert("Λανθασμένος τύπος email.");
		return false;
	} else {
		return true;
	}
}

function ValidateRepLoginForm(theForm) {
  var username = theForm.usr_log_username.value;
  var password = theForm.usr_log_password.value;
	
	if (!username) {
		alert("Πρέπει να γράψετε το Όνομα Χρήστη.");
		return false;
	} else if (!password) {
			alert("Πρέπει να γράψετε τον Κωδικό Πρόσβασης.");
			return false;
	} else {
		return true;
	}
}

function ValidateArticlesSearchBlock(theForm){
	
	var date_from = theForm.art_fdate.value;
	var date_to = theForm.art_tdate.value;
	
	var split_date_from = date_from.split(".");
	var from_dd = parseInt(split_date_from[0], 10);
  	var from_mm = parseInt(split_date_from[1], 10);
  	var from_yy = parseInt(split_date_from[2], 10);

	var split_date_to = date_to.split(".");
	var to_dd = parseInt(split_date_to[0], 10);
 	var to_mm = parseInt(split_date_to[1], 10);
  	var to_yy = parseInt(split_date_to[2], 10);

	var fromdate1 = new Date(from_yy,(from_mm-1),from_dd);
	var todate1 = new Date(to_yy,(to_mm-1),to_dd);
	
	var today = new Date();	

	fromdate=from_dd+from_mm+from_yy;
	todate=to_dd+to_mm+to_yy;

	if (((from_dd != fromdate1.getDate()) || (from_mm != fromdate1.getMonth()+1) || (from_yy != fromdate1.getFullYear())) && (date_from != '') ) {
		alert("Η ημερομηνία 'Απο' είναι λανθασμένη.");
		return false;
	} else if ( ((to_dd != todate1.getDate()) || (to_mm != todate1.getMonth()+1) || (to_yy != todate1.getFullYear())) && (date_to != '') ) {
		alert("Η ημερομηνία 'Μέχρι' είναι λανθασμένη.");
		return false;
	} else if (((fromdate1 > todate1) && (todate != '')) /*|| (fromdate == todate)*/) {
		alert("Η ημερομηνία 'Από' πρέπει να είναι πρίν απο την ημερομηνία 'Μέχρι'.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Usr_General(theForm) {
  var usr_fname = theForm.usr_fname.value;
  var usr_lname = theForm.usr_lname.value;
  var usr_nickname = theForm.usr_nickname.value;
  var usr_email = theForm.usr_email.value;
  var usr_log_username = theForm.usr_log_username.value;
  var usr_log_password = theForm.usr_log_password.value;
  var verifyusr_log_password = theForm.verifyusr_log_password.value;
	
	if (!usr_fname) {
		alert("Πρέπει να γράψετε το Όνομα σας.");
		return false;
	} else if (!usr_lname) {
		alert("Πρέπει να γράψετε το Επώνυμο σας.");
		return false;
	} else if (!usr_nickname) {
		alert("Πρέπει να γράψετε το Ψευδώνυμο σας.");
		return false;
	} else if (!usr_email) {
		alert("Πρέπει να γράψετε το Email σας.");
		return false;
	} else if ((usr_email.indexOf('@') == -1) || (usr_email.indexOf('.') == -1)) {
		alert("Λανθασμένος τύπος Email.");
		return false;
	} else if (!usr_log_username) {
		alert("Πρέπει να γράψετε το Όνομα Χρήστη.");
		return false;
	} else if ((usr_log_username.length < 4) && (usr_log_username != ' ')) {
		alert("Το Όνομα Χρήστη πρέπει να είναι τουλάχιστο 4 χαρακτήρες.");
		return false;
	} else if (!usr_log_password) {
		alert("Πρέπει να γράψετε τον Κωδικό Πρόσβασης.");
		return false;
	} else if ((usr_log_password.length < 4) && (usr_log_password != ' ')) {
		alert("Ο Κωδικός Πρόσβασης πρέπει να είναι τουλάχιστο 4 χαρακτήρες.");
		return false;
	} else if ((usr_log_password.indexOf(' ') != -1) && (usr_log_password != ' ')) {
		alert("Λανθασμένος τύπος Κωδικού Πρόσβασης.");
		return false;
	} else if (usr_log_password != verifyusr_log_password) {
		alert("Ο Κωδικός Πρόσβασης δεν είναι ο ίδιος με την Επαλήθευση του.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Art_General(theForm, theShowAllCatFilFlag) {
	var cat_id;
	if (theShowAllCatFilFlag == 'Y') {
		cat_id = theForm.cat_id.options[theForm.cat_id.selectedIndex].value;
	} else {
		cat_id = theForm.cat_id.value;
	}
  var art_title = theForm.art_title.value;

	if (!art_title) {
		alert("Πρέπει να γράψετε τον Τίτλο.");
		return false;
	} else if (!cat_id) {
		alert("Πρέπει να επιλέξετε Κατηγορία.");
		return false;
	} else {
		return true;
	}
}

function ValidateMemLoginForm(theForm) {
  var username = theForm.mem_log_username.value;
  var password = theForm.mem_log_password.value;
	
	if (!username) {
		alert("Πρέπει να γράψετε το Όνομα Χρήστη.");
		return false;
	} else if (!password) {
			alert("Πρέπει να γράψετε τον Κωδικό Πρόσβασης.");
			return false;
	} else {
		return true;
	}
}

function ValidateForm_Mem_General(theForm) {
  var mem_fname = theForm.mem_fname.value;
  var mem_lname = theForm.mem_lname.value;
  var mem_nickname = theForm.mem_nickname.value;
  //var mem_mobile_phone = theForm.mem_mobile_phone.value;
  var mem_email = theForm.mem_email.value;
  var mem_log_username = theForm.mem_log_username.value;
  var mem_log_password = theForm.mem_log_password.value;
  var verifymem_log_password = theForm.verifymem_log_password.value;
	
	if (!mem_fname) {
		alert("Πρέπει να γράψετε το Όνομα σας.");
		return false;
	} else if (!mem_lname) {
		alert("Πρέπει να γράψετε το Επώνυμο σας.");
		return false;
	} else if (!mem_nickname) {
		alert("Πρέπει να γράψετε το Ψευδώνυμο σας.");
		return false;
	} else if (!mem_log_username) {
		alert("Πρέπει να γράψετε το Όνομα Χρήστη.");
		return false;
	} else if ((mem_log_username.length < 4) && (mem_log_username != ' ')) {
		alert("Το Όνομα Χρήστη πρέπει να είναι τουλάχιστο 4 χαρακτήρες.");
		return false;
	} else if (!mem_log_password) {
		alert("Πρέπει να γράψετε τον Κωδικό Πρόσβασης.");
		return false;
	} else if ((mem_log_password.length < 4) && (mem_log_password != ' ')) {
		alert("Ο Κωδικός Πρόσβασης πρέπει να είναι τουλάχιστο 4 χαρακτήρες.");
		return false;
	} else if ((mem_log_password.indexOf(' ') != -1) && (mem_log_password != ' ')) {
		alert("Λανθασμένος τύπος Κωδικού Πρόσβασης.");
		return false;
	} else if (mem_log_password != verifymem_log_password) {
		alert("Ο Κωδικός Πρόσβασης δεν είναι ο ίδιος με την Επαλήθευση του.");
		return false;
	//} else if (!mem_mobile_phone) {
	//	alert("Πρέπει να γράψετε τον Αριθμό του κινητού σας.");
	//	return false;
	} else if (!mem_email) {
		alert("Πρέπει να γράψετε το Email σας.");
		return false;
	} else if ((mem_email.indexOf('@') == -1) || (mem_email.indexOf('.') == -1)) {
		alert("Λανθασμένος τύπος Email.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Mem_RegCredits(theForm) {
  var smscode = theForm.smscode.value;
	
	if (!smscode) {
		alert("Πρέπει να γράψετε το Κωδικό που λάβατε μέσω SMS.");
		return false;
	} else {
		return true;
	}
}


function goToFindArticle(theform) {
  var ArtCategory = theform.cat_id.value;
  var ArtContains = theform.art_contains.value;
  var ArtFromDateParam = theform.art_fdate.value;
  var ArtToDateParam = theform.art_tdate.value;
  
  var SplitArtFromDate = ArtFromDateParam.split(".");
  var SplitArtToDate = ArtToDateParam.split(".");
  
  var ArtFromDate = ''; 
  var ArtToDate = ''; 
  
  if (ArtFromDateParam != '') {
	  ArtFromDate = SplitArtFromDate[2]+'-'+SplitArtFromDate[1]+'-'+SplitArtFromDate[0];
  }
  if (ArtToDateParam != '') {
	  ArtToDate = SplitArtToDate[2]+'-'+SplitArtToDate[1]+'-'+SplitArtToDate[0];
  }
  
  lochref = 'index.php?pageaction=ast&modid=SearchArticles&criteria=set';

	if (ArtCategory != '') {	lochref += '&catid=' + ArtCategory; }
	if (ArtContains != '') {	lochref += '&contains=' + ArtContains; }
	if (ArtFromDate != '') {	lochref += '&fdate=' + ArtFromDate; }
	if (ArtToDate != '') {	lochref += '&tdate=' + ArtToDate; }

	location = lochref;
}


function uploadAsset(theSection, theFolder, theId, theReturnURL) {
	w_width = 570;
	w_height = 150;
	if (screen) {
		w_left = (screen.availWidth - w_width)/2;
		w_top = ((screen.availHeight - w_height)/2)-20;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=no,scrollbars=yes';
	
	fparam = 'admin/modules/ws_mod_ast_01/tools/upload_file.php?section='+theSection+'&folder='+theFolder+'&id='+theId+'&returnurl='+theReturnURL;
  window.uploadAssetWindow = open(fparam, 'uploadAssetWindow', theWindowParam);
	setTimeout('if(uploadAssetWindow&&!uploadAssetWindow.closed)uploadAssetWindow.focus()',100);
}

var browser = new checkBrowser();
var preloadInterval ="";

function checkBrowser() {
   var userAgent = navigator.userAgent.toLowerCase()
   this.isIE = (userAgent.indexOf('msie') != -1);
   this.isGecko = (userAgent.indexOf('gecko') != -1 && userAgent.indexOf('safari') == -1);
   this.isOpera = (userAgent.indexOf('opera') != -1)
   this.isRTECompatible= (this.isIE || this.isGecko);
}

function preloadImage(ImageID) {
// ---------------------------------------------------------------------------------------------------
// preloadImage([id of an img tag])
// ---------------------------------------------------------------------------------------------------
// This function can be used in the previewArea only!
// It tests if the download of an image is complete. On positive result it:
//  - displays the image by changing its display properties
//  - changes the size of large images
//  - removes its own interval
//
// Usage example:
// if(preloadInterval!="") clearInterval(preloadInterval);            // remove possible old interval
// preloadInterval = setInterval("preloadImage('"+ImageID+"')",100);  // start this function in an interval

//settings for height and width according to source of functioncall
var ImgWidth = 190;
var ImgHeight= 190;
//if(Caller == 1)
//{
//ImgWidth = 200;
//ImgHeight = 200;
//}


  if(document.getElementById(ImageID).complete) {                     // do nothing while the image is not uploaded yet

// create dummy image to get (non-cached) image width & height
    testImage=document.createElement("img");
    testImage.src=document.getElementById(ImageID).src;

    percent = 100;
    if(testImage.width != 0) {                                        // do nothing while the width is unset
      document.getElementById(ImageID).style.display="block";
      if(testImage.width> ImgWidth || testImage.height> ImgHeight) {
// resize large images
        horPercent = 100*ImgWidth/testImage.width;
        verPercent = 100*ImgHeight/testImage.height;
        if(horPercent > verPercent) {
            document.getElementById(ImageID).height =ImgHeight;
            document.getElementById(ImageID).width =testImage.width * verPercent / 100;
            percent = verPercent;
        }  else {
            document.getElementById(ImageID).width =ImgWidth;
            document.getElementById(ImageID).height =testImage.height * horPercent / 100;
            percent = horPercent;
        }
      } else {
// reset image sizes for 1:1 Images
        document.getElementById(ImageID).width = testImage.width;
        document.getElementById(ImageID).height = testImage.height;
      }
// calculate new postion
      newMarginLeft = document.getElementById(ImageID).width/2;
      newMarginTop = document.getElementById(ImageID).height/2;

      if (!browser.isOpera)
      {
        document.getElementById(ImageID).style.left="50%";
        document.getElementById(ImageID).style.top="50%";
        document.getElementById(ImageID).style.marginLeft="-"+newMarginLeft+"px";
        document.getElementById(ImageID).style.marginTop="-"+newMarginTop +"px";
      }
      else
      {
        document.getElementById(ImageID).style.margin='auto';
      }

      newTextnode= document.createTextNode("("+Math.floor(percent)+"%)");
      document.getElementById("Percentage").replaceChild(newTextnode, document.getElementById("Percentage").firstChild);
      document.getElementById("Loading").style.display="none";
      document.getElementById("Percentage").style.display="inline";
      clearInterval(preloadInterval);
    }
  }
}

function preloadImage_Gal(ImageID) {
// ---------------------------------------------------------------------------------------------------
// preloadImage([id of an img tag])
// ---------------------------------------------------------------------------------------------------
// This function can be used in the previewArea only!
// It tests if the download of an image is complete. On positive result it:
//  - displays the image by changing its display properties
//  - changes the size of large images
//  - removes its own interval
//
// Usage example:
// if(preloadInterval!="") clearInterval(preloadInterval);            // remove possible old interval
// preloadInterval = setInterval("preloadImage('"+ImageID+"')",100);  // start this function in an interval

//settings for height and width according to source of functioncall
var ImgWidth = 190;
var ImgHeight= 190;
//if(Caller == 1)
//{
//ImgWidth = 200;
//ImgHeight = 200;
//}


  if(document.getElementById(ImageID).complete) {                     // do nothing while the image is not uploaded yet

// create dummy image to get (non-cached) image width & height
    testImage=document.createElement("img");
    testImage.src=document.getElementById(ImageID).src;

    percent = 100;
    if(testImage.width != 0) {                                        // do nothing while the width is unset
      document.getElementById(ImageID).style.display="block";
      if(testImage.width> ImgWidth || testImage.height> ImgHeight) {
// resize large images
        horPercent = 100*ImgWidth/testImage.width;
        verPercent = 100*ImgHeight/testImage.height;
        if(horPercent > verPercent) {
            document.getElementById(ImageID).height =ImgHeight;
            document.getElementById(ImageID).width =testImage.width * verPercent / 100;
            percent = verPercent;
        }  else {
            document.getElementById(ImageID).width =ImgWidth;
            document.getElementById(ImageID).height =testImage.height * horPercent / 100;
            percent = horPercent;
        }
      } else {
// reset image sizes for 1:1 Images
        document.getElementById(ImageID).width = testImage.width;
        document.getElementById(ImageID).height = testImage.height;
      }
// calculate new postion
      newMarginLeft = document.getElementById(ImageID).width/2;
      newMarginTop = document.getElementById(ImageID).height/2;

      if (!browser.isOpera)
      {
        document.getElementById(ImageID).style.left="50%";
        document.getElementById(ImageID).style.top="50%";
        document.getElementById(ImageID).style.marginLeft="-"+newMarginLeft+"px";
        document.getElementById(ImageID).style.marginTop="-"+newMarginTop +"px";
      }
      else
      {
        document.getElementById(ImageID).style.margin='auto';
      }

      newTextnode= document.createTextNode("("+Math.floor(percent)+"%)");
      document.getElementById("Percentage_Gal").replaceChild(newTextnode, document.getElementById("Percentage_Gal").firstChild);
      document.getElementById("Loading_Gal").style.display="none";
      document.getElementById("Percentage_Gal").style.display="inline";
      clearInterval(preloadInterval);
    }
  }
}

function changePreviewImage_Gal(ImageID, ImageURL, ImageTitle) {
// changes the PreviewImage in the PreviewArea and starts the image preloader
  changeImage(ImageID, ImageURL, ImageTitle);
  document.getElementById(ImageID).style.display="none";      // hide preview image while loading
  document.getElementById("Loading_Gal").style.display="inline";  // display Loading info
  document.getElementById("Percentage_Gal").style.display="none"; // hide image size while loading

  if(preloadInterval!="") clearInterval(preloadInterval);
  preloadInterval = setInterval("preloadImage_Gal('"+ImageID+"')",100);
}

function changePreviewImage(ImageID, ImageURL, ImageTitle) {
// changes the PreviewImage in the PreviewArea and starts the image preloader
  changeImage(ImageID, ImageURL, ImageTitle);
  document.getElementById(ImageID).style.display="none";      // hide preview image while loading
  document.getElementById("Loading").style.display="inline";  // display Loading info
  document.getElementById("Percentage").style.display="none"; // hide image size while loading

  if(preloadInterval!="") clearInterval(preloadInterval);
  preloadInterval = setInterval("preloadImage('"+ImageID+"')",100);
}

function changeImage(ImageID, ImageURL, ImageTitle) {
// changes the image url & title of an image element (specified by its id attribute)
  theTmpInterval = setInterval("document.getElementById('"+ImageID+"').src = '"+ImageURL+"';", 0);   // display image
//  document.getElementById(ImageID).src = ImageURL;
  if (ImageTitle) {
    document.getElementById(ImageID).alt = ImageTitle;
  }
}

function ShowImageNormalSize(theImage) {
	w_width = 100;
	w_height = 100;
	if (screen) {
		w_left = 10;
		w_top = 10;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=yes,scrollbars=yes';
	
	fparam = 'admin/modules/ws_mod_ast_01/tools/show_normal_size.php?img=' + theImage;
  window.ShowImageNormalSizeWindow = open(fparam, 'ShowImageNormalSizeWindow', theWindowParam);
	setTimeout('if(ShowImageNormalSizeWindow&&!ShowImageNormalSizeWindow.closed)ShowImageNormalSizeWindow.focus()',100);
}

function showArticlePhotoGallery(theId, theLang) {
	w_width = 700;
	w_height = 620;
	if (screen) {
		w_left = (screen.availWidth - w_width)/2;
		w_top = ((screen.availHeight - w_height)/2)-20;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=yes,scrollbars=yes';

	fparam = 'modules/ws_mod_ast_01/article_detail/showphotogallery.php?pageid=' + theId + '&lang=' + theLang;
  window.photoGalleryWindow = open(fparam, 'photoGalleryWindow', theWindowParam);
	setTimeout('if(photoGalleryWindow&&!photoGalleryWindow.closed)photoGalleryWindow.focus()',100);
}

function GoToArticlesPage(select, theCurrentPage, theQueryString) {

	var thePageNum = select.options[select.selectedIndex].value;
	theNewPageUrl = theCurrentPage+"?pageNum_rs_ws_mod_ast_category_articles="+thePageNum+theQueryString;
	location.replace(theNewPageUrl);
	
}

function GoToSearchArticlesPage(select, theCurrentPage, theQueryString) {

	var thePageNum = select.options[select.selectedIndex].value;
	theNewPageUrl = theCurrentPage+"?pageNum_rs_ws_mod_ast_search_articles="+thePageNum+theQueryString;
	location.replace(theNewPageUrl);
	
}

function GoToReporterArticlesPage(select, theCurrentPage, theQueryString) {

	var thePageNum = select.options[select.selectedIndex].value;
	theNewPageUrl = theCurrentPage+"&pageNum_rs_ws_mod_ast_articles="+thePageNum+theQueryString;
	location.replace(theNewPageUrl);
	
}