var win;
var win2;
var winCoverFlow;
var contact

function showModal(){
 win = new Ext.Window({
 id:'myFrameWin'
 ,width: 662
 //,height: 662
 ,autoScroll:false
 ,modal:true
 ,closeAction :'hide'
 ,frame:false
 ,shadow:false
 ,border:false
 ,closable:false
 ,resizable:false
 ,y:20
 ,autoLoad:{url:"readmore"}
 });
 win.show();
}

Ext.IframeWindow = Ext.extend(Ext.Window, {
onRender: function() {
    this.bodyCfg = {
        tag: 'iframe',
        src: this.src,
        cls: this.bodyCls,
        style: {
            border: '0px none'
        }
    };
    Ext.IframeWindow.superclass.onRender.apply(this, arguments);
}
});

function showCoverFlow(url){

    var w = new Ext.IframeWindow({
        id:'myFrameWin',
        width:950,
        height:600,
        modal:true,
        closeAction :'hide',
        frame:true,
        shadow:false,
        border:true,
        resizable:false,
        y:20,
        //title:"Knowledge Control Solutions Iframe Window Sample",
        src:url
    })


    w.show();



 /*winCoverFlow = new Ext.Window({
 id:'myFrameWin'
 ,width: 1280
 ,height: 800
 ,autoScroll:false
 ,modal:true
 ,closeAction :'hide'
 ,frame:false
 ,shadow:false
 ,border:false
 ,closable:false
 ,resizable:false
 ,y:100
 ,body:	new Ext.ux.ManagedIFrame({autoCreate:{id:'dynamicIframe1',cls:'x-window-body',width:'100%',height:'100%',src:url}}),

 ,autoLoad:{url:url ,callback:function() {
                    var flashvars = {};
       		var params = {};
	 		var attributes = {};       
            params.WMODE="transparent";
            swfobject.embedSWF("../swf/banner.swf", "player", " 800", "600", "9.0.0", "../swf/expressInstall.swf", flashvars, params, attributes); 
                  }
               } 
           
 });
 winCoverFlow.show();*/
}


Ext.getUrlParam = function(param) {
    var params = Ext.urlDecode(location.search.substring(1));
    return param ? params[param] : params;
    
};

Ext.getFormParam = function(){
    var returnDico = {};
    for(var j=0;j<contact.items.items.length;j++){
        returnDico[contact.items.items[j].name] = contact.items.items[j].getEl().dom.value;
	}
	return returnDico;


}

Ext.onReady(function(){

    // turn on validation errors beside the field globally
    
    Ext.QuickTips.init();
    var bd = Ext.getBody();
    contact = new Ext.FormPanel({
        frame:true,
        emptyText  : 'champs obligatoire',
        msgTarget : 'top',
        monitorValid : true,
        labelWidth: 80,
		baseCls : 'classContact',
		id : 'idContact',       
        items: 
		[
			{
				xtype: 'textfield',
				fieldLabel: '* Nom ',
				name: 'nom',
				allowBlank: false,
				blankText: 'Vous devez remplir ce champ.',
				maxLengthText: '40 car max',
                maxLength: 40,
                cls : "classicInput",
                width: 200,
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'textfield',
				fieldLabel: '* Prénom ',
				name: 'prenom',
				allowBlank: false,
				blankText: 'Vous devez remplir ce champ.',
				maxLengthText: '40 car max',
                maxLength: 40,
                width: 200,
                cls : "classicInput",
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'textfield',
				vtype: 'email',
				vtypeText: 'Adresse email incorrecte, entrez une adresse du type utilisateur@domaine.com.',
				fieldLabel: '* E-mail ',
				name: 'email',
				allowBlank: false,
				blankText: 'Vous devez remplir ce champs.',
				maxLengthText: '40 car max',
                maxLength: 40,
                width: 200,
                cls : "classicInput",
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'textfield',
				fieldLabel: 'Téléphone ',
				name: 'telephone',
				maxLengthText: '40 car max',
                maxLength: 40,
                width: 200,
                cls : "classicInput",
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'textarea',
				fieldLabel: 'Adresse ',
				name: 'adresse',
				maxLengthText: '500 car max',
                maxLength: 400,
                width: 200,
                cls : "classicInput",
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'textarea',
				fieldLabel: 'Message ',
				name: 'message',
				maxLengthText: '500 car max',
                maxLength: 500,
                width: 310,
                cls : "classicInput",
                id: 'messageInput',
                invalidClass :"classicErrorInput"
			},
			{
				xtype: 'label',
				name: 'validation',
				cls: 'validation',
				id: 'validation',
				html: '&nbsp;',
				hidden: false,
				cls: "statutLabel"
			}
		],
		buttons:[{
            text: 'Envoyer',
            handler: function(){
                    var conn = new Ext.data.Connection();
                    conn.request({
                    	url:'contact',
                    	params:Ext.getFormParam(),
                    	method:'POST',
                    	success: function(responseObject) {
                            Ext.get('idContact').update('<p class="x-form-item-label">Merci</p>');
                    	},
                    	failure: function() {
                    	    alert('Un problème technique est survenu.');
                    	}
                    });
                }
            }]            
		
    });
    if(Ext.get("formulaireContact")!=null){
    	contact.render(Ext.get('formulaireContact'));
    }
    if(Ext.get("lirelasuite")!=null){
    	Ext.get("lirelasuite").on("click",showModal);
    }
    if(Ext.get("lirelasuite2")!=null){
    	Ext.get("lirelasuite2").on("click",showModal2);
    } 
    if(Ext.getUrlParam('directmodal')=='1'){
        showModal();
    }
    if(location.pathname.indexOf("Contact")!=-1){
        contact.render(Ext.get('contact'));
    }
});


var msg = function(title, msg) {
                        Ext.Msg.show({
                            title: title,
                            msg: msg,
                            minWidth: 200,
                            modal: true,
                            icon: Ext.Msg.INFO,
                            buttons: Ext.Msg.OK
                      });
                    };


function displayPlay(idPlay) {
	Ext.get(idPlay).setStyle("display","block");

}
function hidePlay(idPlay) {
	Ext.get(idPlay).setStyle("display","none");
}

function getNextNews(currentNews) {
	Ext.Ajax.request({ //get form in ajax
		url: "home/getNews",
		success: function(response, action) {
			if (response.responseText != "") {
				Ext.get("ArtNews").update(response.responseText);
				currentNews++;
			}
			
		},
		params: { currentNews: currentNews}
	});	
}

