// JavaScript Document
DO_NOT_PARSE = [];
function checkTextFields(form) {
	return true;
	if(!form) {
		alert("Critical error: Please report the problem to the support department of stenik.bgs");
		return false;
	}
	this.DO_NOT_PARSE = [];
	this.form = form;
	this.debug = false;
	this.debugText = "";
	this.checkRequires = checkRequires;
	this.checkArray = checkArray;
	this.onsubmit = onsubmit;
	this.checkRequires()
	this.onsubmit()
	var valid = true;
	for(var i=0;i<this.form.length;i++) {
		var name = (this.form[i].id)
		if(!name) continue;
		if(name.indexOf("notRequire_") != -1) continue;
		if(this.checkArray(name)) {
			continue;
		} else {
			if(this.form[i].tagName.toLowerCase() == "input") {
				if(this.form[i].type.toLowerCase() == "text") {
					if(this.form[i].value == "") {
						tip.show(this.form[i],"left","Please fill this field to continue!","error");
						this.form[i].focus();
						valid = false;
						break;
					}
				}
			}
			if(this.form[i].tagName.toLowerCase() == "textarea") {
				if(this.form[i].value == "") {
					tip.show(this.form[i],"left","Please fill this field to continue!","error");
					this.form[i].focus();
					valid = false;
					break;
				}
			}
			if(this.debug) this.debugText+= "Field: "+name+", Value: "+this.form[i].value+"\n";
		}
	}
	if(this.debug) alert(this.debugText)
	return valid;
	
	function checkRequires() {
		for(var i=0;i<this.form.length;i++) {
			var name = (this.form[i].name || this.form[i].id)
			if(typeof name!= "undefined" && name.indexOf("notRequire_") != -1) {
				if(!this.DO_NOT_PARSE.in_array(name.replace("notRequire_",""))) {
					this.DO_NOT_PARSE[DO_NOT_PARSE.length] = name.replace("notRequire_","");
				} else continue;
			}
		}
	}
	function checkArray(name) {
		var len = this.DO_NOT_PARSE.length;
		for ( var x = 0 ; x <= len ; x++ ) {
			if ( this.DO_NOT_PARSE[x] == name ) return true;
		}
		return false;
	}
	function onsubmit() {
		if(typeof oUtil=="undefined") return;
		var sContent;
		for(var i=0;i<oUtil.arrEditor.length;i++) {
			var oEdit=eval(oUtil.arrEditor[i]);
			if(oEdit.mode=="HTMLBody") sContent=oEdit.getHTMLBody();
			if(oEdit.mode=="HTML") sContent=oEdit.getHTML();
			if(oEdit.mode=="XHTMLBody") sContent=oEdit.getXHTMLBody();
			if(oEdit.mode=="XHTML") sContent=oEdit.getXHTML();
			$(oEdit.idTextArea).value= sContent;
		}
	}
}


/* Administration Panel Functions */

function addGallery(action,onSucsessURL) {
	
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	
	var tArr = new Array(
		['1','Видео'],
	    ['2','Стандартна']	
	);
	
	var align = new Array(
		['left','Ляво'],
		['right','Дясно']	
	);
	
	var cat = new Array(
		['1','Страница по избор'],
		['2','Страница "Галерия"']	
	);
	
	var types = new Ext.data.SimpleStore({
				  fields: ['val', 'nam'],
				  data : tArr
				});
				
	var alignment = new Ext.data.SimpleStore({
				  fields: ['val', 'nam'],
				  data : align
				});

	
   var select = new Ext.form.ComboBox({
				    fieldLabel:'Тип галерия',
				    valueField:'val',
   	                store: types,
				    displayField:'nam',
				    typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    emptyText:'Изберете тип ...',
				    selectOnFocus:true,
				    width: 200,
				    editable: false,
				    forceSelection:true,
				    allowBlank:false,
				    blankText:"Това поле е задължително",
				    hiddenName:'type' 
				});
	var select2 = new Ext.form.ComboBox({
				    fieldLabel:'Подравняване',
				    valueField:'val',
   	                store: alignment,
				    displayField:'nam',
				    typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    emptyText:'Изберете тип ...',
				    selectOnFocus:true,
				    width: 200,
				    editable: false,
				    /*forceSelection:true,
				    allowBlank:false,
				    blankText:"Това поле е задължително",*/
				    hiddenName:'align' 
				});
	var select3 = new Ext.form.ComboBox({
				    fieldLabel:'Покажи във',
				    valueField:'val',
   	                store: cat, 
				    displayField:'nam',
				    typeAhead: true,
				    mode: 'local',
				    triggerAction: 'all',
				    emptyText:'Изберете тип ...',
				    selectOnFocus:true,
				    width: 200,
				    editable: false,
				    /*forceSelection:true,
				    allowBlank:false,
				    blankText:"Това поле е задължително",*/
				    hiddenName:'category' 
				}); 

		
	var dlg = new Ext.FormPanel({
			labelAlign:"left",
			waitMsgTarget: true,
			url :FOLDERS.domainRoot+"administration/gallery.php?action=add",
			border:false,
			labelWidth : 150,
			layout:'form',
			items:[{
				fieldLabel:"Име на галерията (bg)",name: 'name_bg',
				xtype:'textfield',tabindex: 1,width:200,allowBlank:false,blankText:"Това поле е задължително"
			},{
				fieldLabel:"Име на галерията (en)",name: 'name_en',
				xtype:'textfield',tabindex: 1,width:200,allowBlank:false,blankText:"Това поле е задължително"
			},select3]
		});
		
		dialog = new Ext.Window({
			layout:'fit',title:"Добави галерия",width:430,height:180,closeAction:'hide',closable : true,shadow: true,modal: false,resizable : false,bodyStyle: "padding: 10px;background:white;",
			items: [dlg],
			buttons: [{
				text:"Добави",
				type: "submit",
				handler:function() {
					if(dlg.form.isValid()) {
						dlg.form.submit({
							waitMsg: "Добавяне на галерия...",
							success: function(dlg, action) {
								dialog.hide();
								dlg.reset();
								Ext.MessageBox.alert('','Галерията е добавена успешно');
								window.location = window.location;
							} 
						})
					}
				}
			},{
				text: "Затвори",
				handler: function(){
					dialog.hide();
				}
			}]
		});
		
		dialog.show();
	
	
	/*if(text=prompt("Please enter the gallery name:")){
			new Ajax.Request(action,{
				method:'post',
				parameters: {name: text,submited:'viaAjax'},
				onSuccess: function(transport){
					var response = transport.responseText || "";
					redirect(onSucsessURL)
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}*/
}

function addPosition(action,onSucsessURL) {
	if(text=prompt("Моля въведете името на позицията за работа")){
			new Ajax.Request(action,{
				method:'post',
				parameters: {name: text,submited:'viaAjax'},
				onSuccess: function(transport){
					var response = transport.responseText || "";
					redirect(onSucsessURL)
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
}

function editPosition(name,action,onSucsessURL) {
	if(text=prompt("Моля въведете името на позицията за работа",name)){
			new Ajax.Request(action,{
				method:'post',
				parameters: {name: text,submited:'viaAjax'},
				onSuccess: function(transport){
					var response = transport.responseText || "";
					redirect(onSucsessURL)
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
}
function deleteAd(id,adid) {
	if(confirm("Сигурни ли сте, че искате да изтриете файла")){
		$("fileDelete").innerHTML = "изтриване...";
		new Ajax.Request("?action=deleteFile",{
			method:'post',
			parameters: {"id": id,submited:'viaAjax',"adid":adid},
			onSuccess: function(transport){
				var response = transport.responseText || "";
				$("fileDelete").innerHTML = "Файла е изтрит";
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
}

function addZone(action,onSucsessURL) {
	if(text=prompt("Name der Gruppe")){
		
	if(typeof Request !="undefined"){
		var res = new Request({
			url:"http://emi.demo.stenikgroup.com/administration/ads.php"+action,
			method:'post',
			data: {name: text,submited:'viaAjax'},
			onSuccess: function(transport){
				var response = transport.responseText || "";
				
				window.location=window.location;
		}, onFailure: function(){ alert('Something went wrong...') }});
		
		res.send();
		}else{
			alert('there');
			console.log('undefined');
		}
	}
}
function editZone(action,onSucsessURL,currentName,currentId) {
	if(text=prompt("Name der Gruppe:",currentName)){
		
		var res = new Request({
			url:"http://emi.demo.stenikgroup.com/administration/ads.php"+action,
			method:'post',
			data: {name: text,submited:'viaAjax',id:currentId},
			onSuccess: function(transport){
				
				window.location=window.location;
				
		}, onFailure: function(){ alert('Something went wrong...') }});
		res.send();
	}
}

function delZone(e) {
	var action = e.href;
	if(confirm("Are you sure you want to delete this record?")){
		var res = new Request({
			url:"http://emi.demo.stenikgroup.com/administration/ads.php"+action,
			method:'post',
			data: {},
			onSuccess: function(transport){
				window.location=window.location;
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
		res.send();
	}
	return false;
}


