﻿var aj = new GLM.AJAX();

function submitReg()
{
	theName = document.getElementById("theName").value;
 	theAddr = document.getElementById("theAddress").value;
	theTk = document.getElementById("theTk").value;
	theCity = document.getElementById("theCity").value;
	theTel = document.getElementById("theTel").value;
	theFax = document.getElementById("theFax").value;
	theManager = document.getElementById("theManager").value;
	theGross = document.getElementById("theGross").value;
	theEmpl = document.getElementById("theEmpl").value;
	theEquip = document.getElementById("theEquip").value;
	theSpec = document.getElementById("theSpec").value;
	theSX = document.getElementById("theSX").value;
	theDT = document.getElementById("theDT").value;
	theM1 = document.getElementById("theM1").value;
	theM2 = document.getElementById("theM2").value;
	eml = document.getElementById("eml").value;
	www = document.getElementById("www").value;
	un  = document.getElementById("un").value;
	pwd = document.getElementById("pwd").value;
	
	if(theName == "" || theAddr == "" || theTk == "" || theTel == "" || theManager == ""  || eml == "" || un == "" || pwd == "")
	{
		jQuery.facebox("Τα πεδία Επωνυμία, Διεύθυνση, ΤΚ, Τηλέφωνο, Υπεύθυνος, email, Username και Password είναι υποχρεωτικά.");
		return;
	}
	
	if(!echeck(eml))
	{
		jQuery.facebox("Το email δεν είναι σωστό.");
		return;
	}
	
	res = aj.callPage("index.php", "", "POST", "event=UNPWDEMAIL&un="+un+"&pwd="+pwd+"&eml="+eml)
	if(res != "")
	{
		jQuery.facebox(res);
		return;
	}	
	
	if(pwd.length < 5)
	{
		jQuery.facebox("Πολύ μικρό Password. Παρακαλώ εισάγετε ένα μεγαλύτερο.");
		return;
	}
	
	hasNum = 0
	for(i=0;i<pwd.length;i++)
	{
		ch = pwd.substring(i,i+1);
		if(isNumeric(ch))
			hasNum = 1;
	}
	
	if(hasNum == 0)
	{
		jQuery.facebox("To Password θα πρέπει να περιέχει και αριθμούς.");
		return;
	}
	
	form = "event=REG&theName="+theName+"&theAddr="+theAddr+"&theTk="+theTk+"&theCity="+theCity+"&theTel="+theTel+"&theFax="+theFax+"&theManager="+theManager+"&theGross="+theGross+"&theEmpl="+theEmpl+"&theEquip="+theEquip+"&theSpec="+theSpec+"&theSX="+theSX+"&theDT="+theDT+"&theM1="+theM1+"&theM2="+theM2+"&eml="+eml+"&www="+www+"&un="+un+"&pwd="+pwd;
	//jQuery.facebox(form);
	//alert(form);
	res = aj.callPage("index.php", "", "POST", form);
	jQuery.facebox(res);
}

function clearReg()
{
	document.getElementById("theName").value="";
	document.getElementById("theAddress").value="";
	document.getElementById("theTk").value="";
	document.getElementById("theCity").value="";
	document.getElementById("theTel").value="";
	document.getElementById("theFax").value="";
	document.getElementById("theManager").value="";
	document.getElementById("theGross").value="";
	document.getElementById("theEmpl").value="";
	document.getElementById("theEquip").value="";
	document.getElementById("theSpec").value="";
	document.getElementById("theSX").value="";
	document.getElementById("theDT").value="";
	document.getElementById("theM1").value="";
	document.getElementById("theM2").value="";
	document.getElementById("eml").value="";
	document.getElementById("www").value="";
	document.getElementById("pwd").value="";
	document.getElementById("un").value="";
}

function showblogbyUID(uid)
{
	res = aj.callPage("index.php", "", "POST", "event=BLOGBYUID&uid="+uid);
	document.getElementById("theblog").innerHTML = res;
}

function showblogbycateg(cid)
{
	document.getElementById("selectedCateg").value = cid;
	res = aj.callPage("index.php", "", "POST", "event=BLOG&id="+cid);
	document.getElementById("theblog").innerHTML = res;
}

function submitComment(bid)
{
	text = document.getElementById("commentTA").value;
	
	if(text == "")
	{
		jQuery.facebox("Πρέπει να εισάγετε κείμενο.");
		return;
	}	
	
	res = aj.callPage("index.php", "", "POST", "event=BLOGCOMMENT&bid="+bid+"&text="+text);
	jQuery.facebox(res);
	//window.location = "index.php";
}

function logmeout()
{
	res = aj.callPage("index.php", "", "POST", "event=LOGOUT");
	window.location = "index.php";
	//jQuery.facebox(res);
}


function logmein()
{
	un = document.getElementById("unf").value;
	pwd = document.getElementById("pwdf").value;
	
	res = aj.callPage("index.php", "", "POST", "event=LOGIN&un="+un+"&pwd="+pwd);
	//jQuery.facebox(res);
	window.location = "index.php";
}

function goto()
{
	window.location = "index.php";
}

function authFail()
{
	jQuery.facebox("<div class='textbody'>Πρέπει να είστε μέλος και να έχετε κάνει login για να έχετε πρόσβαση σ' αυτή την ενότητα.</div>");
	//window.location = "index.php";
}

function submitBlogEntry()
{
	bcategid = document.getElementById("categselect").value;
	btitle = document.getElementById("entryTitle").value;
	btext = document.getElementById("entryText").value;
	
	if(bcategid == "0")
	{
		jQuery.facebox("Πρέπει να επιλέξετε Κατηγορία");
		return;
	}	
	if(btitle == "")
	{
		jQuery.facebox("Πρέπει να εισάγετε Τίτλο");
		return;
	}
	if(btext == "")
	{
		jQuery.facebox("Πρέπει να εισάγετε Κείμενο");
		return;
	}
	
	res = aj.callPage("index.php", "", "POST", "event=NEWBLOG&categ="+bcategid+"&title="+btitle+"&text="+btext);
	jQuery.facebox(res);
}

function newBlogEntry(id)
{
	document.getElementById("theblog").innerHTML = newblogForm;
	cid = document.getElementById("selectedCateg").value;
	
	document.getElementById("categselect").value = cid;
}

function shownewsbycateg(cid)
{
	res = aj.callPage("index.php", setNewsByCateg, "POST", "event=NEWS&id="+cid);
	document.getElementById("thenews").innerHTML = res;
}

function setNewsByCateg(response)
{  ///alert(response);
	//document.getElementById("thenews").innerHTML = response;
}

function onmenu(lev, obj, on, childID, tableID)
{
	hasChild = true;
	if(childID == "-1")
		hasChild = false;
	
   imgID = "imgtext" + tableID;
	childID = "ch_" + childID;
	
	
	if(lev == 0)
	{
		if(on == 0)
		{
			imgsrc = document.getElementById(imgID).src;
			imgtype = imgsrc.substring(imgsrc.length - 4, imgsrc.length);
			imgsrc = imgsrc.substring(0, imgsrc.length - 6);
			newImgSrc = imgsrc + imgtype;
			
			document.getElementById(imgID).src = newImgSrc;
			
			if(hasChild)
				document.getElementById(childID).className = "subMenuDiv";
		}	
		else
		{
		   imgsrc = document.getElementById(imgID).src;
			imgtype = imgsrc.substring(imgsrc.length - 4, imgsrc.length);
			imgsrc = imgsrc.substring(0, imgsrc.length - 4);
			
			pf = hasChild?"ON":"O2";
			newImgSrc = imgsrc + pf + imgtype;
			
			document.getElementById(imgID).src = newImgSrc;
			
			if(hasChild)
				document.getElementById(childID).className = "subMenuDivOn";
		}	
	}
	else
	{
		if(on == 0)
		{
		
		}	
		else
		{
					
		}	
	}
}

function showThis(id)
{
	document.getElementById(id).className="subMenuTableON";
}

function contactForm()
{
	var mail = document.getElementById("theEmail").value;
	var mes  = document.getElementById("theMes").value;
	var name  = document.getElementById("yourname").value;
	var compName = document.getElementById("compName").value;
	var subj = document.getElementById("subj").value;
	
	if(mail == "" || mes== "")
	{
		jQuery.facebox("Ολα τα πεδία που συνοδεύονται από * είναι υποχρεωτικά");
		return;
	}
	
	res = aj.callPage("index.php", getSec, "POST", "id=CSN&mail="+mail+"&mes="+mes+"&name="+name+"&subj="+subj+"&compName="+compName);
	jQuery.facebox(res);
}

function getSec(response)
{

}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {//alert(document);
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
			//var imgUsemap = (img.usemap)?" usemap='" + img.usemap + "'":"";  
			//alert(img.usemap);
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\');\"></span>" 
            img.outerHTML = strNewHTML;
            i = i-1;
			//if(imgName == "FOOTERCORNERLEFT.PNG")
				//alert(strNewHTML);
         }
      }
   }    
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
