function fixIframes(){	//function that parses page to find richeditors and put the values in the appropriate hidden fields
	var selectCollection;
	iframeCollection=document.getElementsByTagName("IFRAME");
	for (var i=0;i<iframeCollection.length;i++) {
		if (iframeCollection[i].id.substring(0,10)=='richEditor'){
			theFieldName=iframeCollection[i].id.substring(11,iframeCollection[i].id.length);
			eval(iframeCollection[i].id+'.hideBordertbl()');
			eval(iframeCollection[i].id+'.replaceWords()');
			toggleEdit(eval(iframeCollection[i].id+'.idContent.document.body'));
			eval(iframeCollection[i].id+'.removeDomainInfo()');
			theIFrameContent=eval(iframeCollection[i].id+".idContent.document.body.innerHTML");
			tmp = eval(iframeCollection[i].id+".requestReplaces");			
			
			eval("document.forms[0]."+theFieldName+".value=theIFrameContent");
			var tmp2 = eval("document.forms[0]." + theFieldName + ".value");
			
			for(var j = 0; j < tmp.length; j++) {			
				//tmp2 = replace2(tmp2, tmp[j].split('-*-')[0], tmp[j].split('-*-')[1]);
				rep = '/' + tmp[j].split('-*')[0] + '/gi';
				tmp2.replace(rep, tmp[j].split('-*-')[1]);
				
			}
			
			eval("document.forms[0]." + theFieldName + ".value=tmp2");
			
		}
	}

	var src = document.forms[0];
	for(var i = 0; i < src.elements.length; i++) {
		if(src.elements[i].getAttribute("richEditor", false) == 'true') {
			// Found, manage content
			setContent();		
			break;
		}
	}
}

function toggleEdit(oObj){
	oObj.contentEditable = false;
}

function addDate(dName,mName,yName,selD,selM,selY,yearRange,required) {
	var d=dName;var m=mName;var y=yName;var i,yearStart,yearEnd;	

	document.write('<select name="'+d+'" class="flat" class="flat" isDate="true" required="'+required+'" kindOf="realize" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=1;i<=31;i++){if (i==selD)document.write('<option value="'+i+'" selected>'+i+'</option>'); else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>/ ');

	document.write('<select name="'+m+'" class="flat" class="flat" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=1;i<=12;i++){if (i==selM)document.write('<option value="'+i+'" selected>'+i+'</option>');else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>/ ');
	
	if (yearRange.length>5){
			yearStart=yearRange.substring(0,yearRange.indexOf('-'));
			yearEnd=yearRange.substring(yearRange.indexOf('-')+1,yearRange.length);
	}
	else{
			yearStart=1990;
			yearEnd=2010;
	}		

	document.write('<select name="'+y+'" class="flat" class="flat" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=yearStart;i<=yearEnd;i++){if (i==selY)document.write('<option value="'+i+'" selected>'+i+'</option>');else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>')
}

function addDateTime(dName,mName,yName,hName,minName,selD,selM,selY,selH,selMin,yearRange,required) {
	var d=dName;var m=mName;var y=yName;var h=hName;var mn=minName;var i,yearStart,yearEnd;

	document.write('<select name="'+d+'" class="flat" class="flat" isDate="true" required="'+required+'" kindOf="realize" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=1;i<=31;i++){if (i==selD)document.write('<option value="'+i+'" selected>'+i+'</option>'); else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>/ ');

	document.write('<select name="'+m+'" class="flat" class="flat" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=1;i<=12;i++){if (i==selM)document.write('<option value="'+i+'" selected>'+i+'</option>');else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>/ ');
	
	if (yearRange.length>5){
			yearStart=yearRange.substring(0,yearRange.indexOf('-'));
			yearEnd=yearRange.substring(yearRange.indexOf('-')+1,yearRange.length);
	}
	else{
			yearStart=1990;
			yearEnd=2010;
	}		

	document.write('<select name="'+y+'" class="flat" class="flat" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=yearStart;i<=yearEnd;i++){if (i==selY)document.write('<option value="'+i+'" selected>'+i+'</option>');else document.write('<option value="'+i+'">'+i+'</option>')}		
	document.write('</select>&nbsp;&nbsp;')

	document.write('<select name="'+h+'" class="flat" class="flat" required="'+required+'" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=0;i<=23;i++){if (i==selH)document.write('<option value="'+i+'" selected>'+(i<10?'0':'')+i+'</option>');else document.write('<option value="'+i+'">'+(i<10?'0':'')+i+'</option>')}		
	document.write('</select>:')
	document.write('<select name="'+mn+'" class="flat" class="flat" required="'+required+'" onFocus="this.style.background=\''+formcolor+'\';" onBlur="this.style.background=\'#FFFFFF\';"><option value="Error">-</option>');
	for(i=0;i<=59;i++){if (i==selMin)document.write('<option value="'+i+'" selected>'+(i<10?'0':'')+i+'</option>');else document.write('<option value="'+i+'">'+(i<10?'0':'')+i+'</option>')}		
	document.write('</select>')
}

function checkDate(i) {
	var flag;var j=i;var mes="Δεν συμπληρώσατε σωστή ημερομηνία\r ";var msg1="Ό μήνας που επιλέξατε έχει";var msg2="Πρέπει να συμπληρώσετε ";
	var msg,msg3;var d=document.forms[0].elements[j].value;var m=document.forms[0].elements[j+1].value;var y=document.forms[0].elements[j+2].value;
		if (d!="Error"){
			if (m!="Error"){
				if (y!="Error"){
					if (m==2){
						if  (d >= 30 &&  parseInt(y) % 4 == 0){
							dateerror=1;window.alert(mes+msg1+" 29 ημέρες");document.forms[0].elements[j].value=29;return false;}
						if (d >= 29 &&  parseInt(y) % 4 !== 0){dateerror=1;	window.alert(mes+msg1+" 28 ημέρες");document.forms[0].elements[j].value=28;return false;}}
						if ((d >= 31) && ((m == 4) || (m == 6) || (m == 9) || (m == 11))){dateerror=1;window.alert(mes+msg1+" 30 ημέρες");document.forms[0].elements[j].value=30;return false;}
					}
				}
			}
	if (!((d=="Error") && (m=="Error") && (y=="Error"))){
		if (d=="Error"){		
			if ((m!="Error")&&(y!="Error")){msg3='ημέρα';}
			if ((m=="Error")&&(y!="Error")){msg3='ημέρα και μήνα';}
			if ((m!="Error")&&(y=="Error")){msg3='ημέρα και έτος';}
			dateerror=1;window.alert(mes+msg2+msg3);return false;}
		if ((d!="Error") && ((m=="Error")||(y=="Error"))){
			if ((m=="Error")&&(y=="Error")){msg3="μήνα και έτος";}
			if ((m!="Error")&&(y=="Error")){msg3="έτος";}
			if ((m=="Error")&&(y!="Error")){msg3="μήνα";}
			dateerror=1;window.alert(mes+msg2+msg3);return false;}}
}

function dateCheck(theDate){
	var flag;var j=i;var mes="Δεν συμπληρώσατε σωστή ημερομηνία\r ";var msg1="Ό μήνας που επιλέξατε έχει";var msg2="Πρέπει να συμπληρώσετε ";
	var msg,msg3;
	var d=theDate.substring(0,theDate.indexOf('/'));
	var m=theDate.substring(theDate.indexOf('/')+1,theDate.lastIndexOf('/'));
	var y=theDate.substring(theDate.lastIndexOf('/')+1,theDate.length);
	if (!(isNaN(d)) && !(isNaN(m)) && !(isNaN(y))){
						if (d!="Error"){
							if (m!="Error"){
								if (y!="Error"){
									if (m==2){
										if  (d >= 30 &&  parseInt(y) % 4 == 0){
											dateerror=1;return false;}
										if (d >= 29 &&  parseInt(y) % 4 !== 0){dateerror=1;return false;}}
										if ((d >= 31) && ((m == 4) || (m == 6) || (m == 9) || (m == 11))){dateerror=1;return false;}
									}
								}
							}
					if (!((d=="Error") && (m=="Error") && (y=="Error"))){
						if (d=="Error"){		
							if ((m!="Error")&&(y!="Error")){msg3='ημέρα';}
							if ((m=="Error")&&(y!="Error")){msg3='ημέρα και μήνα';}
							if ((m!="Error")&&(y=="Error")){msg3='ημέρα και έτος';}
							dateerror=1;return false;}
						if ((d!="Error") && ((m=="Error")||(y=="Error"))){
							if ((m=="Error")&&(y=="Error")){msg3="μήνα και έτος";}
							if ((m!="Error")&&(y=="Error")){msg3="έτος";}
							if ((m=="Error")&&(y!="Error")){msg3="μήνα";}
							dateerror=1;return false;}}
						if (m<1 || m>12){return false;}
						if (d<1 || d>31){return false;}
						if (y<1900 || y>2100){return false;}
	}
	else{
		return false;
	}
	
	//if nothing else till now.....
	return true;
}

function doCheck(){
error=0;
for (i=0;i<document.forms(0).length;i++){
		if (document.forms(0).elements(i).kindOf=="realize"){
					//check required
					if (document.forms(0).elements(i).required=="true"){
								if (document.forms(0).elements(i).type=="text" || document.forms(0).elements(i).type=="textarea"  || document.forms(0).elements(i).type=="hidden" || document.forms(0).elements(i).type=="file"){	//if textfield or textarea
										if (document.forms(0).elements(i).value==""){
												error=1;
												break;
										}
								}		
								if (document.forms(0).elements(i).type=="checkbox"){	//if checkbox team
												checkedstate=false;
												for (j=i;j<=document.forms(0).length-1;j++){
														if (document.forms(0).elements(j).type=="checkbox"){
																i++;
																if (document.forms(0).elements(j).checked==true){
																		checkedstate=true;
																}
														}
														else{
																break;
														}		
												}
												if (!(checkedstate)){
														error=1;
														break;	
												}	
								}
								if (document.forms(0).elements(i).name.indexOf('_pass_RE')!=-1){	//if password
									if (document.forms(0).elements(i-1).value==''){
										error=1;
										break;
									}
									else{
											for (j=0;j<document.forms(0).elements(i-1).value.length;j++){
												if (document.forms(0).elements(i-1).value.charCodeAt(j)<48 || document.forms(0).elements(i-1).value.charCodeAt(j)>122){
														error=3;
														break;									
												}
											}	
											if (document.forms(0).elements(i).value!=document.forms(0).elements(i-1).value){
													error=4;
													break;									
											}
									}	
								}
								if (document.forms(0).elements(i).type=="select-one"){	//if drop-down
										if (document.forms(0).elements(i).isDate=="true"){		//if date
													if (document.forms(0).elements(i).value=="Error"){
															error=1;
															break;													
													}														
													else{
															rvalue=checkDate(i);
															i++;i++;
															if (rvalue==false){
																	error=2;
																	break;
															}		
													}
										}	//if date
										else{		//if normal drop-down
											if (document.forms(0).elements(i).name.indexOf('lev1')!=-1) {
												var ds = document.forms(0).elements(i).name;
												var relatedTo = ds.substring(ds.indexOf('1')+1,ds.length);
												if (document.getElementById(relatedTo+'CategsTable')) { //Multiple Categorization
													//alert('Found the Table. : ' + document.getElementById(relatedTo+'CategsTable').rows.length);
													//alert(document.getElementById(relatedTo+'CategsTable').innerHTML)
													if(document.getElementById(relatedTo+'CategsTable').rows.length==1) {
														error=1;
														break;
													}
												} else {
													if (document.forms(0).elements(i).value=="Error") { //No Multiple Categorization
														error=1;
														break;
													}
												}
											} else {
												if (document.forms(0).elements(i).value=="Error") {
													error=1;
													break;
												}
											}
										}	
									}//if drop-down		
					} else {	//if required
						if (document.forms(0).elements(i).name.indexOf('_pass_RE')!=-1){	//if password
							for (j=0;j<document.forms(0).elements(i-1).value.length;j++){
								if (document.forms(0).elements(i-1).value.charCodeAt(j)<48 || document.forms(0).elements(i-1).value.charCodeAt(j)>122){
									error=3;
									break;									
								}
							}	
							if (document.forms(0).elements(i).value!=document.forms(0).elements(i-1).value){
								error=4;
								break;									
							}
						}
					}

		}	//if kindOf=realize
}//for

var iFrameCollection=document.frames;
if (iFrameCollection.length>0){
	var iFrameTagCollection=document.getElementsByTagName("IFRAME");
	for (var z=0;z<iFrameCollection.length;z++){
		if (iFrameTagCollection[z].id.substring(0,10)=='richEditor'){
			if (iFrameCollection[z].document.readyState=='complete'){
				if(iFrameCollection[z].document.getElementById('checkboxEditHTML_RE')!=null){
					if(iFrameCollection[z].document.getElementById('checkboxEditHTML_RE').checked){
						error=5;
						break;
					}
				} else {
					error=6;
					break;
				}
			} else {
				error=6;
				break;
			}
		}
	}
}

if (error==1){
		alert("Παρακαλώ συμπληρώστε όλα τα υποχρεωτικά πεδία");
		return false;
}
else
		if (error==2){
				return false;
		}
		else
				if (error==3){
					alert('Το password πρέπει να περιέχει μόνο αλφαρηθμιτικούς λατινικούς χαρακτήρες');
					return false;
				}
				else
					if (error==4){
						alert('To password δεν επιβεβαιώθηκε');
						return false;
					}
					else
						if (error==5){
							alert('Παρακαλώ απο-επιλέξτε όλες τις επιλογές προβολής HTML κώδικα σε όλους τους Rich Editors.');
							return false;
						}
						else
							if (error==6){
								alert('Παρακαλώ περιμένετε μέχρι ο browser να φορτώσει τους Rich Editors της φόρμας.');
								return false;
							}
							else {	//checked for required fields.Now validate all fields
								for (i=0;i<document.forms(0).length;i++){
									if (document.forms(0).elements(i).kindOf=="realize"){
										fldName=document.forms(0).elements(i).name;
										if (document.forms(0).elements(i).type=="text" || document.forms(0).elements(i).type=="textarea"  || document.forms(0).elements(i).type=="hidden" || document.forms(0).elements(i).type=="file"){
											if (typeof(DONTvalidateFields)=="undefined"){
												if (eval("fldRules"+fldName).length>1){
													if (!validateField(fldName,eval("fldRules"+fldName),eval("fldRulesDtls"+fldName)))
														return false;
												}
											}
										}
									}	
								}
							return true;
							}
}

function doSearchCheck(){
error=0;
for (i=0;i<document.forms(0).length-1;i++){
		if (document.forms(0).elements(i).kindOf=="realize"){
					//check required
					if (document.forms(0).elements(i).isDate=="true"){		//if date
								rvalue=checkDate(i);
								i++;i++;
								if (rvalue==false){
										error=2;
										break;
								}		
					}	//if date
		}	//if kindOf=realize
}//for

if (error==1){
		alert("Please fill in all the required fields");
		return false;
}
else
		if (error==2){
				return false;
		}
		else
				return true;

}

function validateField(fieldName,fieldValidationRule,fieldValidationRuleDetail){
	if (fieldValidationRule.length>1 && fieldValidationRuleDetail.length>1){
		fieldvalue=eval("document.forms[0]."+fieldName+".value");
		safety=0
		while (fieldValidationRule.length>1 && safety<20){
			if (fieldvalue.length>0){
				thisRule=fieldValidationRule.substring(0,fieldValidationRule.indexOf(','))
				thisRuleDetail=fieldValidationRuleDetail.substring(0,fieldValidationRuleDetail.indexOf(','))

				//let's check now the value of the field according to the rules
				var errorFound=0;
						switch (thisRule){
							case "c27":		//size at least
								if (fieldvalue.length<thisRuleDetail){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει τουλάχιστον '+thisRuleDetail+' χαρακτήρες');
										errorFound=1;
								}
								break;
							case "c28" :		//size at most
								if (fieldvalue.length>thisRuleDetail){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει το πολύ '+thisRuleDetail+' χαρακτήρες');
										errorFound=1;
								}
								break;
							case "c29":		//contains only characters (not numbers)
								var regTest= new RegExp(/^[A-Za-zΑ-Ωα-ω\ ]+$/g);
								if (!regTest.test(fieldvalue)){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει μόνο χαρακτήρες του ελληνικού και αγγλικού αλφαβήτου');
										errorFound=1;
								}		
								break;
							case "c30":		//contains only numbers
								if (isNaN(fieldvalue)){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει μόνο αριθμούς');
										errorFound=1;
								}
								break;
							case "c31":		//contains only specific characters
								var regTest= eval("new RegExp(/^["+thisRuleDetail+"\ ]+$/g)");
								if (!regTest.test(fieldvalue)){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει μόνο τους χαρακτήρες \''+thisRuleDetail+'\'');
										errorFound=1;
								}		
								break;
							case "c32":		//contains only alphanumeric characters
								var regTest= new RegExp(/^[A-Za-zΑ-Ωα-ω0-9\ ]+$/g);
								if (!regTest.test(fieldvalue)){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να περιέχει μόνο αλφαριθμητικούς χαρακτήρες');
										errorFound=1;
								}		
								break;
							case "c44":		//Filename Validation (validates that a filename is correct )
								var regTest= new RegExp(/^[A-Za-zΑ-Ωα-ω0-9@!._)(]+$/g);
								curfieldvalue=fieldvalue.substring(fieldvalue.lastIndexOf('\\')+1,fieldvalue.length);
								if (!regTest.test(curfieldvalue)){
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' δε μπορεί να περιέχει τους χαρακτήρες \r#$%^&*=+/><\':;<space>');
										errorFound=1;
								}
								break;
							case "c45":	//Filetype  Validation
									var currentFileExtension=fieldvalue.substring(fieldvalue.lastIndexOf('.')+1,fieldvalue.length);
									var theExts=thisRuleDetail.split('/');
									var gotValidExtension=false;
									for (k=0;k<theExts.length;k++)
										if (currentFileExtension==theExts[k])
											gotValidExtension=true;
									if (!gotValidExtension)	{	
										alert('Το πεδίο '+eval("fldDescr"+fieldName)+' πρέπει να είναι μεταξύ \rτων τύπων '+thisRuleDetail);
										errorFound=1;
									}	
								break;
							//default : statements;
						}
			}					
			fieldValidationRule=fieldValidationRule.substring(fieldValidationRule.indexOf(',')+1,fieldValidationRule.length)
			fieldValidationRuleDetail=fieldValidationRuleDetail.substring(fieldValidationRuleDetail.indexOf(',')+1,fieldValidationRuleDetail.length)	
			safety++;
		}
		
		if (errorFound==1){
			if (eval("document.all."+fieldName+".parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.display")!='none')
				eval("document.forms[0]."+fieldName+".focus()");
			return false;
		}
		else
			return true;
	}	
}

function changeColor(theColor){
//this.style.background=\'#EFEDDE\'
	this.style.background=theColor;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function RLZ_swImg(imgID,nImg){
	document.all(imgID).src=nImg;
}

function hide_Items(){
	var selectCollection;
	selectCollection=document.getElementsByTagName("SELECT");
	flashCollection=document.getElementsByTagName("OBJECT");
	for (var i=0;i<selectCollection.length;i++) {
		selectCollection[i].style.visibility="hidden";
	}
	for (var i=0;i<flashCollection.length;i++) {
		flashCollection[i].style.visibility="hidden";
	}
}

function informHim(){
	alert('Please uncheck "Edit HTML" checkbox.');
	return false;
}

function show_Items() {
	var selectCollection;
	selectCollection=document.getElementsByTagName("SELECT");
	flashCollection=document.getElementsByTagName("OBJECT");
	for (var i=0;i<selectCollection.length;i++) {
		selectCollection[i].style.visibility="visible";
	}
	for (var i=0;i<flashCollection.length;i++) {
		flashCollection[i].style.visibility="visible";
	}
}

function unlockItem(){
	//This function will try to unlock an object. It is called by function UnLoaded (menu_com.js), which is, in turn, called on body.onunload
	//The item which will be unlocked is specified in a global variable in the page.
	//A window is opened which will open a page to perform this action and which automatically closes itself
	if (document.location.href.indexOf('/edit.asp')>-1 && typeof(locked_item)!="undefined")
		window.open('../aidive/actions.asp?unlockItem=1&t_table='+locked_item+'&t_id='+locked_id,'unlock','width=20,height=20,resize=no')
}

function deleteRecord(id){
	if (confirm("Είστε σίγουρος/η ότι θέλετε να διαγράψετε την εγγραφή αυτή;")){
		document.forms.deleteRec.id.value=id;
		document.forms.deleteRec.submit();
	}
}

function resortRset(t_value,t_order_value){
	//alert(t_value+'-'+t_order_value);
	document.forms.paging.sortby.value=t_value+" "+t_order_value;
	document.forms.paging.submit();
}

var sortColumn,sortOrder;
function sortArray(theColumn,theColumnDescr){
	if (sortColumn=='item'+theColumn && sortOrder=='ASC'){
		sortColumn='item'+theColumn;
		sortOrder='DESC';
		rArray.sort(compareNumbersReverse);
		printArray();
		document.all.sortbyDIV.innerHTML='<b>Ταξινόμηση σελίδας με βάση:</b> '+theColumnDescr+'(Φθίνουσα)';
	}
	else{
		sortColumn='item'+theColumn;
		sortOrder='ASC';
		rArray.sort(compareNumbers);
		printArray();
		document.all.sortbyDIV.innerHTML='<b>Ταξινόμηση σελίδας με βάση:</b> '+theColumnDescr+'(Αύξουσα)';
	}
}

function compareNumbers (n1, n2) {
	  return eval("n1."+sortColumn+"<n2."+sortColumn) ? -1 : (eval("n1."+sortColumn+" == n2."+sortColumn) ? 0 : 1);
}

function compareNumbersReverse (n1, n2) {
	  return eval("n1."+sortColumn+">n2."+sortColumn) ? -1 : (eval("n1."+sortColumn+" == n2."+sortColumn) ? 0 : 1);
}

function nav_res(t_page){	//function that handles navigation on results page
	document.forms.paging.page.value=t_page;
	document.forms.paging.submit();
}

function picture2(picgoal,picname) {
if (document.layers)
  PicWin=window.open("",picname,'status=0,scrollbars=1,resizable=1,width=100,height=100,screenX=50,screenY=50,top=50,left=50');
else
  PicWin=window.open("",picname,'status=0,scrollbars=1,resizable=1,width=100,height=100,screenX=50,screenY=50,top=50,left=50');
  PicWin.document.open();
  PicWin.document.writeln('<html>');
  PicWin.document.writeln('<head>');
  PicWin.document.writeln('<title>Image Preview</title>');
  PicWin.document.writeln('</head>');
if (document.layers)
  PicWin.document.writeln('<BODY onLoad="if (document.all || document.layers) window.resizeTo(document.images[0].width,document.images[0].height)" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
else
  PicWin.document.writeln('<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
  //PicWin.document.writeln('<BODY onLoad="if (document.all || document.layers) window.resizeTo(document.images[0].width+10,document.images[0].height+30)" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
  PicWin.document.writeln('<IMG SRC="' + picgoal + '" onLoad="window.resizeTo(document.images[0].width+10,document.images[0].height+30)">');
  PicWin.document.writeln('</body>');
  PicWin.document.writeln('</html>');
  PicWin.document.close();
}

function picture(picgoal,picname) {
  PicWin=window.open("",picname,'status=1,scrollbars=1,resizable=1,width=665,height=500,screenX=50,screenY=50,top=50,left=50,menubar=1');
  PicWin.document.open();
  PicWin.document.writeln('<html>');
  PicWin.document.writeln('<head>');
  PicWin.document.writeln('<title>Image Preview</title><link rel="stylesheet" href="../aidive/template.css" type="text/css" />');
  PicWin.document.writeln('</head>');
  PicWin.document.writeln('<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
  PicWin.document.writeln('<a href="javascript:void(0)" onclick="document.images[0].style.width=orSize+\'px\';" class="comBlueText">Full Size</a>| <a href="javascript:void(0)" onclick="if(document.images[0].width>635)document.images[0].style.width=\'635px\';" class="comBlueText">Resize</a><br>');
  PicWin.document.writeln('<IMG SRC="' + picgoal + '">');
  PicWin.document.writeln('<scri'+'pt defer=true>var orSize;window.onload=function a(){orSize=document.images[0].width;if(document.images[0].width>635)document.images[0].width=635;}</scr'+'ipt>');
  PicWin.document.writeln('</body>');
  PicWin.document.writeln('</html>');
  PicWin.document.close();
}

//Calendar related functions
function extractCalDate(t_field){
		t_value=t_field.value;
		if (t_value.length>0){
			t_day=t_value.substring(0,t_value.indexOf('/'));t_month=t_value.substring(t_value.indexOf('/')+1,t_value.lastIndexOf('/'));t_year=t_value.substring(t_value.lastIndexOf('/')+1,t_value.length);
			if ((!(isNaN(t_day)) && !(isNaN(t_month)) && !(isNaN(t_year)))&&dateCheck(t_value)){
				if (t_field.name.substring(t_field.name.length-1,t_field.name.length)=='T'){
					eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'DDT.value='+t_day);eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'MMT.value='+t_month);eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'YYT.value='+t_year);
				}else{
					eval('document.forms[0].'+t_field.name+'DD.value='+t_day);eval('document.forms[0].'+t_field.name+'MM.value='+t_month);eval('document.forms[0].'+t_field.name+'YY.value='+t_year);
				}
			}
			else {
				if (t_field.name.substring(t_field.name.length-1,t_field.name.length)=='T'){
					eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'DDT.value="Error"');eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'MMT.value="Error"');eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'YYT.value="Error"');
				}else{
					eval('document.forms[0].'+t_field.name+'DD.value="Error"');eval('document.forms[0].'+t_field.name+'MM.value="Error"');eval('document.forms[0].'+t_field.name+'YY.value="Error"');
				}
				eval('document.forms[0].'+t_field.name+'.value=""');
			}
		}
		else{
				if (t_field.name.substring(t_field.name.length-1,t_field.name.length)=='T'){
					eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'DDT.value="Error"');eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'MMT.value="Error"');eval('document.forms[0].'+t_field.name.substring(0,t_field.name.length-1)+'YYT.value="Error"');
				}
				else{
					eval('document.forms[0].'+t_field.name+'DD.value="Error"');eval('document.forms[0].'+t_field.name+'MM.value="Error"');eval('document.forms[0].'+t_field.name+'YY.value="Error"');
				}
				eval('document.forms[0].'+t_field.name+'.value=""');
		}
}

//###################################Categories Related Function###############################################
function printCategs(relatedTo,parent,level,selected,isRequired){
	eval("var categArray=ctg_"+relatedTo+"_array")
	var slctVar='';var slctVarDef='';var categLevelCaption='';var isCentral=false;
	
		for (i=1;i<categArray.length;i++){
			if (categArray[i].levelID==level){
				if (parent==null || parent==0){	//if no restrinction on parent-child(=level1)
					if(categLevelCaption==''){
						categLevelCaption=categArray[i].categCaption;
						if (categArray[i].isCentral==1)
							isCentral=true;
					}
					slctVar+='<option value="'+categArray[i].categID+'"'
					if (categArray[i].categID==selected)
						slctVar+=' selected '
					slctVar+='>'+categArray[i].categ+'</option>'
				}
				else{
					if (categArray[i].parentID==parent){
						if(categLevelCaption==''){
							categLevelCaption=categArray[i].categCaption;
							if (categArray[i].isCentral==1)
								isCentral=true;
						}
						slctVar+='<option value="'+categArray[i].categID+'"'
						if (categArray[i].categID==selected)
							slctVar+=' selected '
						slctVar+='>'+categArray[i].categ+'</option>'
					}	
				}
			}		
		}

	if (slctVar.length>0){
		if (isCentral)
			slctVarDef='<select name="centrallev'+level+relatedTo+'"'
		else
			slctVarDef='<select name="lev'+level+relatedTo+'"'

	//if (level==1 && location.href.indexOf('search.asp')>-1)
	//	slctVar+='<option value="0">Χωρίς Κατηγορία</option>'

		//if level = 1, let's make the field mandatory. If not, all records without category will not be visible
		if (level==1)
			slctVarDef+=' required="'+isRequired+'" kindOf="realize" '

		slctVar=slctVarDef+'class="selectField" onChange="printCategs(\''+relatedTo+'\',this.value,'+(level+1)+',0)"><option value="Error">Επιλέξτε</option>'+slctVar+'</select>'
		document.getElementById('l'+level+relatedTo+'div').innerHTML='<font class="comText">'+categLevelCaption+'</font><br>'+slctVar;
	}
	else
		if (typeof(document.getElementById('l'+level+relatedTo+'div'))!="undefined" && document.getElementById('l'+level+relatedTo+'div')!=null)	
				document.getElementById('l'+level+relatedTo+'div').innerHTML='';
	//Now let's deselect all categs from this level down
	i=level+1
	while (typeof(document.getElementById('l'+i+relatedTo+'div'))!="undefined" && document.getElementById('l'+i+relatedTo+'div')!=null){
		document.getElementById('l'+i+relatedTo+'div').innerHTML=''
	i++;	
	}
	//alert(slctVar);
}

function searchAndGet(t_Array,whatToSearch,valueToFind,whatToGet,isCentral){
	for (i=1;i<=eval(t_Array+".length");i++){
		if (eval(t_Array+"["+i+"]."+whatToSearch)==valueToFind && eval(t_Array+"["+i+"].isCentral")==isCentral){
			return eval(t_Array+"["+i+"]."+whatToGet)
			break;
		}
	}
}
function saveCateg(t_RelatedTo){
	var df=document.forms[0];var theCTGStr="";var theCateg="";var i=1;
	for (i=1;i<=10;i++){
		//if (eval("typeof(df.centrallev"+i+t_RelatedTo+")")!="undefined"){
		if (typeof(df['centrallev'+i+t_RelatedTo])!="undefined"){
			if (df['centrallev'+i+t_RelatedTo].value!='Error'){
				theCateg=searchAndGet('ctg_'+t_RelatedTo+'_array','categID',eval("df.centrallev"+i+t_RelatedTo+".value"),'categ',1)
				theCTGStr+=theCateg+'<input type="hidden" name="centrallev'+i+t_RelatedTo+'_'+globalUniqueCategCounter+'" value="'+eval("df.centrallev"+i+t_RelatedTo+".value")+'">/ '
				globalUniqueCategCounter++;
			}
			else
				break;	
		}
	}

	for (i=1;i<=50;i++){
		//if (eval("typeof(df.lev"+i+t_RelatedTo+")")!="undefined"){
		if (typeof(df['lev'+i+t_RelatedTo])!="undefined"){
			if (eval("df.lev"+i+t_RelatedTo+".value")!='Error'){
				theCateg=searchAndGet('ctg_'+t_RelatedTo+'_array','categID',eval("df.lev"+i+t_RelatedTo+".value"),'categ',0)
				theCTGStr+=theCateg+'<input type="hidden" name="lev'+i+t_RelatedTo+'_'+globalUniqueCategCounter+'" value="'+eval("df.lev"+i+t_RelatedTo+".value")+'">/ '
				globalUniqueCategCounter++;
			}	
			else
				break;	
		}
	}
	if (theCTGStr!=''){
		AddToCategTable(t_RelatedTo,theCTGStr)
		printCategs(t_RelatedTo,null,1,0);
	}	
}


function categItem(categID,categ,levelID,parentID,categCaption,isCentral){
	this.categID=categID;this.categ=categ;this.levelID=levelID;this.parentID=parentID;this.categCaption=categCaption;this.isCentral=isCentral;
}
//########################################################################################################

function deleteMe(item){
	//this function will delete the row of a table (tables of relations)
	theTable=item.parentElement.parentElement.parentElement.parentElement;
	whichOne=item.parentElement.parentElement.rowIndex;
	theTable.deleteRow(whichOne);
	theTable.deleteRow(whichOne); //delete next row too (spacer)
	theTable.deleteRow(whichOne);	//delete next row too (dottes)
	theTable.deleteRow(whichOne); //delete next row too (spacer)
}

function forClick3(){
if(parent.document.frames.leftMenu.document.getElementById('menu').src.indexOf('custom')!=-1){
parent.document.frames.leftMenu.document.frames.menu.stopdragHTML();
parent.document.frames.leftMenu.document.frames.menu.stopCountMouseDoun();
}
}
function forClick2(){
parent.document.frames.leftMenu.document.frames.menu.hideHelpWin();
parent.document.frames.leftMenu.document.frames.shortcuts.hideHelpWin();
}
function forClick1(){
	document.body.onclick=forClick2;
	document.body.onmouseover=forClick3;
}

if(self.location.href.indexOf('index.asp')==-1 && self.location.href.indexOf('richeditor.asp')==-1 && typeof(parent.document.frames.leftMenu)!="undefined")
window.onload=forClick1;

//cookies functions
function ReadCookie (CookieName) {
  var CookieString = top.document.cookie;var CookieSet = CookieString.split (';');var SetSize = CookieSet.length;var CookiePieces;var ReturnValue = "";var x = 0;
  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
   CookiePieces = CookieSet[x].split ('=');
   if (CookiePieces[0].substring (0,1) == ' ') {CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);}
	if (CookiePieces[0] == CookieName) {ReturnValue = CookiePieces[1];}}
  return unescape(ReturnValue);}

function WriteCookie (cookieName, cookieValue) 
{
	top.document.cookie = cookieName + "=" + escape (cookieValue) + "; expires='Tuesday, 01-Apr-2007 07:00:00 GMT'"
}

function resizeParentIFrame(whichFrame){
	try {
		bodyheight = document.getElementById('mainTable').offsetHeight;
		bodyheight = parseInt(bodyheight) + 1;
		if(bodyheight != parent.document.getElementById(whichFrame.height))
			parent.document.getElementById(whichFrame).height=bodyheight;
		setTimeout("resizeParentIFrame('" + whichFrame + "')", 500);
	} catch(error) { return; }
}
