var noteCal_1;
var noteCal_2;
var browserName = navigator.appName;
var device="pc";
var interval  = 0;	//window interval. Used by onGetMessage() for flashing the button.
var interval2 = 0;	//used for flashing the window title
var interval3 = 0;	//used for blinking private chat icons
var winHasFocus = false;
var usrForWhisper = ""; //stores the receiver's username of our private message.
var chart;//global chart variabele. Holds the charts in htmltable

/***********************************GMAPS*************************/
var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        
      }
    }
    
    function setDirections(fromAddress, toAddress, locale) {

    	if (jQuery("#directionstable").css('display')=="none")
    		jQuery("#directionstable").css('display',"");
    	else{
    		jQuery("#directionstable").css('display',"none");
    		return;
    	}
    	locale = document.getElementById('platonLanguage').getAttribute('lang');
    	if (toAddress.length<3){
    		alert(getMessage(99));
    	}
    	initialize();
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
                
    }
    function handleErrors(){
    	alert(getMessage(99));
	   /*if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");*/
	   
	}
	function onGDirectionsLoad(){ 
		var dir = gdir.getRoute(0).getNumSteps();
		var rout = gdir.getRoute(0);
		for(var i=0;i<dir;i++){
			//alert( rout.getStep(i).getDescriptionHtml());
		}
		
      // Use this function to access information about the latest load()
      // results.
      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	
	
	/********************************************************/
jQuery(document).ready(function() {
	var arefs=jQuery('.imgtoLighBox');
	for(var i=0; i<arefs.length; i++){
		var idi=arefs[i].id;
		jQuery('#'+idi).lightBox();
	}
});
// IE
document.onfocusin = focusHandler;	//it's better to assing it to document
document.onfocusout = blurHandler;

// FF, Saf, Op
if (document.addEventListener) {
	document.addEventListener('focus',focusHandler,true);
	document.addEventListener('blur',blurHandler,true);
}

/*function vitaTest() {
	var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+
					"<elements>"+
					"<actor>"+document.getElementById('thisActorCode').value+"</actor>"+
					"<unit>"+document.getElementById('unit').value+"</unit>"+
					"<pageAction>importProducts</pageAction>"+
					"<action>importProducts</action>";
					//"<message>"+message+"</message>";
					
	xmlString += "</elements>";
	
	xmlString=xmlString.replace(/&/g,'&amp;');
	
	var loader1 = new net.sendThis("main",this.onVitaTest,null,this,null, "POST",xmlString,"text/xml");
	
}

function onVitaTest() {
	alert("callback onVitaTest");
}*/

/*
jQuery(window).blur(function() { winHasFocus = false;} );
jQuery(window).focus(function() {
	winHasFocus = true;
	interval2 = window.clearInterval(interval2);	//stop flashing title
	interval2 = 0;
	var title = document.title;
	if (title.indexOf(" - New chat message!") > -1)
		document.title = title.substring(0, title.indexOf(" - New chat message!")); //index of newMsg
});
*/
function focusHandler () {
	winHasFocus = true;
	interval2 = window.clearInterval(interval2);	//stop flashing title
	interval2 = 0;
	var title = document.title;
	if (title.indexOf(" - New chat message!") > -1)
		document.title = title.substring(0, title.indexOf(" - New chat message!")); //index of newMsg
}

function blurHandler () {
	winHasFocus = false;
}

String.prototype.endsWith = function(str){
	return (this.match(str+"$")==str);
}

//for jQuery selector: converts special characters to escaped
function jQid(id){
	//var symbols=["#", ";", "&", ",", ".", "+", "*", "~", ":", "!", "^", "$", "[", "]", "(", ")", "=", ">", "|", "/", "\""];
	return id.replace(/\./g,'\\\.');
}
//normalize astrign for post usage
function norm(str){
	if(str==null)
		return "";
	str=str.replace(/&/g,'&amp;');
	str=str.replace(/"/g,'&quot;');
	str=str.replace(/</g,'&lt;');
	str=str.replace(/>/g,'&gt;');
	return str;
}
//normalize astring for url usage
function hexnorm(str){
	if(str==null)
		return "";
	str=str.replace(/&/g,'%26');
	str=str.replace(/"/g,'%22');
	str=str.replace(/</g,'%3C');
	str=str.replace(/>/g,'%3E');
	str=str.replace(/\+/g,'%2B');
	return str;
}

function showOrous(){
	if (document.getElementById('oroiTr').style.display=='none')
		jQuery('#oroiTr').css('display','');
	else
		jQuery('#oroiTr').css('display','none');
}

function validateFieldId(inpId, type){
	var inp=document.getElementById(inpId);
	validateField(inp, type);
}

function validateField(inp, type){
	var inpId=inp.id;
	var value=inp.value;
	var actor=document.getElementById('thisActorCode').value;
	var unit=document.getElementById('unit').value;
	if(type=="DATE" || type=="TIME"){
		var xmlString="<elements>"+
						"<actor>"+actor+"</actor>"+
						"<unit>"+unit+"</unit>"+
						"<inputId>"+inpId+"</inputId>"+
						"<action>getDateTimeFixed</action>"+
						"<pageAction>s_checkDateTime</pageAction>"+
						"<datetime>"+value+"</datetime>"+
						"<mode>"+type+"</mode>"+
						"</elements>";
		xmlString=xmlString.replace(/&/g,'&amp;');
		var check_loader = new  net.send("main",onValidateField,null,"POST",xmlString,"text/xml");
		return;
	}else if(type=="NUMBER" || type=="DOUBLE"){
		check(inp);
	}else if(type=="CURRENCY"){
		checkCurrency(inp);
	}else if(type=="LONG" || type=="INTEGER"){
		checkNodecimal(inp);
	}else if(type=="LIST" || type=="RECDIS"){
		if(inp.getAttribute('state')!='1'){
			return;
		}
		if(inp.value!=""){
			if(inp.getAttribute('hasCode')=="true"){
				if(value!="" && jQuery(inp).attr('code')!=""){
					value=inp.getAttribute('code');
				}
			}
			var dcomp=inp.getAttribute('formDataComponent');
			if(!dcomp || dcomp=="null"){
				dcomp=inp.getAttribute('dataComponent');
			}
			var xmlString="<elements>"+
							"<actor>"+actor+"</actor>"+
							"<unit>"+unit+"</unit>"+
							"<inputId>"+inpId+"</inputId>"+
							"<action>checkList</action>"+
							"<pageAction>s_checkList</pageAction>"+
							"<value>"+norm(value)+"</value>"+
							"<dataComponent>"+dcomp+"</dataComponent>"+
							"<field>"+inp.getAttribute('datafield')+"</field>"+
							"</elements>";
			var check_loader = new  net.send("main",onValidateField,null,"POST",xmlString,"text/xml");
			return;
		}
	}
	if(inp.getAttribute('post')=="true"){
		postAction(inpId);
	}else{
		//checkDflt(inp, true); //not used pros to paron
		jQuery(inp).trigger("valueChangedEvent");
	}
}

function onValidateField(){
	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	if(status[0].firstChild.nodeValue=='0'){
		var inputId = doc.getElementsByTagName("inputId")[0].firstChild.nodeValue;
		var inp=document.getElementById(inputId);
		if(doc.getElementsByTagName("value")[0].firstChild!=null){
			inp.value=doc.getElementsByTagName("value")[0].firstChild.nodeValue;
			if(inp.getAttribute('hasCode')=="true"){
				inp.setAttribute('code', doc.getElementsByTagName("code")[0].firstChild.nodeValue);
			}
		}else{
			inp.value="";
			if(inp.getAttribute('hasCode')=="true"){
				inp.setAttribute('code', "");
			}
		}
		if(inp.getAttribute('post')=="true"){
			postAction(inputId);
		}else{
			//checkDflt(inp, true); //not used pros to paron
			jQuery(inp).trigger("valueChangedEvent");
		}
	}else if(status[0].firstChild.nodeValue=='-1'){
		alert(message[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-4'){
	}
}

function check(t){
	var numb = "0123456789,.-";
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (numb.indexOf(x,0) != -1)
			w += x;
	}
	t.value = w;
}

//prepei na elegxei gia morfi currency ###.00
//pros to paron einai to idio me tous arithmous
function checkCurrency(t){
	var numb = "0123456789.,-";
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (numb.indexOf(x,0) != -1)
			w += x;
	}
	t.value = w;
}
//elegxos gia akeraious arithmous
function checkNodecimal(t){
	var numb = "0123456789-";
	var oper = ",.";
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (numb.indexOf(x,0) != -1)
			w += x;
		if(oper.indexOf(x,0)!=-1){
			break;
		}
	}
	t.value = w;
}

function getCommunicationForm(){
	var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+
		"<elements>"+
		"<actor>"+document.getElementById('thisActorCode').value+"</actor>"+
		"<unit>"+document.getElementById('unit').value+"</unit>"+
		"<pageAction>getCommunicationForm</pageAction>"+
		"<action>getCommunicationForm</action>"+
		"</elements>";
		xmlString=xmlString.replace(/&/g,'&amp;');
		var loader1 = new  net.sendThis("main",this.onGetCommunicationForm,null,this,null, "POST",xmlString,"text/xml");
}

function onGetCommunicationForm(){
	var doc=this.req.responseXML;
	var content=doc.getElementsByTagName("content");
	if (content.length!=0)
		content = content[0].firstChild.nodeValue;
	var status=doc.getElementsByTagName("status")[0].firstChild.nodeValue;
	var message = doc.getElementsByTagName("message");
	if(content.length!=0){
		var contentWin=new Window({id: "main_communication_div", className: 'alphacube', title: getMessage(25), hideEffect:Element.hide, showEffect:Element.show, minimizable:false,maximizable:false, resizable:false, wiredDrag: true, destroyOnClose: true, width:300, height:320, modal:true});
		contentWin.setHTMLContent(content);
		contentWin.showCenter();
		return;
	}
	alert(message[0].firstChild.nodeValue);
	
}

function sendCommunicationForm(id){
				if (id==null)
					id = "section";
				else {
					id = id.getAttribute('parentid');
				}
				var message = "";
				var name = "";
				var lastname = "";
				var email = "";
				var phone = "";
				var fullname = "";
				var company = "";
				var ins = jQuery("#"+id).find("input");

				for (var i=0;i<ins.length;i++){
					if (ins[i].value != "" && ins[i].getAttribute('type') == "text"){
						message += ins[i].value+":";
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "firstname"){
						name = ins[i].value;
						}
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "lastname"){
						lastname = ins[i].value;}
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "email"){
						email = ins[i].value;}
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "phone"){
						phone = ins[i].value;}
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "fullname"){
							fullname = ins[i].value;
						}
					}
					if (ins[i].hasAttribute('name') == true){
						if (ins[i].getAttribute('name') == "company"){
							company = ins[i].value;
						}
					}
				}/*for*/
				/*alert(_fullname);*/
				message = message.substr(0,message.length-1);
				
				ins = jQuery("#"+id).find("textarea");
				for (var i=0;i<ins.length;i++){
					if (ins[i].value != "")
						message += ":"+ins[i].value;
				}
				try{
					if (!receiver)
						receiver=100;
				}catch(err){receiver=100;}
				var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+
					"<elements>"+
					"<actor>"+document.getElementById('thisActorCode').value+"</actor>"+
					"<unit>"+document.getElementById('unit').value+"</unit>"+
					"<pageAction>addMessage</pageAction>"+
					"<action>addMessage</action>"+
					"<message>"+message+"</message>";
					if (name!="")
						xmlString+="<firstName>"+name+"</firstName>";
					if (lastname!="")
						xmlString+="<lastName>"+lastname+"</lastName>";
					if (fullname!="")
						xmlString+="<fullName>"+fullname+"</fullName>";
					if (company!="")
						xmlString+="<company>"+company+"</company>";
					
					xmlString +=				
					"<email>"+email+"</email>"+
					"<phone>"+phone+"</phone>"+
					"<receiver>"+receiver+"</receiver>"+
					"<articleCode>"+document.getElementById('articleCode').value+"</articleCode>"+
					"<wrapper>"+document.getElementById('wrapper').value+"</wrapper>"+
					"</elements>";
					xmlString = xmlString.replace(/&/g,'&amp;');
					//alert(xmlString);

					var loader1 = new net.sendThis("main",this.onGetCommunicationForm,null,this,null, "POST",xmlString,"text/xml");
}
function checkDate(inp, mode){
	var inpId=inp.id;
	var value=inp.value;
	var actor=document.getElementById('thisActorCode').value;
	var unit=document.getElementById('unit').value;
	//var strParams="actor="+actor+"&unit="+unit+"&action=getDateTimeFixed&pageAction=s_checkDateTime&datetime="+value+"&inputId="+inpId+"&mode="+mode;
	//var check_loader = new  net.ContentLoader("main",onCheckDateTime,null,"POST",strParams);
	var xmlString="<elements>"+
					"<actor>"+actor+"</actor>"+
					"<unit>"+unit+"</unit>"+
					"<inputId>"+inpId+"</inputId>"+
					"<action>getDateTimeFixed</action>"+
					"<pageAction>s_checkDateTime</pageAction>"+
					"<datetime>"+value+"</datetime>"+
					"<mode>"+mode+"</mode>"+
					"</elements>";
	xmlString=xmlString.replace(/&/g,'&amp;');
	var check_loader = new  net.send("main",onCheckDateTime,null,"POST",xmlString,"text/xml");
}

function onCheckDateTime(){
	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	if(status[0].firstChild.nodeValue=='0'){
		var inputId = doc.getElementsByTagName("inputId")[0].firstChild.nodeValue;
		if(doc.getElementsByTagName("value")[0].firstChild!=null){
			document.getElementById(inputId).value=doc.getElementsByTagName("value")[0].firstChild.nodeValue;
		}else{
			document.getElementById(inputId).value="";
		}
	}else if(status[0].firstChild.nodeValue=='-1'){
		alert(message[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-4'){
}
}

//get a parameter from url if there is any or an empty string if there isn't
/*function getParameter(parameter){
	var loc=window.location.href;
	if(loc.indexOf(parameter+'=')!=-1){
		loc=loc.substring(loc.indexOf(parameter+'='), loc.length);
		loc=loc.substring(loc.indexOf('=')+1, loc.length);
		if(loc.indexOf('&')!=-1){
			loc=loc.substring(0, loc.indexOf('&'));
		}
		if(loc.indexOf('#')!=-1){
			loc=loc.substring(0, loc.indexOf('#'));
		}
		return loc;
	}else{
		return "";
	}
}
*/

/*
Show chatroom users
  -objDiv is the container the users are shown into.
  -user and cod are arrays of users. If null, the function will search for users within the list but will not add new ones
  IMPORTANT: in selectUsrForWhisper() it should be used after showChatroom() because usrForWhisper is initialized there.
*/
function showChatUsers (objDiv, user, cod,global) {
	if (objDiv == null) return;
	
	var selectedUser;
	var hasPrivateConversation = false;
	
	//it means that this function is called when a message arrives. Adds users from message.
	if (user != null && cod != null) {
		var tmpSelected = "false";
		var tmpStyle = "style='color: black; font-weight: normal; display: block;' ";
		
		objDiv.innerHTML = "";
		
		//find if there is selected user
		for (var i=0; i<user.length-1; i++) {	//-1 because user contains a trailing ',' which the delimiter sees as an empty word at the end.
			if (usrForWhisper == cod[i]) {
				//tmpSelected = "true";
				//tmpStyle = "style='color: red; font-weight: bold; display: block;' ";
				//put selected user on top of the list
				//objDiv.innerHTML = "<div id='chatUser' name='chatUser' selected='"+tmpSelected+"' code='"+cod[i]+"' ondblclick=\"selectUsrForWhisper('"+cod[i]+"');\" "+tmpStyle+" title='"+cod[i]+"'>"+user[i]+"</div>";
				hasPrivateConversation = true;
				i = user.length;
			}
		}
		
		//tmpSelected = "false";
		tmpStyle = "style='color: black; font-weight: normal; display: block;' ";	//style for all users
		var tmpStyle2;	//style for selected user
		
		//make non-private users hidden
		if (hasPrivateConversation) {
			tmpStyle2 =  "style='color: red; font-weight: bold; display: block;' ";
			tmpStyle = "style='color: black; font-weight: normal; display: none;' ";
		}
		else
			tmpStyle2 = tmpStyle;
		var globalstr="";
		if (global=="true")
			globalstr="_global";
		//add users
		for (var i=0; i<user.length-1; i++) {
			if (usrForWhisper == cod[i])
				objDiv.innerHTML += "<div id='chatUser"+globalstr+"' name='chatUser' selected='true' code='"+cod[i]+"' onclick='selectUser(this)'   "+tmpStyle2+" title='"+user[i]+" ("+cod[i]+")'>"+user[i]+"</div>";
			else
				objDiv.innerHTML += "<div id='chatUser"+globalstr+"' name='chatUser' selected='false' code='"+cod[i]+"' onclick='selectUser(this)' "+tmpStyle+" title='"+user[i]+" ("+cod[i]+")'>"+user[i]+"</div>";
		}
		
		objDiv.innerHTML = "<span>"+getMessage(52)+"</span><br/><br/>"+ objDiv.innerHTML;
		objDiv.scrollTop = objDiv.scrollHeight;
	}
	else if (user == null || cod == null) {		//Redraw existing user list.
		//search for selected user in list
		var divs2 = objDiv.getElementsByTagName("div");
		var divs = new Array(divs2.length);
		
		//clone nodes because after clearing the parent the divs2 changes
		for (var i=0; i<divs2.length; i++) {
			divs[i] = divs2[i].cloneNode(true);
		}
		
		//clear parent
		objDiv.innerHTML = "";
		
		//add users
		for (var i=0; i<divs.length; i++) {
			divs[i].style.display = "block";
			//if (divs[i].getAttribute("code") == usrForWhisper) {
			if (divs[i].getAttribute("selected") == "true") {
				selectedUser = divs[i];
				hasPrivateConversation = true;
				//continue;
			}
			objDiv.appendChild(divs[i]);
		}
		
		if (hasPrivateConversation) {
			//make all others hidden
			for (var i=0; i<divs.length; i++) {
				if (divs[i].getAttribute("selected") == "false")
					divs[i].style.display = "none";
				else
					divs[i].style.display = "block";
			}
			
		}
		
		objDiv.innerHTML = "<span>"+getMessage(52)+"</span><br/><br/>" + objDiv.innerHTML;
	}
	else {
		alert("Wrong Parameters in showChatUsers()");
	}
	
}

// adds an image when there is a new private conversation between id1 and id2 -- used in onGetMessage()
// removes  private conversation icon and chat room upon double clicking on icon
//switches to  conversation when clicked on  message icon. If isPrivate is true then switches to private chatrooms.
//highlights the user who you are having the chat with.
function showChatRoom(id1, id2, isPrivate,isGlobal) {
	
	var glbl="";
	if (isGlobal && isGlobal=="true")
		glbl="_global";
	if (id1 != null && id1 == id2) return;
	var tmp = document.getElementsByName("chatUser");
	var room = rooms.getItem("prv_"+id1+"_"+id2);
	if (!room)
		room = rooms.getItem("prv_"+id2+"_"+id1);
	if (room){
		room.showChatRoom();
	}
	else {	//if both id1 and id2 are null
		// show public chat room

		var publicChat = document.getElementById("chatMessages"+glbl);
		currentGroup="public";
		var prvChat = document.getElementById("privateMessages"+glbl);
		var kid = jQuery(document.getElementById("chatUsers"+glbl)).children().get(0);
		
		publicChat.style.display = "block";		
		//and scroll to bottom (has to be after its made visible)
		publicChat.scrollTop = publicChat.scrollHeight;
		
		//stop blinking icon, if any
		interval = window.clearInterval(interval);
		interval = 0;
		jQuery("#public_chatroom_img"+glbl).css({'opacity': '1.0'});
		
		//un-highlight user
		for (var i=0; i<tmp.length; i++) {
			tmp[i].style.color = "black";
			tmp[i].style.fontWeight = "normal";
			tmp[i].setAttribute("selected","false");
		}
		
		//make all private chatrooms hidden
		var tmpKids = prvChat.childNodes;
		if (tmpKids != null) {
			for (var i=0; i<tmpKids.length; i++)
			if (tmpKids[i].tagName!=null && tmpKids[i].tagName!="undefined")
				tmpKids[i].style.display = "none";
		}
		prvChat.style.display = "none";	//to fix bug in IE
		for (var i=0; i<tmp.length; i++) {
			tmp[i].style.color = "black";
			tmp[i].style.display = "block";
			tmp[i].style.fontWeight = "normal";
			tmp[i].setAttribute("selected", "false");
		}
	}
	
	
}

//get a parameter from url if there is any or an empty string if there isn't
function getParameter(parameter){
	var loc=window.location.href;
	if(loc.indexOf(parameter+'=')!=-1){
		loc=loc.substring(loc.indexOf(parameter+'='), loc.length);
		loc=loc.substring(loc.indexOf('=')+1, loc.length);
		if(loc.indexOf('&')!=-1){
			loc=loc.substring(0, loc.indexOf('&'));
		}
		if(loc.indexOf('#')!=-1){
			loc=loc.substring(0, loc.indexOf('#'));
		}
		return loc;
	}else{
		return "";
	}
}

function resizeIframe(newHeight){
  //alert('aaaa');
  //alert(newHeight);
  //var f =document.getElementsByTagName('iframe')[0];
  //f.style.height = f.contentWindow.document.body.scrollHeight + 'px';
  //alert(f.style.height);
  //alert(.contentDocument.body.height);
  //document.getElementsByTagName('iframe')[0].style.height = parseInt(newHeight) + 10 + 'px';
  //alert(document.getElementsByTagName('iframe')[0].style.height);
  
  /*iframe=parent.document.frames[frameId];
  iframe.height = newHeight;*/
}
/*function resizeIframe(frameId) {
   try{
      frame = document.getElementByTagName('iframe')[0];
      innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
      objToResize = (frame.style) ? frame.style : frame;
      objToResize.height = innerDoc.body.scrollHeight + 10;
   }
   catch(err){
      window.status = err.message;
   }
}*/

function processBlock(){

	/*var el = document.getElementById('loginDialog');
	//alert(el);
	$.blockUI({
		message: jQuery(el),
		centerY: 0,
		css: {
			width: '200px',
			top: '100px',
			left: '300px',
			right: '',
			border: 'none',
			padding: '5px',
			cursor: 'not-allowed',
			backgroundColor: '#fff',
			'-webkit-border-radius': '10px',
			'-moz-border-radius': '10px',
			//opacity: .6,
			color: '#fff'
		}
	});*/
}

function loginDash(){
	var username = document.getElementById('un_input').value;
	var pass = document.getElementById('pass_input').value;
	var act_code = document.getElementById('act_input').value;
	var strParams="action=Login&username="+username+"&password="+pass+"&actorCode="+act_code;
	//alert(strParams);
	var login_loader = new  net.ContentLoader("MainViewServlet",Dlogged,null, "POST",strParams);
}

function handleRoles(el){
	var val = el.getAttribute('value');
	var strParams="action=fetchRoles&value="+val;
	
	var login_loader = new  net.ContentLoader("main",changeTabs,null, "POST",strParams);
}

function changeTabs(){

	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	var content = doc.getElementsByTagName("content");

	if(status[0].firstChild.nodeValue=='0'){
		document.getElementById('cssmenubopen').innerHTML=content[0].firstChild.nodeValue;
	}else if(status[0].firstChild.nodeValue=='-1'){
		document.getElementById('viewDiv').innerHTML="";
		alert(message[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-4'){
		document.getElementById('viewDiv').innerHTML="";
		parent.processBlock();
	}

}

function Dlogged(){
	var doc=this.req.responseXML;
	//alert(this.req.responseText);
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	if(status[0].firstChild.nodeValue=='0'){
		$.unblockUI();
	/*for(var i=0; i<lastOpenedFrame.length; i++){
			var ifra=lastOpenedFrame.pop();
			ifra.reload(this, lastOpenedUrl.pop());
		}*/
	}else if(status[0].firstChild.nodeValue=='-1'){
		alert(message[0].firstChild.nodeValue);
	}
}

function al() {
	var div=document.getElementById("div4");
	div.style.cursor="pointer";
	div.style.position = "absolute";
	div.style.backgroundImage="url(codebase/neokopsimo/3-red.gif)";
	div.style.left = "755px";
	div.style.top = "146px";
	div.style.height = "62px";
	div.style.width = "269px";
	div.style.zIndex = "1000";
	div.onmouseout=function(evt){
		eval("al2()");
	}
}
 
function al2(){
	var div=document.getElementById("div4");
	div.style.cursor="pointer";
	div.style.position = "absolute";
	div.style.backgroundImage="url(codebase/neokopsimo/3.gif)";
	div.style.left = "755px";
	div.style.top = "146px";
	div.style.height = "62px";
	div.style.width = "269px";
	div.style.zIndex = "1000";
}

function al3() {
	var div=document.getElementById("div10");
	div.style.cursor="pointer";
	div.style.position = "absolute";
	div.style.backgroundImage="url(codebase/neokopsimo/5-anapoda.gif)";
	div.style.left = "755px";
	div.style.top = "302px";
	div.style.height = "68px";
	div.style.width = "269px";
	div.style.zIndex = "1000";
	div.onmouseout=function(evt){
		eval("al4()");
	}
}

function al4(){
	var div=document.getElementById("div10");
	div.style.cursor="pointer";
	div.style.position = "absolute";
	div.style.backgroundImage="url(codebase/neokopsimo/5.gif)";
	div.style.left = "755px";
	div.style.top = "302px";
	div.style.height = "68px";
	div.style.width = "269px";
	div.style.zIndex = "1000";
}

function loadMaps() {

	var el = document.createElement("a");
	el.setAttribute("href",'?unit=KT_Example');
	el.appendChild(document.createElement("br"));
	el.appendChild(document.createElement("br"));
	el.appendChild(document.createElement("br"));
	el.appendChild(document.createElement("br"));
	el.style.position = "absolute";
	el.style.cursor = "pointer";
	el.style.left = "780px";
	el.style.top = "290px";
	el.style.Height = "200px";
	el.style.width = "200px";
	el.href='?unit=KT_Example';
	//el.style.backgroundColor = "red";
	document.body.appendChild(el);


	addScrollers();

	if (GBrowserIsCompatible() && document.getElementById("map")!=null) {
		var la = document.getElementById("map").getAttribute("la");
		var lo = document.getElementById("map").getAttribute("lo");
     
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(la,lo), 15);
		map.addOverlay(new GMarker(new GLatLng(la, lo)));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());


	}
}

function onButtonClick(itemId,itemValue){
	alert("Button "+itemId+" was pressed"+(itemValue?("\n select value : "+itemValue):""));
};

var first,second;
var active;

document.oncontextmenu = function() {
	return true;
}
	
function onDown(val) {
	first=val;
	active=val;
	val.oncontextmenu = function() {
		return false;
	}
		
}
	
function resizeRight(elem){
		
	var start = parseInt(elem.id);
	var identity = start+(1*elem.getAttribute('colspan'));
	//alert(elem.parentNode.innerHTML);
	//alert(elem.getAttribute('colspan'));
	var ni = (parseInt(elem.getAttribute('colspan'))+1);
	var total = parseInt(ni)+parseInt(elem.id)-1;
	var d;
	if (parseInt(elem.id)>0 && parseInt(elem.id)<=30)
		d = 30;
	if (parseInt(elem.id)>30 && parseInt(elem.id)<=60)
		d = 60;
	if (parseInt(elem.id)>60 && parseInt(elem.id)<=90)
		d = 90;
	if (parseInt(elem.id)>90 && parseInt(elem.id)<=120)
		d = 120;
		
	if (total>d)
		return;
	//alert(elem.innerHTML);
	//alert("BEFORE:"+elem.getAttribute('colspan'));
	elem.colSpan = ni;
	elem.width = (ni*3)+"%";
	//elem.colspan="2";
	//alert(elem.parentNode.innerHTML);
	//alert("AFTER:"+elem.getAttribute('colspan'));
	//alert(elem.colspan);
	for (var i=0;i<elem.getAttribute('rowspan');i++)
	{
		var nex = document.getElementById(identity);
		if (nex!=null)
			nex.parentNode.removeChild(nex);
		identity = identity + 30;
	}
		
//alert((elem.getAttribute('colspan')+1));
}
	
function resizeUp(elem){
		
	var start = parseInt(elem.id);
		
	var identity = start+(30*elem.getAttribute('rowspan'));
	var ni = (parseInt(elem.getAttribute('rowspan'))+1);
	elem.rowSpan = ni;
	for (var i=0;i<elem.getAttribute('colspan');i++)
	{
		//alert(i);
		  
		var nex = document.getElementById(identity);
		//alert(identity);
		if (nex!=null)
			nex.parentNode.removeChild(nex);
		identity = identity + 1;
	}
//alert((elem.getAttribute('colspan')+1));
}
	
function test(e,el){
	if(navigator.appName.toLowerCase().indexOf("netscape")!=-1){
		if (e.button == 0)
			resizeUp(el)
		if (e.button == 2)
			resizeRight(el)
	}

	if(navigator.appName.toLowerCase().indexOf("netscape")==-1){
		if (e.button == 1)
			resizeUp(el)
		if (e.button == 2)
			resizeRight(el)
	}
}

function onOver(el){
	el.parentNode.className="over";
	el.className="over";
}

function onOut(el){
	el.parentNode.className="out";
	el.className = "out";//setAttribute('style',"font-size:14;");
}

function getHtmlFragment(xmlUrl,id) {
	alert('1')
	//load the xml file
	var xmlSource = getResponseXml(xmlUrl,"POST").responseXML;
	var elem = document.getElementById(id);
	elem.innerHTML = getResponseXml(xmlUrl,"POST").responseText;
}

function kteolist(){
	var xmlUrl = "../PlatonServlet/PlatonServlet?user=kteo&pass=group&unit=kt_Example&datacomponent=g_KteoList&";
	alert('1');
	//"?action=fetch&dataComponent=articleMain&id=symmetry/philosophy.html";//"PlatonServlet/PlatonServlet?user=kteo&pass=group&unit=kt_Example&datacomponent=g_KteoList&";
	//load the xml file
	var xmlSource =  getResponseXml(xmlUrl,"GET");

	//alert(xmlSource.responseText);
	var text = xmlSource.responseText;
	try //Internet Explorer
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(text);
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(text,"text/xml");
		}
		catch(e) {
			alert(e.message)
			}
	}
	var xmlRoot = xmlDoc.documentElement;
	var sel = document.getElementById('kteo');
	var str="";
	for(var i=0;i<xmlRoot.getElementsByTagName('kteo').length;i++){
		str+="<option value="+xmlRoot.getElementsByTagName('kteo')[i].childNodes[0].firstChild.nodeValue+">"+
		xmlRoot.getElementsByTagName('kteo')[i].childNodes[1].firstChild.nodeValue+"</option>";
	}
	alert('2');
	sel.innerHTML = str;
	sel.outerHTML = "<select id='kteo'>"+str+"</select>";
//alert(xmlRoot.getElementsByTagName('kteo')[0].getAttribute('id'));
//alert(xmlRoot.getElementsByTagName('kteo')[0].childNodes[0].firstChild.nodeValue);
//alert(xmlRoot.getElementsByTagName('kteo')[0].childNodes[1].firstChild.nodeValue);
}

function calendar(){
	/*document.body.style.cursor = "wait";
	//alert('1');
	var dd = document.getElementById('date1').value;
	var day = dd.substring(0,dd.indexOf("/"));
	var mm = dd.substring(dd.indexOf("/")+1,dd.lastIndexOf("/"));
	var yy = dd.substring(dd.lastIndexOf("/")+1,dd.length);
	if (day.length<2)
	  day = "0"+day;
	if (mm.length<2)
	  mm = "0"+mm;
	dd = yy+mm+day;
	//alert(yy+" "+mm+" "+day);
	var xmlUrl = "../PlatonServlet/PlatonServlet?&user=kteo&pass=group&unit=kt_Example&datacomponent=g_CalendarSet&date="+
	   +dd+"&kteo="+document.getElementById('select1').value+"&days=2";
//alert(xmlUrl);
	//"?action=fetch&dataComponent=articleMain&id=symmetry/philosophy.html";//"PlatonServlet/PlatonServlet?user=kteo&pass=group&unit=kt_Example&datacomponent=g_KteoList&";
//load the xml file
var xmlSource =  getResponseXml(xmlUrl,"GET");

//alert(xmlSource.responseText);
var text = xmlSource.responseText;
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(text);
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(text,"text/xml");
    }
  catch(e) {alert(e.message)}
  }
  var xmlRoot = xmlDoc.documentElement;
  var sel = document.getElementById('select2');
  var str="";
  */
	document.getElementById('karelegx').removeAttribute('disabled');
	document.getElementById('liksikartas').removeAttribute('disabled');
	document.getElementById('eidoxim').removeAttribute('disabled');
	document.getElementById('eidelegx').removeAttribute('disabled');
	document.getElementById('arkyklof').removeAttribute('disabled');
  
	document.getElementById('name').removeAttribute('disabled');
	document.getElementById('address').removeAttribute('disabled');
	document.getElementById('tk').removeAttribute('disabled');
	document.getElementById('city').removeAttribute('disabled');
	document.getElementById('mobile').removeAttribute('disabled');
	document.getElementById('homephone').removeAttribute('disabled');
	document.getElementById('workphone').removeAttribute('disabled');
	document.getElementById('email').removeAttribute('disabled');
  
// document.getElementById('kartaelegxou').removeAttribute('disabled');
//alert('2');
/* if (xmlRoot!=null) {
    if (xmlRoot.getElementsByTagName('hour').length==0){
      alert('Αυτή την ημερομηνία είμαστε πλήρεις');
      document.body.style.cursor = "default";
      return;
    }
  //alert('3');
  if (xmlRoot.getElementsByTagName('hour'))
  for(var i=0;i<xmlRoot.getElementsByTagName('hour').length;i++){
  	str+="<option value="+xmlRoot.getElementsByTagName('kteo')[i].childNodes[0].firstChild.nodeValue+">"+
  	  xmlRoot.getElementsByTagName('kteo')[i].childNodes[1].firstChild.nodeValue+"</option>";
  }
//alert('4');
  sel.innerHTML = str;
  sel.outerHTML = "<select id='select1'>"+str+"</select>";
  }
  document.body.style.cursor = "default";

 
  //alert(xmlRoot.getElementsByTagName('kteo')[0].getAttribute('id'));
  //alert(xmlRoot.getElementsByTagName('kteo')[0].childNodes[0].firstChild.nodeValue);
  //alert(xmlRoot.getElementsByTagName('kteo')[0].childNodes[1].firstChild.nodeValue);*/
}
function callScript(elem){
	var unit = getParameter('unit');
	var action = "callScript"
	var xmlUrl = "main"
	var strParams = "component=PlatonAction&action="+action+"&dataAction="+action+"&unit="+unit+"&script="+elem;
	var loader1 = new  net.ContentLoader(xmlUrl,setChanges,null, "POST",strParams);   
}
function senddata(elem){
	var unit = getParameter('unit');
	var action = elem.getAttribute("action");
	var dc="";
	if(elem.getAttribute("dataComponent") && elem.getAttribute("dataComponent")!=""){
		dc = elem.getAttribute("dataComponent");
	}else{
		dc = elem.getAttribute("formDataComponent");
	}
	var xmlUrl = "main"
	var strParams = "component=PlatonAction&action="+action+"&dataAction="+action+"&unit="+unit+"&dataComponent="+dc;
	var loader1 = new  net.ContentLoader(xmlUrl,setChanges,null, "POST",strParams);   
}

function aler(){
	var xmlUrl = "?&action=platonAction&dataAction=execute&unit=KT_Example&dataComponent=s_KteoList&";
  
	//var xmlSource =  getKteoList(xmlUrl,"POST");
	//alert(xmlSource.responseText);
	var xmlDoc = getKteoList(xmlUrl,"POST").responseXML;
	var xmlRoot = xmlDoc.documentElement;
	var kteos = xmlDoc.getElementsByTagName('kteo');
	var sel = document.getElementById('kteo');
	var str="";
	for(var i=0;i<xmlRoot.getElementsByTagName('kteo').length;i++){
		str+="<option value="+xmlRoot.getElementsByTagName('kteo')[i].childNodes[0].firstChild.nodeValue+">"+
		xmlRoot.getElementsByTagName('kteo')[i].childNodes[1].firstChild.nodeValue+"</option>";
	}
	//alert('2');
	sel.innerHTML = str;
	sel.outerHTML = "<select id='kteo'>"+str+"</select>";
  
	if (document.getElementById('karelegx'))
		document.getElementById('karelegx').setAttribute('disabled','disabled');
	if (document.getElementById('liksikartas'))
		document.getElementById('liksikartas').setAttribute('disabled','disabled');
	if (document.getElementById('eidoxim'))
		document.getElementById('eidoxim').setAttribute('disabled','disabled');
	if (document.getElementById('eidelegx'))
		document.getElementById('eidelegx').setAttribute('disabled','disabled');
	if (document.getElementById('arkyklof'))
		document.getElementById('arkyklof').setAttribute('disabled','disabled');
   
	if (document.getElementById('name'))
		document.getElementById('name').setAttribute('disabled','disabled');
	if (document.getElementById('address'))
		document.getElementById('address').setAttribute('disabled','disabled');
	if (document.getElementById('tk'))
		document.getElementById('tk').setAttribute('disabled','disabled');
	if (document.getElementById('city'))
		document.getElementById('city').setAttribute('disabled','disabled');
	if (document.getElementById('mobile'))
		document.getElementById('mobile').setAttribute('disabled','disabled');
	if (document.getElementById('workphone'))
		document.getElementById('workphone').setAttribute('disabled','disabled');
	if (document.getElementById('homephone'))
		document.getElementById('homephone').setAttribute('disabled','disabled');
	if (document.getElementById('email'))
		document.getElementById('email').setAttribute('disabled','disabled');
}

function getKteoList(xmlUrl,meth) {
	
	var xmlHttp;


	if(navigator.appName.toLowerCase().indexOf("explorer")!=-1){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{

		xmlHttp = new XMLHttpRequest();

	}

	xmlHttp.open(meth, xmlUrl, false);
	xmlHttp.send(null);

	return xmlHttp;
}

function getArticles(sourceNodeId,categoryName,code,unit){
	
	var elem = document.getElementById(sourceNodeId);
	//alert("adsfdf"+sourceNodeId+" "+elem);
	if (elem==null){
		window.location = "?unit="+unit+"&code="+code+"&component="+sourceNodeId;
		return;
	}else{
		//alert("IN POST");
		var xy = sourceNodeId+'.getArticles(sourceNodeId,categoryName,code,unit)';
		eval(xy);
	//loadMaps();
	}
}

function changePic(elem){
	var image = document.getElementById("imbig");
	var elemstr = elem.id;
 
	var srcold = image.src;
	/*if ((elem.id).indexOf("renti")!=-1)
	   document.getElementById("imbig").setAttribute("src","../../../platonimages/images/mrkteo/renti/"+elem.id+".jpg");	
	if ((elem.id).indexOf("XAID")!=-1)
		document.getElementById("imbig").setAttribute("src","../../../platonimages/images/mrkteo/XAIDARI/"+elem.id+".jpg");
	if ((elem.id).indexOf("ANAR")!=-1)
		document.getElementById("imbig").setAttribute("src","../../../platonimages/images/mrkteo/ANARGIROI/"+elem.id+".jpg");
	if ((elem.id).indexOf("ANAR")!=-1)
		document.getElementById("imbig").setAttribute("src","../../../platonimages/images/mrkteo/ANARGIROI/"+elem.id+".jpg");*/
	image.src=elem.src;
	elem.src = srcold;
	setOpacity(image, 0);
	image.style.visibility = 'visible';
	fadeIn("imbig",0);
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
  
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
  
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
  
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
  
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}

function load() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	}
}

function isDisekto(tempyear){

	if(tempyear % 4 == 0 && tempyear % 100 != 0){
		
		return true;
	}
	else{
		if(tempyear % 400 == 0){
		
			return true;
		}
	
		return false;
	}
	
}

/*function potePernaoKteo(){
	window.addEvent('domready', function() {
		Sexy = new SexyAlertBox();
	});
	

	
	var year = document.getElementById("year").value;
	year = parseInt(year);
	//alert(year+4);
	
	var date = document.getElementById("date").value;
	date = parseInt(date );
	var month = document.getElementById("month").value;
	month = parseInt(month );
	var enddate,endmonth,endyear;
	if (document.getElementById("type").value=="2" || (document.getElementById("type").value=="1" && year>=2005)){
 
		//gia mines me 31 meres
		if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
			if (date>21){
				var tt="αρχικού";
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
			
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				endmonth=month;
		
				if (date>24){
					if (month==12){
						endmonth=1;endyear=endyear+1;
					}
					else{
						endmonth=endmonth+1;
					}
					enddate=31-date;
					enddate=7-enddate;
				
				}
				else
					enddate=date+7;
				date=date-21;
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
			else{
				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
		  
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
			
				endyear=year;
				enddate=date+7;
				endmonth=month;
			
			
				date=21-date-1;
			
				if(isDisekto(year)==true && month==3){
					date=29-date-1;
				}
				else if(month==3)
					date=28-date-1;
				else if (month==8)
					date=31-date-1;
				else
					date=30-date-1;
				if (month>1)
					month=month-1;
				else{
					year=year-1;month=12;
				}
		
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}
			
			//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
		}
		//TELOS 31 meres
		else
		//gia mines me 30 meres
		if(month==4 || month==6 || month==9 || month==11){
			if (date>21){
				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				endmonth=month;
		
				if (date>23){
					if (month==12){
						endmonth=1;endyear=endyear+1;
					}
					else{
						endmonth=endmonth+1;
					}
					enddate=31-date;
					enddate=7-enddate+1;
				
				}
				else
					enddate=date+7;
				date=date-21;
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}	//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
			else{
				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				enddate=date+7;
				endmonth=month;
			
				if (month>1)
					month=month-1;
				else{
					year=year-1;month=12;
				}
		
				date=21-date-1;
				date=31-date-1;
		
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}///alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
		}
		//TELOS 30 meres
		else
		//gia febrouario me 29 meres
		if(month==2 && isDisekto(year)==true){
			if (date>21){
				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				endmonth=month;
		
				if (date>22){
					if (month==12){
						endmonth=1;endyear=endyear+1;
					}
					else{
						endmonth=endmonth+1;
					}
					enddate=29-date;
					enddate=7-enddate;
				
				}
				else
					enddate=date+7;
				date=date-21;
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}	//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
			else{
				var tt="αρχικού";
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				enddate=date+7;
				endmonth=month;
			
				if (month>1)
					month=month-1;
				else{
					year=year-1;month=12;
				}
		
				date=21-date-1;
				date=31-date-1;
		
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
		}
		//TELOS febrouario me 29 meres
		
		//gia febrouario me 28 meres
		else
		if(month==2 && isDisekto(year)==false){

			if (date>21){

				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				endmonth=month;
		
				if (month==12){
					endmonth=1;
					endyear=endyear+1;
				}
				else{
					endmonth=endmonth+1;
				}
			
				enddate=28-date;
			
				enddate=7-enddate;
				
			
		  
				//enddate=date+7;
				date=date-21;
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}	//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
			else{
				var tt="αρχικού"
				if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="2"){
					year=year+2;
					tt="περιοδικού"
				}
				else if (document.getElementById("eidos").value=="2" && document.getElementById("type").value=="1"){
					if (year>=2007)
						year=year+2;
					else
						year=year+3;
			 	
					tt="περιοδικού"
				}
				else
					year=year+4;
				endyear=year;
				enddate=date+7;
				endmonth=month;
	
				if (month>1)
					month=month-1;
				else{
					year=year-1;month=12;
				}
		
				date=21-date-1;
				date=31-date-1;
		
				var myDate=new Date();
				myDate.setFullYear(endyear,(endmonth-1),enddate);
      
				var today = new Date();

				if (myDate>today)
				{
					Sexy.info("Το ημερολογιακό διάστημα <br>εμπρόθεσμου "+tt+" τεχνικού ελέγχου <Br>για το όχημα σας είναι <br><b>Aπό:</b>"+date+"/"+month+"/"+year+" <Br><b>Mέχρι:</b>"+enddate+"/"+endmonth+"/"+endyear);
			
				}
				else
				{
					Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
				}//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
			}
		//TELOS febrouario me 28 meres
		}
	}
		
	else {
	
		if (year<2005){
			Sexy.alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
			//alert("Το όχημα σας είναι ήδη εκπρόθεσμο για αρχικό τεχνικό έλεγχο");
			return;
		}
		var d = new Date();
	
		var currentYear = d.getFullYear();
		year = currentYear;
		d = d.getMonth();
		d=d+1;
		if (d>month){
			year=year+1;
		}
		endmonth=month;
		endyear=year;
		if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
			enddate=31;
		if(month==4 || month==6 || month==9 || month==11)
			enddate=30;
		if(month==2 && isDisekto(year)==true)
			enddate=29;
		if(month==2 && isDisekto(year)==false)
			enddate=28;
		Sexy.info("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:1/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
	//alert("Το ημερολογιακό διάστημα εμπρόθεσμου αρχικού τεχνικού ελέγχου \nγια το όχημα σας είναι από:"+date+"/"+month+"/"+year+" μέχρι:"+enddate+"/"+endmonth+"/"+endyear);
	
	}

//Else if (document.getElementById("eidos").value=="2"){
//	if (document.getElementById("type").value=="1"){
		
//		Sexy.info("Δεν ξέρω πότε θα περάσετε τεχνικό έλεγχο");

//	}
//	if (document.getElementById("type").value=="2"){
//		endyear=year+4;
//		endmonth=month;
//		enddate=date;
//		Sexy.info("Θα περάσετε εμπρόθεσμο τεχνικό έλεγχο \nστις:"+enddate+"/"+endmonth+"/"+endyear);
//	}
//}
}*/

function postAction(elem){
	var dc="";
	var inp=document.getElementById(elem);
	var inpval=inp.value;
	var value="";
	if(inp.getAttribute('hasCode')=="true"){
		if(inpval!=""){
			value=inp.getAttribute('code');
		}else{
			value=inpval;
		}
	}else{
		if(inp.type=='checkbox'){
			if(inp.checked){
				value='1';
			}else{
				value='0';
			}
		}else{
			value=inpval;
		}
	}
	if (inp.getAttribute('dataVariable')!=null){
		dc=inp.getAttribute('dataVariable');
	}else if (inp.getAttribute('dataComponent')!=null && inp.getAttribute('dataComponent')!=""){
		dc=inp.getAttribute('dataComponent');
	}else{
		dc=inp.getAttribute('formDataComponent')+"."+inp.getAttribute('formField');
	}
	var extra="";
	if(jQuery(inp).hasClass('gridInput')){
		extra="&recordId="+inp.getAttribute('recId')+"&row="+inp.getAttribute('row');
	}
	var xmlUrl = "main"
	var unit = document.getElementById("unit").value;
	var strParams = "actorCode="+document.getElementById('thisActorCode').value+"&component=PlatonAction&action=set value&dataAction=WEB_SETVALUE&value="+value+"&unit="+unit+"&dataComponent="+dc+"&commit="+inp.getAttribute("commit")+extra;
	var loader1 = new  net.ContentLoaderThis(xmlUrl,setChanges,null, inp, null,"POST",strParams); 
}

function setChanges(){
	var xml;
	var pp=0;
	var inp;
	if(arguments[0]){
		xml = arguments[0];
	}else{
		xml = this.req.responseXML;
		inp=this.obj_reference;
	}
	if (xml!=null && xml.getElementsByTagName("changed")[0]!=null){
		var inputs=document.getElementsByTagName("input");
		var txtareas=document.getElementsByTagName("textarea");
		var inputslen=inputs.length;
		var txtareaslen=txtareas.length;
		var changed=xml.getElementsByTagName("changed")[0].childNodes;
		for(var v=0; v < changed.length; v++){
			var chang=changed[v];
			var ch = chang.tagName;
			var type=chang.getAttribute('type');
			var editMode=chang.getAttribute('editMode');
			if (type=="variable"){
				for (var j=0;j<inputslen;j++){
					var inp = inputs[j];
					if(!inp){
						//if somehow exe figei to input apo to dom
						continue;
					}
					if (inp.getAttribute("dataComponent") == ch){//simple variable
						inp.value=chang.getAttribute("value");
						if (editMode!=null && editMode=="true")
							inp.removeAttribute("disabled");
						else if (editMode=="false")
							inp.setAttribute("disabled","true");
						jQuery(inp).trigger("valueChangedEvent");
					}/*else if(inp.getAttribute("datavariable")==ch){
						//ti tha ginei an allaksei timi i variable pou sindeetai me mia lista?
					}*/
				}
			}else if (type=="list"){
				//de xreiazetai tpt efoson oi listes einai dinamikes
			}else if (type=="record"){
				var isActive=chang.getAttribute('isActive');
				var row=chang.getAttribute('row');
				var set=chang.getAttribute('set');
				//an i grammi den einai active tote bres to table me dataset=set kai kane ti row disabled
				if(isActive=="false" && set!="s_LinkSet"){
					var tr=jQuery('table[dataset='+set+'] tbody tr:eq('+row+')');
					if(tr.length>0){
						tr.addClass("deletedRow");
						tr.removeClass("selectedRow");
						tr.removeClass("isSelected");
						tr.trigger('rowDisabled'); //trigger the event to unbind the click in the row. currently used for grid
					}
				}else{
					//ilopoisi ean einai true. xreiazetai??
				}
				var chnodes=chang.childNodes;
				var len=chnodes.length;
				for(j=0; j<len; j++){
					var tname=chnodes[j].tagName;
					for (var i=0;i<inputslen;i++){
						var inp = inputs[i];
						if(!inp){
							//if somehow exe figei to input apo to dom
							continue;
						}
						if(inp.type=="file"){
							continue;
						}
						if (inp.getAttribute('dataComponent')==ch+"."+tname ){//&&  && !jQuery(inp).hasClass("gridInput")  pgrdInput
							var el=chnodes[j];
							var bal=chnodes[j].firstChild;
							if(bal){
								bal=chnodes[j].firstChild.nodeValue;
							}else{
								bal="";
							}
							if(inp.type=="checkbox"){
								if(bal=='1'){
									inp.checked=true;
								}else{
									inp.checked=false;
								}
							}else{
								inp.value=bal;
								if(el.getAttribute('code')){
									inp.setAttribute(code, el.getAttribute('code'));
								}
							}							
							if (editMode!=null && editMode=="true")
								inp.removeAttribute("disabled");
							else if (editMode=="false")
								inp.setAttribute("disabled","true");
							jQuery(inp).trigger("valueChangedEvent");
						}
					}
					for (var i=0;i<txtareaslen;i++){
						var inp =txtareas[i];
						if (inp.getAttribute('dataComponent')==ch+"."+tname){
							var bal=chang.childNodes[j].firstChild;
							if(bal){
								bal=chang.childNodes[j].firstChild.nodeValue;
							}else{
								bal="";
							}
							inp.value=bal;
							if (editMode!=null && editMode=="true")
								inp.removeAttribute("disabled");
							else if (editMode=="false")
								inp.setAttribute("disabled","true");
							jQuery(inp).trigger("valueChangedEvent");
						}
					}
				}
			}else if (type=="dataset"){
				//alert('data set:'+pp);
				//if (pp>0 || xml.getElementsByTagName("g_questionRec")[0]==null)
				//	continue;
				//pp++;
				var tablesDataset = jQuery("table[dataset='"+ch+"']");
				if (tablesDataset.length>0){
					var idd = tablesDataset[0].id;
					idd=idd.replace(/_mainTable/,"");
					//tables.getItem(idd).executeCriteria();
					tables.getItem(idd).refreshTable();
					//tables.getItem(tablesDataset[0].id.substring(0,tablesDataset[0].id.indexOf("_"))).executeCriteria();
				}
			}else if (ch=='platonmessage'){
				var message = chang.childNodes[0].nodeValue;
				alert(message);
			}else{
				//alert('No type attribute specified in changed element');
			}
		}
	}
	if(inp){
		//checkDflt(inp, true); //not used pros to paron
	}
}

function hourList(){
	var xml = this.req.responseXML;
	//alert(this.req.responseText);
	var unit = window.location.href ;
	unit = unit.substring(unit.indexOf("unit=")+5,unit.length);
	
	if (unit.indexOf("&")!=-1)
		unit = unit.substring(0,unit.indexOf("&"));
  
	if (unit.indexOf("#")!=-1)
		unit = unit.substring(0,unit.indexOf("#"));

	if (xml!=null && xml.getElementsByTagName("message")[0]!=null && unit=="KT_Accounts"){
		alert(xml.getElementsByTagName("message")[0].childNodes[0].nodeValue);
	}
	/*if (xml!=null && xml.getElementsByTagName("message")[0]!=null)
{
	//alert(xml.getElementsByTagName("message")[0].childNodes[0].nodeValue);
	var a3 = document.getElementById("s_article3");
		 	 while ( a3.childNodes.length >= 1 )
    				{
        					a3.removeChild( a3.firstChild );       
    				} 
		 	val2= xml.getElementsByTagName("message")[0].childNodes[0].nodeValue;
		 	//alert(val2);
		 	//a3.appendChild(document.createElement("<br>"));
		 	a3.appendChild(document.createTextNode(val2));
		 	a3.appendChild(document.createElement("<br>"));
}	*/

	if (xml!=null && xml.getElementsByTagName("changed")[0]!=null)
	{
		//alert(xml.getElementsByTagName("result"));
		//alert(this.req.responseText);
		for(var v=0;v<xml.getElementsByTagName("changed")[0].childNodes.length;v++){
		
			var ch = xml.getElementsByTagName("changed")[0].childNodes[v].tagName;
			if (ch=="s_ReturnVar"){
				var a3 = document.getElementById("s_article3");
				//alert(a3.childNodes[1].childNodes[0].getAttribute("class"));
				var aa = a3.childNodes[0];
				if (aa.tagName!="DIV" && aa.tagName!="div")
					aa = a3.childNodes[1];
				var aa1 = aa.childNodes[0];
				//alert(a3.getAttribute("class"));
				//	a3.setAttribute("class","messageBodyIe");
		 	
				while ( aa1.childNodes.length >= 1 )
				{
					aa1.removeChild( aa1.firstChild );
				}
				val2= xml.getElementsByTagName("changed")[0].childNodes[v].getAttribute('value');
				//alert(val2);
				aa1.appendChild(document.createTextNode(val2));
			//alert(a3.getAttribute("class"));
			}
		
			var type=xml.getElementsByTagName("changed")[0].childNodes[v].getAttribute('type');
			var editMode=xml.getElementsByTagName("changed")[0].childNodes[v].getAttribute('editMode');
		 
			if (xml.getElementsByTagName("changed")[0].childNodes[v].getAttribute("value")!=null){
				for (var j=0;j<document.getElementsByTagName("input").length;j++){
					var inp = document.getElementsByTagName("input")[j];
					//my code //here
					if (inp.getAttribute("dataComponent") == ch || inp.getAttribute("formDataComponent") == ch){
						inp.value=xml.getElementsByTagName("changed")[0].childNodes[v].getAttribute("value");
						if (editMode!=null && editMode=="true")
							inp.removeAttribute("disabled");
						else if (editMode=="false")
							inp.setAttribute("disabled","true");
					}
				// to here
				}
			//alert(inp.id+" "+inp.getAttribute("dataComponent"));
			//if (inp.getAttribute("dataComponent") == ch)
			//alert("variablefield:"+inp.id);
			}
			else if (type==null && xml.getElementsByTagName("changed")[0].childNodes[v].childNodes.length==0){
				for (var i=0;i<document.getElementsByTagName("input").length;i++){
					var inp = document.getElementsByTagName("input")[i];
					if (inp.getAttribute("dataComponent") == ch || inp.getAttribute("formDataComponent")==ch){
						if (editMode!=null && editMode=="true")
							inp.removeAttribute("disabled");
						else if (editMode=="false")
							inp.setAttribute("disabled","true");
					}
				}
		 	  
				for (var i=0;i<document.getElementsByTagName("select").length;i++){
		 	  	
					var inp = document.getElementsByTagName("select")[i];
					if (inp.getAttribute("dataComponent") == ch || inp.getAttribute("formDataComponent")==ch){
						if (editMode!=null && editMode=="true")
							inp.removeAttribute("disabled");
						else if (editMode=="false")
							inp.setAttribute("disabled","true");
					}
				}
			}
			else{
				//my code //here
				var len=xml.getElementsByTagName("changed")[0].childNodes[v].childNodes.length;
				for(j=0; j<len; j++){
					var tname=xml.getElementsByTagName("changed")[0].childNodes[v].childNodes[j].tagName;
					for (var i=0;i<document.getElementsByTagName("input").length;i++){
						var inp = document.getElementsByTagName("input")[i];
						if (inp.id.endsWith(tname) && (inp.getAttribute('formDataComponent')==ch || inp.getAttribute("dataComponent") == ch)){
							inp.value=xml.getElementsByTagName("changed")[0].childNodes[v].childNodes[j].getAttribute('value');
							if (editMode!=null && editMode=="true")
								inp.removeAttribute("disabled");
							else if (editMode=="false")
								inp.setAttribute("disabled","true");
						}
					}
					for (var i=0;i<document.getElementsByTagName("textarea").length;i++){
						var inp = document.getElementsByTagName("textarea")[i];
						if (inp.id.endsWith(tname) && (inp.getAttribute('formDataComponent')==ch || inp.getAttribute("dataComponent") == ch)){
							inp.value=xml.getElementsByTagName("changed")[0].childNodes[v].childNodes[j].getAttribute('value');
							if (editMode!=null && editMode=="true")
								inp.removeAttribute("disabled");
							else if (editMode=="false")
								inp.setAttribute("disabled","true");
						}
					}
				}
				//to here
			
				for (var i=0;i<document.getElementsByTagName("select").length;i++){
					var inp = document.getElementsByTagName("select")[i];
					if (inp.getAttribute("dataComponent") == ch){
						var str="";
		 	  	
						while ( inp.childNodes.length >= 1 )
						{
							inp.removeChild( inp.firstChild );
						}

						for (var j=0;j<xml.getElementsByTagName("changed")[0].childNodes[v].childNodes.length;j++){
							var val = xml.getElementsByTagName("changed")[0].childNodes[v].childNodes[j].getAttribute('value');
							var val2 = xml.getElementsByTagName("changed")[0].childNodes[v].childNodes[j].firstChild.nodeValue;
							var oOption = document.createElement("OPTION");
							oOption.value=val;
		   					
							oOption.appendChild(document.createTextNode(val2));
							inp.appendChild(oOption);
   
						//str+="<option value=\""+val+"\">"+val2+"</option>";
						}
		 	  		
					}
				//alert("selectfield:"+inp.id);
				}
			}
		 
		 
		}
	//alert(xml.getElementsByTagName("changed")[0].childNodes[v].tagName);
	}



	if (xml!=null && xml.getElementsByTagName("action")[0]!=null && xml.getElementsByTagName("action")[0].childNodes[0].nodeValue=="clear")
	{
		var ch = xml.getElementsByTagName("action")[0].getAttribute('dataComponent');
		//alert(ch);
		for (var i=0;i<document.getElementsByTagName("input").length;i++){
		 	  	
			var inp = document.getElementsByTagName("input")[i];
			if (inp.getAttribute("dataComponent") == ch || inp.getAttribute("formDataComponent")==ch){
				inp.value="";
			}
		}
	
		for (var i=0;i<document.getElementsByTagName("select").length;i++){
		 	  	
			var inp = document.getElementsByTagName("select")[i];
			if (inp.getAttribute("dataComponent") == ch || inp.getAttribute("formDataComponent")==ch){
				inp.value="epilogi";
			}
		}
	
	}
}

function changePics() {

	var img1 = document.getElementById('imarr1');
  
 
	if (img1.src.indexOf('up')!=-1){
		img1.src = '../../../platonimages/images/down_arrow.gif';
  	
	}
	else {
		img1.src = '../../../platonimages/images/up_arrow.gif';
  	
	}
 
}

/*jQuery.jPrintArea=function(el)
{
var iframe=document.createElement('IFRAME');
var doc=null;
$(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links[i].rel.toLowerCase()=='stylesheet')
doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
doc.write('<div class="'+$(el).attr("class")+'">'+$(el).html()+'</div>');
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
alert('Printing...');
document.body.removeChild(iframe);
}*/

function printIt(elemdiv, scriptdiv, dcomp, comp) {
	var unit=document.getElementById("unit").value;
	var actor=document.getElementById("thisActorCode").value;
	var strParams="unit="+unit+"&actor="+actor+"&action=getPrintDialog&dataComponent="+dcomp+"&prScript="+scriptdiv+"&el="+elemdiv.id+"&pagecomp="+comp;
	var check_loader = new net.ContentLoader("main",onGotPrintDialog,null,"POST",strParams);
}

function onGotPrintDialog(){
	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	if(status[0].firstChild.nodeValue=='0'){
		var title=doc.getElementsByTagName("title")[0].firstChild.nodeValue;
		var content=doc.getElementsByTagName("content")[0].firstChild.nodeValue;
		var contentWin=new Window({id: "mainPrintDialog", className: 'windowStyle', title: title, hideEffect:Element.hide, showEffect:Element.show, minimizable:false,maximizable:false, resizable:false, wiredDrag: true, destroyOnClose: true, width:230, height:170, modal:true});
		contentWin.setHTMLContent(content);
		contentWin.showCenter();
	}else if(status[0].firstChild.nodeValue=='-1'){
		alert(message[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-4'){
		var uarl=doc.getElementsByTagName("url");
		window.location=uarl[0].firstChild.nodeValue;
	}
}

function choosePrint(obj, dComp, el, prscr){
	if(obj.selectedIndex==0){
		justPrint(document.getElementById(el), prscr);
	}else{
		var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+
		"<elements>"+
		"<actor>"+document.getElementById('thisActorCode').value+"</actor>"+
		"<unit>"+document.getElementById('unit').value+"</unit>"+
		"<pageAction>getReport</pageAction>"+
		"<action>getReport</action>"+
		"<dataComponent>"+dComp+"</dataComponent>"+
		"<report>"+obj.value+"</report>"+
		"<componentId>"+dComp+"</componentId>"+
		"</elements>";
		xmlString=xmlString.replace(/&/g,'&amp;');
		var loader1 = new  net.send("main", onGotReport,null, "POST",xmlString,"text/xml");
	}
	Windows.getWindow('mainPrintDialog').close();
}

function onGotReport(){
	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	var content = doc.getElementsByTagName("content");
	var printStr = content[0].childNodes[0].nodeValue
	var str = "";
	var win = window.open();
	self.focus();
	win.document.open();
	win.document.write("<html><head>"+str+"</head><body>"+printStr+"</body></html>");
	win.document.close();
	win.print();
	if(status[0].firstChild.nodeValue=='0'){
		var url = doc.getElementsByTagName("url");
		window.open(url[0].firstChild.nodeValue, '_blank');
	}else if(status[0].firstChild.nodeValue=='1'){
		alert(doc.getElementsByTagName("message")[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-1'){
	}else if(status[0].firstChild.nodeValue=='-4'){
		var uarl=doc.getElementsByTagName("url");
		window.location=uarl[0].firstChild.nodeValue;
	}
}

function justPrint(elemdiv, scriptdiv){
	elemDiv = jQuery(elemdiv).parent().parent().parent().parent().parent().parent();
	var str = "";
	var links=window.document.getElementsByTagName('link');
	for(var i=0;i<links.length;i++)
		if(links[i].rel.toLowerCase()=='stylesheet')
			str+='<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>';
	//doc.write('<div class="'+jQuery(el).attr("class")+'">'+jQuery(el).html()+'</div>');
	var sc=document.getElementById(scriptdiv);
	if(sc){
		var chart=sc.innerHTML.replace(/&gt;/g,">");
		str+='<script type="text/javascript" src="codebase/jquery/jquery-1.4.2.min.js"></script>'+
			'<script type="text/javascript" src="codebase/Highcharts-2.1.0/js/highcharts.js"></script>'+
			'<script type="text/javascript">jQuery(document).ready(function() { '+chart+' });</script>';
	}
	win = window.open();
	self.focus();
	win.document.open();
	win.document.write("<html><head>"+str+"<style>div{overflow:visible !important;}</style></head><body>"+elemDiv.html()+"</body></html>");
	win.document.close();
	win.print();
//win.close();
}

function encodeGreek(greekText){
	//alert(greekText);
	var clearString=greekText;
	clearString = escape(clearString);
	clearString = clearString.replace(/%u/g,"..u");
	clearString = clearString.replace(/%20/g," ");
	clearString = clearString.replace(/%2C/g,",");
	clearString = clearString.replace(/%/g,"");
	// alert(clearString);
	return clearString;
}

function getLogUsers(){
	var xmlUrl = "LogViewer";
	var strParams = "action=getLogUsers";
	var loader1 = new  net.ContentLoader(xmlUrl,getLogResponse,null, "POST",strParams);
}

function getLog(){
	var xmlUrl = "LogViewer";
	var fromd = document.getElementById('fromDate').value;
	var fromt = document.getElementById('fromTime').value;
	var tot = document.getElementById('toTime').value;
	var strParams = "fromDate="+fromd+"&fromTime="+fromt+"&toTime="+tot+"&tab="+selectedLogTab;
	var loader1 = new  net.ContentLoader(xmlUrl,getLogResponse,null, "POST",strParams);
}

function getLogResponse(){
	var doc =this.req.responseText;
	document.getElementById('logarea').innerHTML="<pre>"+doc+"</pre>";
}

function killServer( server ){
    var xmlUrl = "LogViewer";
	var strParams = "action=killServer&server="+server;
	var loader1 = new  net.ContentLoader(xmlUrl,alertResponse,null, "POST",strParams);    
}
function alertResponse()
{	
	alert(this.req.responseText);
}
var selectedLogTab="ApacheTab";

function openLogTab(tab){
	document.getElementById("logarea").innerHTML="";

	if(tab=="actorsbox"){
		var sel = document.getElementById(tab);
		var choice=sel.options[sel.selectedIndex].value;
		var pos=sel.options[sel.selectedIndex].id;
		var paged=parseInt(pos)/5;
		paged=parseInt(paged);
		tab=choice+"Tab";
		window.location="LogViewer?page="+paged+"&requestedActor="+tab;;
	}
	else{
		var sel = document.getElementById("actorsbox");
		//sel.options[sel.selectedIndex].value;
		sel.selectedIndex="none";
	}
	//alert(tab);
	//alert(selectedLogTab);
    
	if(selectedLogTab!==""){
		if(document.getElementById(selectedLogTab)!=null)
			document.getElementById(selectedLogTab).className=" ";
	}
	if(document.getElementById(tab)!=null)
		document.getElementById(tab).className="selected";
	
	selectedLogTab=tab;
	
	//Once the tab is selected. Fetch the contents
	getLog();
}

function viewField(field, set, row){
	var unit=document.getElementById('unit').value;
	var actor=document.getElementById('thisActorCode').value;
	var strParams = "actor="+actor+"&unit="+unit+"&action=viewField&pageAction=viewField&field="+field+"&set="+set+"&row="+row;
	var loader1 = new  net.ContentLoader("main",onViewField,null, "POST",strParams);
}

function onViewField(){
	
}

function fetchArticle(obj, frmId, id, table){
	var unit=document.getElementById('unit').value;
	var actor=document.getElementById('thisActorCode');
	if(actor){
		actor=actor.value;
	}else{
		actor=obj.getAttribute('actor');
	}
	var fieldName=obj.getAttribute('fldName');
	if (fieldName!=null && fieldName.indexOf(".")>=0)
		fieldName = fieldName.substring(fieldName.indexOf(".")+1,fieldName.length);
	var file="", date="", time="";
	if(obj.getAttribute('file')){
		file=obj.getAttribute('file');
		file=hexnorm(file);
	}
	if(obj.getAttribute('date')){
		date=obj.getAttribute('date');
		time=obj.getAttribute('time');
	}
	var action="main?actor="+actor+"&action=fetchArticle&pageAction=fetchArticle&field="+fieldName+"&unit="+unit+"&id="+id+"&table="+table+"&component=PlatonAction&file="+file+"&date="+date+"&time="+time;
	var frm=document.getElementById(frmId);
	frm.action=action;
	//alert(action);
	frm.submit();
}

/*function fetchArticle2(component, id,table,fieldName, obj){
	if (fieldName!=null && fieldName.indexOf(".")>=0)
		fieldName = fieldName.substring(fieldName.indexOf(".")+1,fieldName.length);
	var unit=document.getElementById('unit').value;
	var actor=document.getElementById('thisActorCode').value;
	var file="";
	if(obj){
		file=obj.getAttribute('file');
	}
	//alert("actor="+getParameter('actorCode')+"&action=fetchArticle&field="+fieldName+"&unit="+unit+"&id="+id+"&table="+table);
	//if (component!=null)
	//	var loader1 = new  net.ContentLoader("main",onFetchArticle,null, "POST","actor="+getParameter('actorCode')+"&action=fetchArticle&unit="+unit+"&id="+id+"&component="+component);
	//else
	//var loader1 = new  net.ContentLoader("main",onFetchArticle,null, "POST","actor="+getParameter('actorCode')+"&action=fetchArticle&field="+fieldName+"&unit="+unit+"&id="+id+"&table="+table);
	var loader1 = new  net.ContentLoader("main",onFetchArticle,null, "POST","actor="+actor+"&action=fetchArticle&pageAction=fetchArticle&field="+fieldName+"&unit="+unit+"&id="+id+"&table="+table+"&component=PlatonAction&file="+file);
}*/

function onFetchArticle(){
	var doc=this.req.responseXML;
	var status = doc.getElementsByTagName("status");
	var message = doc.getElementsByTagName("message");
	if(status[0].firstChild.nodeValue=='0'){
		var url = doc.getElementsByTagName("url")[0].firstChild.nodeValue;
		if(url.endsWith(".pdf") || url.endsWith(".txt") || url.endsWith(".html")){
			var win=window.open(url, '_blank');
		}else{
			var ifra=document.getElementById('uploadTrickFrame');
			ifra.src=url;
		}
	}else if(status[0].firstChild.nodeValue=='1'){
		alert(doc.getElementsByTagName("message")[0].firstChild.nodeValue);
	}else if(status[0].firstChild.nodeValue=='-1'){
	}else if(status[0].firstChild.nodeValue=='-4'){
		if(document.getElementById('postType')){
			if(document.getElementById('postType').value=='unitsMenu'){
				parent.processBlock();
				return;
			}
		}
		var uarl=doc.getElementsByTagName("url");
		window.location=uarl[0].firstChild.nodeValue;
	}
}

function sbmtLogin(){
	document.getElementById('loginForm').submit();
	jQuery("#mainTable").remove();
	
	var dv=document.createElement("div");
	document.body.appendChild(dv);
	jQuery(dv).html("<table style='height:100%; width:100%'>"+
						"<tr>"+
							"<td align='center'>"+
								"<object width='300' height='32' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>"+
									"<param value='../../../platonimages/servers/Bopen/images/loader.swf' name='movie'>"+
									"<param value='high' name='quality'>"+
									"<param value='transparent' name='wmode'>"+
									"<embed width='300' height='32' wmode='transparent' type='application/x-shockwave-flash' src='../../../platonimages/servers/Bopen/images/loader.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer'>"+
								"</object>"+
							"</td>"+
						"</tr>"+
					"</table>");
}

function slideToggle(el, bShow){
	if (jQuery(el).css('display')=="none")
	  jQuery(el).css('display','');
	else
		jQuery(el).css('display','none');
	/*
  var $el = jQuery(el), height = jQuery(el).data("originalHeight"), visible = $el.is(":visible");
  alert('after');
  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = jQuery(el).show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){
    jQuery(el).show().animate({height: height}, {duration: 250});
	//$el.show("normal");
  } else {
    jQuery(el).animate({height: 0}, {duration: 250, complete:function (){
        jQuery(el).hide();
      }
    });
  }*/
}

function slideToggleEl(el){
	if (jQuery('#'+el).css('display')=="none")
	  jQuery('#'+el).css('display','');
	else
		jQuery('#'+el).css('display','none');
}

function select(clas, obj){
	obj.className=clas;

}

function deselect(clas, obj){
	if(obj.getAttribute('selected')=='false'){
		obj.className=clas;
	}
}

function changeState(inpId, state){
	var inp=document.getElementById(inpId);
	document.getElementById(inpId+"_1").checked=false;
	document.getElementById(inpId+"_2").checked=false;
	//document.getElementById(inpId+"_3").checked=false;
	document.getElementById(inpId+"_"+state).checked=true;
	inp.setAttribute('state', state);
}

function stopEvents(e){
	if (!e)
		e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
	if (e.preventDefault)
		e.preventDefault();
	//e.returnValue = false;
}

function editMenu(obj, ulId){
	var lis=jQuery('#'+ulId+" li");
	var ul=document.getElementById(ulId);
	var length=lis.length;
	if(ul.getAttribute('edit')=="on"){
		jQuery(obj).next().next().css('display', 'none');
		jQuery(obj).parent().parent().css('height', null);
		for(var i=1; i<length; i++){
			jQuery(lis[i]).removeClass('selectedLi');
			//lis[i].setAttribute("onclick", "");
			lis[i].onclick="";
			var ihtml=lis[i].innerHTML;
			ihtml=ihtml.replace(/_onclick/g,"onclick");
			ihtml=ihtml.replace(/_href/g,"href");
			lis[i].innerHTML=ihtml;
		}
		ul.setAttribute('edit', 'off');
		var ni=document.getElementById('newMenuItem');
		if(ni){
			ni.id="";
		}
	}else{
		jQuery(obj).next().next().css('display', '');
		jQuery(obj).parent().parent().css('height', 80);
		for(var i=1; i<length; i++){
			//lis[i].setAttribute("onclick", "selectMenu(this, '"+ulId+"')");
			lis[i].onclick=function(){
					selectMenu(this, ulId)
				};
			var ihtml=lis[i].innerHTML;
			ihtml=ihtml.replace(/onclick/g,"_onclick");
			ihtml=ihtml.replace(/href/g,"_href");
			lis[i].innerHTML=ihtml;
		}
		ul.setAttribute('edit', 'on');
	}
}

function selectMenu(obj, ulId){
	var sli=getSelectedLi(ulId);
	if(sli){
		jQuery(sli).removeClass('selectedLi');
	}
	if(sli==obj){
		jQuery(obj).removeClass('selectedLi');
	}else{
		jQuery(obj).addClass('selectedLi');
	}
}

function getSelectedLi(ulId){
	var lis=jQuery('#'+ulId+" li");
	var length=lis.length;
	for(var i=1; i<length; i++){
		if(jQuery(lis[i]).hasClass('selectedLi')){
			return lis[i]
		}
	}
	return null;
}

function newMenuItem(obj, ulId){
	var win=Windows.getWindow('newMenuDialog');
	if(win){
		return;
	}
	var li=getSelectedLi(ulId);
	var level="";
	if(li){
		if(jQuery(li).hasClass("level1")){
			level="level2";
		}else if(jQuery(li).hasClass("level2")){
			//level="level2";
			level="level2";
		}
	}
	if(!li){
		jQuery(obj).parent().parent().parent().after("<li class='level1' onclick=\"selectMenu(this, '"+ulId+"')\"><a id='newMenuItem' ><span></span></a></li>");
	}else{
		jQuery(li).after("<li class='"+level+"' onclick=\"selectMenu(this, '"+ulId+"')\"><a id='newMenuItem' ><span></span></a></li>");
	}
	var content = "<div><form><table width='100%'><tr><td width='10%'>"+getMessage(5)+"</td><td><input id='menuText' type='text' /></td></tr><tr><td width='10%'>"+getMessage(6)+"</td><td><input id='menuUrl' type='text' style='width:350px'/></td></tr>"+
				"<tr><td></td><td align='right'><input type='button' value='"+getMessage(4)+"' onclick='setItemProperties(); Windows.getWindow(\"newMenuDialog\").close();' class='stylishBut'/>&nbsp;<input type='button' value='"+getMessage(3)+"' onclick='cancelnewItem(); Windows.getWindow(\"newMenuDialog\").close();' class='stylishBut'/></td></tr></table></form></div>";
	var contentWin=new Window({id: "newMenuDialog", className: 'alphacube', title: getMessage(8), hideEffect:Element.hide, showEffect:Element.show, minimizable:false,maximizable:false, resizable:true, wiredDrag: true, destroyOnClose: true, width:450, height:100, modal:true});
	contentWin.setHTMLContent(content);
	contentWin.showCenter();
}

function setItemProperties(){
	var mitem=document.getElementById("newMenuItem");
	if(mitem){
		var a=mitem;
		a.innerHTML="<span>"+document.getElementById("menuText").value+"</span>";
		var uarl=document.getElementById("menuUrl").value;
		if(uarl==""){
			uarl="javascript:void(0);";
		}
		a.setAttribute('_href', uarl);
		mitem.id="";
	}
}

function cancelnewItem(){
	jQuery('#newMenuItem').parent().remove();
}

function deleteMenuItem(obj, ulId){
	var li=getSelectedLi(ulId);
	if(!li){
		return;
	}
	//var ok = confirm("Delete this menuItem?");
	var ok = confirm(getMessage(2));
	if (ok == false) {
		return;
	}
	jQuery(li).remove();
}

function moveItem(obj, ulId, orient){
	var li=getSelectedLi(ulId);
	if(!li){
		return;
	}
	if(orient=="up"){
		var prev=jQuery(li).prev();
		if(prev.attr('id')!="actionLi"){
			prev.before(li);
		}
	}else{
		var next=jQuery(li).next().after(li);
	}
}

function editMenuItem(obj, ulId){
	var li=getSelectedLi(ulId);
	if(!li){
		return;
	}
	var win=Windows.getWindow('newMenuDialog');
	if(win){
		return;
	}
	var a=li.childNodes[0];
	a.id="newMenuItem";
	var content = "<div><form><table width='100%'><tr><td width='10%'>"+getMessage(5)+"</td><td><input id='menuText' type='text' value='"+a.childNodes[0].innerHTML+"'/></td></tr><tr><td width='10%'>"+getMessage(6)+"</td><td><input id='menuUrl' type='text' style='width:350px' value='"+a.getAttribute('_href')+"'/></td></tr>"+
				"<tr><td></td><td align='right'><input type='button' value='"+getMessage(4)+"' onclick='setItemProperties(); Windows.getWindow(\"newMenuDialog\").close();' class='stylishBut'/>&nbsp;<input type='button' value='"+getMessage(3)+"' onclick='document.getElementById(\"newMenuItem\").id=\"\"; Windows.getWindow(\"newMenuDialog\").close();' class='stylishBut'/></td></tr></table></form></div>";
	var contentWin=new Window({id: "newMenuDialog", className: 'alphacube', title: getMessage(7), hideEffect:Element.hide, showEffect:Element.show, minimizable:false,maximizable:false, resizable:true, wiredDrag: true, destroyOnClose: true, width:450, height:100, modal:true});
	contentWin.setHTMLContent(content);
	contentWin.showCenter();
}

function saveMenu(obj, ulId, recId, s){
	var ul=document.getElementById(ulId);
	if(ul.getAttribute('edit')=="on"){
		editMenu(jQuery(obj).prev(), ulId);
	}
	var lis=jQuery('#'+ulId+" li");
	var length=lis.length;
	var menuData="";
	var start="true";
	var elements=new Array()
	var index=0;
	for(var i=1; i<length; i++){
		var iindex=0;
		if(jQuery(lis[i]).hasClass('level1')){
			var tmpArray=new Array();
			var a=lis[i].childNodes[0];
			var oncl=a.getAttribute('onclick');
			//var oncl=jQuery(a).attr('onclick');
			var m="";
			if(oncl){
				oncl=oncl+"";
				if(oncl.indexOf("function onclick()")!=-1){
					oncl=oncl.substring(oncl.indexOf("{")+1, oncl.lastIndexOf("}"));
				}
				m=a.childNodes[0].innerHTML+" click="+oncl;
			}else{
				var hr=a.href;
				m=a.childNodes[0].innerHTML+" link="+hr;
			}
			tmpArray[iindex]=m;
			iindex+=1;
			for(var j=i+1; j<length; j++){
				if(jQuery(lis[j]).hasClass('level1')){
					break;
				}
				var a=lis[j].childNodes[0];
				oncl=a.getAttribute('onclick');
				//oncl=jQuery(a).attr('onclick');
				var m="";
				if(oncl){
					oncl=oncl+"";
					if(oncl.indexOf("function onclick()")!=-1){
						oncl=oncl.substring(oncl.indexOf("{")+1, oncl.lastIndexOf("}"));
					}
					m=a.childNodes[0].innerHTML+" click="+oncl;
				}else{
					var hr=a.href;
					m=a.childNodes[0].innerHTML+" link="+hr;
				}
				tmpArray[iindex]=m;
				iindex+=1;
			}
			elements[index]=tmpArray;
			index+=1;
		}
	}
	for(var i=0; i<elements.length; i++){
		menuData+="{";
		for(var j=0; j<elements[i].length; j++){
			menuData+=elements[i][j];
			if(j!=elements[i].length-1){
				menuData+=",";
			}
		}
		menuData+="}";
	}
	//alert(menuData);
	quickSave(recId, menuData, s);
}

function fixForm(formId, index, width){
	var form=document.getElementById(formId);
	var jqform=jQuery('#'+formId);
	if(!form){
		return;
	}
	if(width==-1){
		var par=jqform.parent();
		do{
			par=par.parent();
		}while(par.get(0).tagName.toLowerCase()!="td" && par.attr('id').indexOf('m')!=0);
		width=par.width();
	}else if(width==-2){
		width=EDIT_DIALOG_WIDTH;
	}
	var ftable;
	var number=parseInt(index);
	if(isNaN(number)){
		ftable=jqform.find('#'+index+' .diaTable');
	}else{
		if(number==-1){
			ftable=jqform.find('.diaTable');
		}else{
			ftable=jqform.find('.diaTable:eq('+number+')');
		}
	}
	width=width-15;
	for(var i=0; i<ftable.length; i++){
		var trows=ftable[i].tBodies[0].rows;
		for(var r=0; r<trows.length; r++){
			var rwidth=0;
			var tcells=trows[r].cells;
			var widths=new Array();
			var inputs=new Array();
			var ind=0;
			for(var c=0; c<tcells.length; c++){
				var inp=jQuery(tcells[c]).find('input');
				var lab=jQuery(tcells[c]).find('label');
				var img=jQuery(tcells[c]).find('img');
				if(inp.length>0){
					if (jQuery(inp[0]).width()>=jQuery(tcells[c]).width()){
						widths[ind]=jQuery(inp[0]).width();
						inputs[ind]=inp[0];
						ind++;
						rwidth+=jQuery(inp[0]).width();
					}else{
						widths[ind]=jQuery(inp[0]).width();

						inputs[ind]=inp[0];
						ind++;
						rwidth+=jQuery(tcells[c]).width()
					}
				}
				if(lab.length>0){
					rwidth+=jQuery(tcells[c]).width();
				}
			}
			sortTables(widths,inputs);
			if(jqform.width()-20<rwidth){
				var substracted=0;var temp=0;
				for(var c=inputs.length-1; c>=0; c--){
					temp=0;
					var inp=inputs[c];
					if (inp.getAttribute('size')>50){
						temp = jQuery(inp).width();
						inp.setAttribute('size', "50");
						substracted+=parseInt(temp - jQuery(inp).width());
					}
					rwidthtemp = parseInt(rwidth - substracted);
					if(width-20	>=rwidthtemp)
						break;
				}
			}
		}
	}
	form.setAttribute('fixed', 'true');
}

function sortTables(table1,table2){
	
	for (var i = table1.length - 1; i >= 0;  i--) {
		for (var j = 0; j <= i; j++) {
			if (table1[j+1] < table1[j]) {
				var tempValue = table1[j];
				table1[j] = table1[j+1];
				table1[j+1] = tempValue;
				
				tempValue = table2[j];
				table2[j] = table2[j+1];
				table2[j+1] = tempValue;
			 }
		}
	}
}

var tgList="";
var exList="";

function closeLookupDivs(idd, type){
	//jQuery("div .dropDownList[class='dropDownList'][id!='"+idd+"']").remove();
	//jQuery("div .dropDownList[class~='static'][id!='"+idd+"']").css('display','none');
	var l1=document.getElementById(tgList);
	var l2=document.getElementById(exList);
	if(l1){
		jQuery(l1).remove();
	}
	if(l2){
		jQuery(l2).css('display', 'none');
	}
	f_tcalHideAll();
	if(type==1){
		tgList=idd;
		exList="";
	}else if(type==2){
		exList=idd;
		tgList="";
	}
}

function keepAlive(){
	var actor=document.getElementById('thisActorCode').value;
	var unit=document.getElementById('unit').value;
	var strParams="actor="+actor+"&unit="+unit+"&action=keepAlive";
	new  net.ContentLoader("main",function(){},errorState,"POST",strParams);
}

function errorState(){
	alert(getMessage(44));
}
/*function IESettingsWindow() {
	var contentWin = new Window({id: "IESettingsWindow", className: 'alphacube', title: getMessage(40), hideEffect:Element.hide, showEffect:Element.show, minimizable:false, maximizable:false, resizable:true, wiredDrag: true, destroyOnClose: true, width:400, height:300, modal:true});
	contentWin.setHTMLContent(getMessage(39));
	contentWin.showCenter();
}*/

			/******************************
					List functions
			*******************************/

function setListValue(inpId, val, code, remove){
	var inp=document.getElementById(inpId);
	inp.value=val;
	inp.setAttribute('value', norm(inp.value));
	inp.setAttribute('code', code);
	if(remove=="true"){
		jQuery('#'+jQid(inpId)+'_ddList').remove();
	}else{
		jQuery('#'+jQid(inpId)+'_ddList').css('display', 'none');
	}
	var validate=inp.getAttribute('validate');
	if(validate!=null && validate!=""){
		validateFieldId(inpId, validate);
	}else{
		//checkDflt(inp, true); //not used pros to paron
		jQuery(inp).trigger("valueChangedEvent");
	}
}

function removeList(inpId){
	if(document.getElementById(inpId).getAttribute('state')=='1'){
		jQuery('#'+jQid(inpId)+'_ddList').remove();
	}
}

function toggleList(inpId, listId){
	var list=jQuery('#'+jQid(listId));
	if(list.css('display')!='none'){
		list.css('display','none');
		return;
	}
	closeLookupDivs(jQid(listId), 2);
	var jq=jQuery('#'+jQid(inpId));
	if(jq.attr('disabled')==true){
		return;
	}
	var offset = jq.offset();
	var pos = jq.position();
	var extratop=6; //for paddings etc...
	var topOffset=jq.offsetParent().scrollTop();
	if(browserName.search("Internet Explorer")!=-1){
		if(jq.hasClass('prdInput')){
			list.css('left', pos.left);
			jQuery(list).css('top', pos.top+jq.height()+extratop);
		}else if(list.hasClass('static')){
			list.css('left', pos.left);
			jQuery(list).css('top', pos.top+jq.height()+extratop);
		}else{
			list.css('left', pos.left);
			jQuery(list).css('top', pos.top+jq.height()+extratop+2);
		}
	}else{
		list.css('left', pos.left);
		list.css('top', topOffset+pos.top+jq.height()+extratop);
	}
	list.css('width', jq.width()+18);
	list.css('z-index','10');
	list.css('display','block');
	/*jq.focus();*/
}

var listTable;
var position=-1;
var overlist;

function listFunctions(listId){
	listTable=null;
	overlist=null;
	position=-1;
	var ltables=jQuery('#'+listId+' table');
	if(ltables.length>0){
		listTable=ltables[0];
	}
	jQuery('#'+listId).unbind('mouseover').bind('mouseover', function(event){overlist=true});
	jQuery('#'+listId).unbind('mouseout').bind('mouseout', function(event){overlist=false});
	jQuery(document).unbind('keydown').bind('keydown', function(event){checkListKey(listId, event);});
	jQuery(document).unbind('mousedown').bind('mousedown', function(){if(!overlist){closeList(listId);}});
}

function checkListKey(list, e){
	if (!e) var e = window.event;
	var scrll=jQuery('#'+list);
	if(!scrll.hasClass('inlst')){
		scrll=jQuery(scrll.children()[0]);
	}
	if(e.keyCode==40){//down arrow
		if(position<listTable.rows.length-1){
			jQuery(listTable.rows[position+1]).mouseover();
			scrll.scrollTop(scrll.scrollTop()+jQuery(listTable.rows[position+1]).position().top);
			if(position>=0){
				jQuery(listTable.rows[position]).mouseout();
			}
			position++;
		}
		
		if (e.preventDefault){
			e.preventDefault();
		}else{
			e.returnValue = false;
		}
	}else if(e.keyCode==38){//up arrow
		if(position>=1){
			jQuery(listTable.rows[position-1]).mouseover();
			scrll.scrollTop(scrll.scrollTop()+jQuery(listTable.rows[position-1]).position().top);
			jQuery(listTable.rows[position]).mouseout();
			position--;
		}
		if (e.preventDefault){
			e.preventDefault();
		}else{
			e.returnValue = false;
		}
	}else if(e.keyCode==13){//enter key
		if(position>=0){
			jQuery(document).unbind('keydown').unbind('mousedown');
			jQuery(listTable.rows[position]).mouseout();
			jQuery(listTable.rows[position]).click();
			stopEvents(e);
			jQuery('#'+list.replace(/_ddList/,'')).focus();
			closeList(list);
		}
	}else if(e.keyCode==37){//left arrow
		if(position>=0 && position<listTable.rows.length){
			var jq=jQuery(listTable.rows[position]);
			var parent=jQuery('#'+jq.attr('parentId'));
			if(parent.attr('hasSub')=='true'){
				if(jq.attr('level')!=0){
					position=parent.get(0).sectionRowIndex;
					jQuery(listTable.rows[position]).mouseover();
					scrll.scrollTop(scrll.scrollTop()+jQuery(listTable.rows[position]).position().top);
				}
				var tc=parent.find('img')[0];
				jQuery(tc).click();
				stopEvents(e);
			}
		}
	}else if(e.keyCode== 39){//right arrow
		if(position>=0 && position<listTable.rows.length){
			var jq=jQuery(listTable.rows[position]);
			if(jq.attr('hasSub')=='true'){
				var tc=jq.find('img')[0];
				jQuery(tc).click();
				stopEvents(e);
			}
		}
	}else if(e.keyCode==27){//escape
		 closeList(list);
		 jQuery('#'+list.replace(/_ddList/,'')).focus();
	}
}

function closeList(list){
	//if (!e) var e = window.event;
	var lilist=document.getElementById(list);
	if(lilist){
		var jq=jQuery(lilist);
		jq.unbind('mouseover').unbind('mouseout');
		if(jq.hasClass('static')){
			jq.css('display','none');
		}else{
			jq.remove();
		}
	}
	jQuery(document).unbind('keydown').unbind('mousedown');
	listTable=null;
	overlist=null;
	position=-1;
}

function swapImage(img_id , img_src){

	jQuery('#'+img_id).attr("src" , img_src);

}

function freeSpace(id){
	var element;
	if(typeof id == "string"){
		element=jQuery('#'+id);
	}else{
		element=id;//jQuery object
	}
	var visible=false;
	if(element.is(':visible')){
		element.css('display', 'none');
		visible=true;
	}
	var parent=element.parent();
	var height=parent.height();
	var innerHeight=0;
	parent.children().each(function(){
		var thisel=jQuery(this);
		if(this!=element.get(0) && thisel.is(':visible')){
			innerHeight+=thisel.outerHeight();
		}
	});
	var ppadtop=parseInt(parent.css('padding-top').replace("px", ""));
	var ppadbot=parseInt(parent.css('padding-bottom').replace("px", ""));
	var elppadtop=parseInt(element.css('padding-top').replace("px", ""));
	var elpadbot=parseInt(element.css('padding-bottom').replace("px", ""));
	var bordtop=parseInt(element.css('borderTopWidth').replace("px", ""));
	if(isNaN(bordtop)){
		bordtop=0;
	}
	var bordbot=parseInt(element.css('borderBottomWidth').replace("px", ""));
	if(isNaN(bordbot)){
		bordbot=0;
	}
	var margtop=parseInt(element.css('marginTop').replace("px", ""));
	if(isNaN(margtop)){
		margtop=0;
	}
	var margbot=parseInt(element.css('marginBottom').replace("px", ""));
	if(isNaN(margbot)){
		margbot=0;
	}
	var heiLeft=height-innerHeight-ppadtop-ppadbot-elppadtop-elpadbot-bordtop-bordbot-margtop-margbot;
	if(visible){
		element.css('display', '');
	}
	return [heiLeft, parent.width()];
}

function windowFormat(tabs, content, buttons, height){
	var str="";
	if(tabs!=""){
		str+="<div class='tabmenu'>"+tabs+"</div><div style='clear:both;'></div>";
	}
	if(content!=""){
		str+="<div class='fwrpNoscrl'";//fwrp
		if(height!=""){
			str+=" style='height: "+height+"' ";
		}
		str+=">"+content+"</div>";
	}
	if(buttons!=""){
		str+="<div class='alertButtonsArea' style='text-align:right;'>"+buttons+"</div>";
	}
	return str;
}













/*****************************READY.JS*********************/
jQuery(document).ready(function(){

	if(document.getElementById("linksContent") != null){
		clearAll();
	}
	if(document.getElementById('unit')){
		window.name=document.getElementById('unit').value;
	}
	if(document.getElementById("device") && document.getElementById("device").value=="pc"){
		device="pc";
	}else if(document.getElementById("device") && document.getElementById("device").value=="mobile"){
		device="mobile";
	}
	if ((screen.width==1024) && (screen.height==768)){
		DEFAULT_WIDTH = 650;
		DEFAULT_HEIGHT = 450;
		var style="<style type='text/css'>"+
					"table tr td {font: normal 11px Tahoma;}"+
					".actionBut{font-size:11px;}"+
					"</style>";
		jQuery('head').append(style);
	}else if ((screen.width==800) && (screen.height==600)){
		DEFAULT_WIDTH = 550;
		DEFAULT_HEIGHT = 350;
		var style="<style type='text/css'>"+
					"table tr td {font: normal 10px Tahoma;}"+
					".actionBut{font-size:10px;}"+
					"</style>";
		jQuery('head').append(style);
	}else if ((screen.width<800) || (screen.height<600)){
		var style="<style type='text/css'>"+
					"table tr td {font: normal 10px Tahoma;}"+
					".actionBut{font-size:9px;}"+
					".unitsMenu li {padding:5px 3px;}"+
					"</style>";
		jQuery('head').append(style);
		DEFAULT_WIDTH = 550;
		DEFAULT_HEIGHT = 350;
	}
	if (document.getElementById("units")){
		//fixMenu('units');
		var as = jQuery("#scrollMenu").find("a");
		for (var i=0;i<as.length;i++){
			var jq=jQuery(as[i]);
			jq.css('width', jq.innerWidth());
		}
		if(device=="pc"){
			jQuery("#scrollMenu").smoothDivScroll({startAtElementId: "selectedMenuItem", scrollStep: 1, scrollInterval: 5, visibleHotSpots: "always"});
		}else if(device=="mobile"){
			jQuery("#scrollMenu").smoothDivScroll({startAtElementId: "selectedMenuItem", scrollStep: 20, scrollInterval: 5, visibleHotSpots: "always"});
		}
	}
	if (document.getElementById("chatContent") != null) {
		getChatMessage();
		getChatMessageGlobal();
	}
	if(document.getElementById('user') && document.getElementById('user').value!="anonymous"){
		setInterval("keepAlive()", 120000);
	}
	var imgs = jQuery("#m103").find("img[alttext='image']");
	if (document.getElementById('m103')==null)
		return;
	var parw = document.getElementById("m103").scrollWidth;//jQuery("#m103").css('width');
	for (var i=0;i<imgs.length;i++){
		var tw = jQuery(imgs[i]).css('width');
		//if (parseInt(tw) >= (parseInt(parw)-2)){
			jQuery(imgs[i]).css('width',(parseInt(parw)-3))
			//alert('inside');
		//}
	}
		
});
/****************************************/


/******************WINFUNCT.JS*********************/
var EDIT_DIALOG_WIDTH = 600;
var EDIT_DIALOG_HEIGHT = 500;
var DEFAULT_WIDTH = 720;
var DEFAULT_HEIGHT = 560;

if(typeof(Windows) !== 'undefined') {
	Object.extend(Windows, {
	  // Overide minimize function
	  close: function(id, event) {
		var win = this.getWindow(id)
		if (win && win.visible) {
			if(window.f_tcalHideAll){
				f_tcalHideAll();
			}
			if(id=="main_message_div_Window"){
				if(isNull_Message()){ //apo sendSMSServlet
					win.destroy();
				}else{
					confirmClose(id);
				}
			}else{
				win.hide();
			}
		}
	  }
	});
}

function addWindow(id, wintitle){
	var contentWin=Windows.getWindow(id+"_Window");
	if (contentWin) {
		//contentWin.show();
		return;
	} else {
		//contentWin = new Window({maximizable: false, resizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, destroyOnClose: true});
		//contentWin=new Window({id: id+"_Window", className: 'alphacube', title: wintitle, hideEffect:Element.hide, minimizable:false,maximizable:false,showEffect:Element.show, wiredDrag: true, top:50, left:150, width:850, height:620, minWidth:850});
		contentWin=new Window({id: id+"_Window", className: 'windowStyle', title: wintitle, hideEffect:Element.hide, minimizable:false,maximizable:false,showEffect:Element.show, wiredDrag: true, recenterAuto:false, top:50, left:150, width:DEFAULT_WIDTH, height:DEFAULT_HEIGHT, minWidth:250});
		contentWin.setContent(id, false, false);
		/*myObserver = {
			onClose: function(eventName, win) {
				if (win == contentWin) {
					//contentWin = null;
					Windows.removeObserver(this);
				}
			}
			onDestroy: function(eventName, win) {
				if (win == contentWin) {
					//$(id+'_container').appendChild($(id));
					contentWin = null;
					Windows.removeObserver(this);
				}
				//debug(eventName + " on " + win.getId()) 
			}
		}*/
		//Windows.addObserver(myObserver);
	}
}

function confirmClose(aid){
	var win=Windows.getWindow("messageConfirm");
	if(win){
		return;
	}
	var confwin=new Window({id: "messageConfirm",className: 'windowStyle',title:getMessage(16),minimizable:false,maximizable:false,closable:false, resizable:false, recenterAuto:false, destroyOnClose: true,width:380,height:80});
	var contents="<div><br/><div style='text-align:center;'>"+getMessage(17)+"</div>"+
		"<div class='winBLink'>"+
		"<table width='100%'><tr><td align='center'>"+
		" <input type='button' value='"+getMessage(18)+"' class='stylishBut' onclick=\"if(!validateForSave()){Windows.getWindow('messageConfirm').destroy(); return false;} sbmtFRMSave('smsForm'); Windows.getWindow('messageConfirm').destroy(); Windows.getWindow('"+aid+"').destroy();\" />"+
		" <input type='button' value='"+getMessage(19)+"' class='stylishBut' onclick=\"Windows.getWindow('messageConfirm').destroy(); Windows.getWindow('"+aid+"').destroy();\" />"+
		" <input type='button' value='"+getMessage(3)+"' class='stylishBut' onclick=\"Windows.getWindow('messageConfirm').destroy();\" />"+
		"</td></tr></table></div></div>";
	confwin.setHTMLContent(contents);
	confwin.showCenter();
}

function addWindowWithProperties(id, wintitle,width,height,minim,maxim){
	var contentWin=Windows.getWindow(id+"_Window");
	if (contentWin) {
		//contentWin.show();
		return null;
	} else { 
		//contentWin = new Window({maximizable: false, resizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, destroyOnClose: true});
		contentWin=new Window({id: id+"_Window", className: 'windowStyle', title: wintitle, hideEffect:Element.hide, minimizable:minim,maximizable:maxim,showEffect:Element.show, recenterAuto:false, resizable:false, wiredDrag: true, destroyOnClose: true, top:50, left:150, width:width, height:height, modal:true});
		contentWin.setContent(id, false, false)
		/*myObserver = {
			onDestroy: function(eventName, win) {
				if (win == contentWin) {
					//$(id+'_container').appendChild($(id));
					contentWin = null;
					Windows.removeObserver(this);
				}
			}
		}
		Windows.addObserver(myObserver);*/
	}
	return contentWin;
}

function addWindowWithContent(id, content, wintitle,width,height,minim,maxim){
	var contentWin=Windows.getWindow(id+"_Window");
	if (contentWin) {
		return null;
	} else { 
		contentWin=new Window({id: id+"_Window", className: 'windowStyle', title: wintitle, hideEffect:Element.hide, minimizable:minim,maximizable:maxim,showEffect:Element.show, recenterAuto:false, resizable:false, wiredDrag: true, destroyOnClose: true, top:50, left:150, width:width, height:height, modal:true});
		contentWin.setHTMLContent(content);
	}
	return contentWin;
}

/******************************************/

/*******/
//gia hover. irthe apo to webcalendar.js
function hoveron(obj){
		var jq=jQuery(obj);
		if ( !jq.hasClass('calendarTdOver') && (jq.hasClass('calendarTd')) ){
			jq.addClass('calendarTdOver');
		}
		else if (jq.hasClass('workCalendarTd')){
			jq.addClass('workCalendarTdOver');
			jq.removeClass('workCalendarTd');
		}
		else if (jq.hasClass('tday')){
			jq.addClass('tdayOver');
			jq.removeClass('tday');
		}
		else if (jq.hasClass('RecWidgetClass')){
			jq.addClass('RecWidgetClassOver');
			jq.removeClass('RecWidgetClass');
		}
	}
	
function hoveroff(obj){
	var jq=jQuery(obj);
	if (jq.hasClass('calendarTdOver')){
		jq.removeClass('calendarTdOver');
	}
	else if (jq.hasClass('workCalendarTdOver')){
		jq.removeClass('workCalendarTdOver');
		jq.addClass('workCalendarTd');
	}
	else if (jq.hasClass('tdayOver')){
		jq.removeClass('tdayOver');
		jq.addClass('tday');
	}
	else if (jq.hasClass('RecWidgetClassOver')){
		jq.removeClass('RecWidgetClassOver');
		jq.addClass('RecWidgetClass');
	}
}

function hoverdown(obj){

	var jq=jQuery(obj);
		
	
		if (jq.hasClass('RecWidgetClassSelect')){
			jq.removeClass('RecWidgetClassSelect');
			jq.addClass('RecWidgetClassOver');
			jQuery('#b'+(obj.id).substring(1)).css('display','none');
		}
		else if (jq.hasClass('RecWidgetClassOver')){
			jq.removeClass('RecWidgetClassOver');
			jq.addClass('RecWidgetClassSelect');
			jQuery('#b'+(obj.id).substring(1)).css('display','inline');
		}
		else
			if(jq.hasClass('workCalendarTdSelect')){
				jq.removeClass('workCalendarTdSelect');
			}
		else
			jq.addClass('workCalendarTdSelect');
}

function fillInfoDialog(id, title, showhelp){
	jQuery(document).ready(function(){
		var content=document.getElementById(id+"_wrapper");
		var contentWin=new Window({id: id+'_dialog_Window', className: 'windowStyle', title: title, hideEffect:Element.hide, showEffect:Element.show, minimizable:false,maximizable:false, resizable:false, recenterAuto:false, closable:false, wiredDrag: false, width:560, height:380, modal:true, top:50, left:150});
		contentWin.setHTMLContent(content.innerHTML);
		document.getElementById(id+'_form').reset();
		var myObserver = {
			onClose : function(eventName, win1) {
				if (win1 == contentWin) {
					contentWin.destroy();
					Windows.removeObserver(this);
					if(showhelp!="false"){
						openHelp();
					}
				}
			}
		}
		Windows.addObserver(myObserver);
		contentWin.showCenter(true);
		jQuery(content).remove();
	});
}

/******/

