﻿
//disable right click
document.oncontextmenu=new Function("return false")

function openPdfWindow(url) {
	window.open(url, '', 'scrollbars=yes,width=800,height=600', '_blank');
	
}

function showImage(imageName, imageTitle){
		
		document.getElementById("imageHolderId").src = "/images/photos/"+ imageName + "_extended.jpg";
		document.getElementById("imageTitleHolderId").innerText = imageTitle;
		document.getElementById("imageHolderId").title = imageTitle;
		document.getElementById("imageHolderId").alt = imageTitle;
	}

function openPopupWindow(url) {
	window.open(url,'','menubar=no,addressbar,scrollbars,toolbar=no,width=680,height=600');
}	


function openPopupWindowDefinedSize(url, width, height) {
	window.open(url,'',"menubar=no,addressbar,scrollbars,toolbar=no,width="+width+",height="+height+"");
}	
	
function changeTarget(id) {				
	document.getElementById(id).target = "_blank";
}		
	
function changeTargetForPopupWin(id, url) {
	
	var currentUrl = location.href;
	var initHref = document.getElementById(id).href;
	

	//alert(id + " initHref:" + initHref);
	window.open(initHref, '', 'scrollbars=yes,width=800,height=600', '_blank');
//	document.getElementById(id).href = initHref;	
}

//function changeTargetForPopupWin(id, url) {
	
	//	alert("id:" + id + " url:" + document.getElementById(id).href);
	//document.getElementById(id).href = "#";	
	//document.getElementById(id).target = "_blank";
	
	//window.open(document.getElementById(id).href, '', 'scrollbars=yes,width=800,height=600');
//}

function test(ele) {

}


function checkContactFormFields() {




	var contactForm = document.getElementById("contactForm");
	var atLeastOneEmptyField = false;
	var atLeastOneΙnvalidField = false;
	var emptyMessage = "Τα παρακάτω πεδία είναι κενά:\n\n";
	var invalidMessage = "Τα παρακάτω πεδία περιλαμβάνουν μη έγκυρες τιμές:\n\n";
	
	var otherError = false;
	alert("test:");
	
	alert("form:" + contactForm);
	
	alert("firstname:" + contactForm.firstname);
	alert("lastname:" + contactForm.lastname);
	alert("email:" + contactForm.email);
	
	alert("phone:" + contactForm.phone);
	
	
	alert("addess:" + contactForm.address);
	
	alert("number:" + contactForm.number);
	
	alert("city:" + contactForm.city);
	
	alert("postcode:" + contactForm.code);
	
	
	if (IsEmpty(contactForm.firstname)) {
		atLeastOneEmptyField = true;
		emptyMessage +=" Όνομα \n";
	}
	if (IsEmpty(contactForm.lastname)) {
		atLeastOneEmptyField = true;
		emptyMessage +=" Επώνυμο \n";
	}
	if (IsEmpty(contactForm.email)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" E-mail \n";
	} else {
		if (!(isValidEmail(contactForm.email))) {
		atLeastOneΙnvalidField = true;
		invalidMessage += " E-mail\n";
		
		}
	
	}
	
	if (IsEmpty(contactForm.phone)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" Τηλέφωνο \n";
	} else {
		
		if (!(IsNumeric(contactForm.phone))) {
		
			atLeastOneΙnvalidField = true;
			invalidMessage += " Τηλέφωνο \n";
		}
	}
	
	
	
	if (IsEmpty(contactForm.address)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" Οδός \n";
	}
	
	if (IsEmpty(contactForm.number)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" Αριθμός \n";
	} 
	
	
	
	if (IsEmpty(contactForm.city)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" Πόλη \n";
	}
	
	if (IsEmpty(contactForm.code)) {
		atLeastOneEmptyField= true;
		emptyMessage +=" Ταχυδρομικός κώδικας \n";
	}
	
	if (atLeastOneEmptyField && atLeastOneΙnvalidField) {
	
		emptyMessage +="\n" + invalidMessage;
	} if (atLeastOneEmptyField) {
		alert(emptyMessage);
	} else if (atLeastOneΙnvalidField) {
		alert(invalidMessage);
	} else {
		contactForm.submit();
	}	
	
	
	
	
	

}


function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	



function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = strEmail.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
     
      return false;
    } 
    return true; 
}


function IsNumeric(sText) {
	
	sText = sText.value;
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i); 	
      if (ValidChars.indexOf(Char) == -1) {	
         IsNumber = false;
      }
    }
   return IsNumber;   
}


//check ENTER for form so as not to be submitted if the appropriate button is not clicked
function checkEnter(e){ 
 e = e || event; 
 return (e.keyCode || event.which || event.charCode || 0) !== 13; 
} 