var windowG;

function showRecommendForm(subject, id, dataresource) {
	
	if (windowG) {
		windowG.destroy();
	}

	windowG = new Ext.Window({
		renderTo: Ext.getBody(),
		resizable:false,
		draggable: false,
		width: 880,
		cls: 'supportpopup',		
		minWidth: 300,
		minHeight: 200,
		bodyStyle:'',
		buttonAlign:'center',
		items: [{html:
			'<div id="supportcontainer"><img src="/js/libs/ext-2.3.0/resources/images/default/shared/blue-loading.gif" alt="loading" /></div>'			
		}],
		plain:false,
		floating:true,
		modal:true,
		closable: false,
		title:'',
		shadow:false
	});
	
	windowG.show(1, function() { loadRecommendForm(subject, '', '', '', '', '', 0, id, dataresource); });
	
}

function loadRecommendForm(subject, sender, receiver, message, captcha, captchacrypt, send, id, dataresource) {
	
	if(!subject) subject = "";
	if(!sender) sender = "";
	if(!receiver) receiver = "";
	if(!message) message = "";
	if(!captcha) captcha = "";
	if(!captchacrypt) captchacrypt = "";
	if(!send) send = 0;
	if(!id) id = 0;
	if(!dataresource) dataresource = 0;

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getrecommendform&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'SUCCESSFULLYSENT'],
		baseParams: {
			subject: subject,
			sender: sender,
			receiver: receiver,			
			message: message,
			captcha: captcha,
			captchacrypt: captchacrypt,
			send: send,
			id: id,
			dataresource: dataresource
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('supportcontainer').innerHTML = records[i].data.FORM;
					if(records[i].data.SUCCESSFULLYSENT.CODE) {
						windowG.close();
						Ext.Msg.show({
							title: records[i].data.SUCCESSFULLYSENT.TITLE,
							msg: records[i].data.SUCCESSFULLYSENT.MESSAGE,
							buttons: Ext.Msg.OK,						   
							animEl: 'elId',
							cls: 'msgbox'
						});
					}
				}	
				
				windowG.center();
			}			
		}
	});
	
}


function saveRecommendForm() {

	document.getElementById('submitbutton').disabled = "disabled";
	
	if(document.getElementById('captcha'))
		cap = document.getElementById('captcha').value;
	else
		cap = '';
	
	if(document.getElementById('captchacrypt'))
		capcr = document.getElementById('captchacrypt').value;
	else
		capcr = '';
	
	loadRecommendForm(
		document.getElementById('tsubject').value,
		document.getElementById('sender').value,
		document.getElementById('receiver').value,
		document.getElementById('message').value,
		cap,	
		capcr,
		1,
		document.getElementById('id').value,
		document.getElementById('dataresource').value
	);
		
}


function showContactForm(subject) {
	
	if (windowG) {
		windowG.destroy();
	}

	windowG = new Ext.Window({
		renderTo: Ext.getBody(),
		resizable:false,
		draggable: false,
		width: 880,
		cls: 'supportpopup',		
		minWidth: 300,
		minHeight: 200,
		bodyStyle:'',
		buttonAlign:'center',
		items: [{html:
			'<div id="supportcontainer"><img src="/js/libs/ext-2.3.0/resources/images/default/shared/blue-loading.gif" alt="loading" /></div>'			
		}],
		plain:false,
		floating:true,
		modal:true,
		closable: false,
		title:'',
		shadow:false
	});
	
	windowG.show(1, function() { loadContactForm(subject); });
	
}

function loadContactForm(subject, sender, message, captcha, captchacrypt, send) {
	
	if(!subject) subject = "";
	if(!sender) sender = "";
	if(!message) message = "";
	if(!captcha) captcha = "";
	if(!captchacrypt) captchacrypt = "";
	if(!send) send = 0;
	
	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getcontactform&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'SUCCESSFULLYSENT'],
		baseParams: {
			subject: subject,
			sender: sender,
			message: message,
			captcha: captcha,
			captchacrypt: captchacrypt,
			send: send
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('supportcontainer').innerHTML = records[i].data.FORM;
					if(records[i].data.SUCCESSFULLYSENT.CODE) {
						windowG.close();
						Ext.Msg.show({
							title: records[i].data.SUCCESSFULLYSENT.TITLE,
							msg: records[i].data.SUCCESSFULLYSENT.MESSAGE,
							buttons: Ext.Msg.OK,						   
							animEl: 'elId',
							cls: 'msgbox'
						});
					}
				}	
				
				windowG.center();
			}			
		}
	});
	
}


function saveContactForm() {
	
	document.getElementById('submitbutton').disabled = "disabled";
	
	if(document.getElementById('captcha'))
		cap = document.getElementById('captcha').value;
	else
		cap = '';
	
	if(document.getElementById('captchacrypt'))
		capcr = document.getElementById('captchacrypt').value;
	else
		capcr = '';
	
	loadContactForm(
		document.getElementById('tsubject').value,
		document.getElementById('sender').value,
		document.getElementById('message').value,
		cap,	
		capcr,
		1
	);
		
}

function showImagePopup(p, aImg, nImg, ctr) {
		
	if (windowG) {
		windowG.destroy();
	}
	if (!p) {
		p = 1;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}

	windowG = new Ext.Window({
		renderTo: Ext.getBody(),
		resizable:false,
		draggable: false,
		width: 880,
		cls: 'supportpopup',		
		minWidth: 300,
		minHeight: 200,
		bodyStyle:'',
		buttonAlign:'center',
		items: [{html:
			'<div id="imagecontainer"><img src="/js/libs/ext-2.3.0/resources/images/default/shared/blue-loading.gif" alt="loading" /></div>'			
		}],
		plain:false,
		floating:true,
		modal:true,
		closable: false,
		title:'',
		shadow:false
	});
	
	windowG.show(1, function() { loadImage(p, 0, aImg, nImg, ctr); });
	
}

function loadImage(p, inpage, aImg, nImg, ctr) {
	
	if (!inpage) {
		inpage = 0;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}
	if(!ctr) {
		ctr = 'aImages,nImages';
	}

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getimagepopup&p=' + p + '&img=' + aImg[p] + '&max=' + nImg + '&ctr=' + ctr + '&inpage=' + inpage + '&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM','HEIGHT'],
		baseParams: {			
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('imagecontainer').innerHTML = records[i].data.FORM;

					dmy = Ext.get('gallery_nav_left');		
					if (dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					dmy = Ext.get('gallery_nav_right');		
					
					if(dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					if(dmy)
						dmy.applyStyles('margin-top: -'+(records[i].data.HEIGHT + 4)+'px');
					dmy = Ext.get('gallery_nav_left_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					dmy = Ext.get('gallery_nav_right_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
				}		

				if(inpage == 0) {
					windowG.center();
				}
			}			
		}
	});
	
}

function loadImageInPage(p, inpage, aImg, nImg, ctr) {
	
	if (!inpage) {
		inpage = 0;
	}
	if(!aImg) {
		aImg = aImages;
	}
	if(!nImg) {
		nImg = nImages;
	}
	if(!ctr) {
		ctr = 'aImages,nImages';
	}
	if(!ivwcode) {
		ivwcode = '';
	}

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.multimedia.getimageinpage&p=' + p + '&img=' + aImg[p] + '&max=' + nImg + '&ctr=' + ctr + '&inpage=' + inpage + '&random=' + Math.random() + '&ivwcode=' + ivwcode,
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'HEIGHT'],
		baseParams: {			
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('imagecontainer').innerHTML = records[i].data.FORM;
					//alert(records[i].data.HEIGHT);
					dmy = Ext.get('gallery_nav_left');		
					if (dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					dmy = Ext.get('gallery_nav_right');		
					if(dmy)
						dmy.applyStyles('height: '+records[i].data.HEIGHT+'px');
					if(dmy)
						dmy.applyStyles('margin-top: -'+(records[i].data.HEIGHT + 4)+'px');
					dmy = Ext.get('gallery_nav_left_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					dmy = Ext.get('gallery_nav_right_a');	
					dmy2 = Math.round((records[i].data.HEIGHT-77)/2);
					if(dmy)
						dmy.applyStyles('margin-top: '+dmy2+'px');
					//document.getElementById('gallery_nav_left').style.height = records[i].data.HEIGHT;
				}					
			}			
		}
	});
	
}

cMediacontent = 0;

function slide(trigger,type) {
	
	if(typeof(cMediacontent) != 'object') {
		cMediacontent = new Object();
	}
	if(typeof(cMediacontent[trigger]) != 'number') {
		cMediacontent[trigger] = 0;
	}
	
	dmy = Ext.select('#imagegallery_'+trigger+' #innerslide');

	if(type == 'next')	{
		cMediacontent[trigger]++;
		dmy.applyStyles('left: -'+ cMediacontent[trigger] * 165 +'px');			
	}
	else {
		cMediacontent[trigger]--;
		dmy.applyStyles('left: -'+ cMediacontent[trigger] * 165 +'px');		
	}
	
	if(cMediacontent[trigger] == 0)
		Ext.select('#imagegallery_'+trigger+' #sliderback').applyStyles('display:none');
	else
		Ext.select('#imagegallery_'+trigger+' #sliderback').applyStyles('display:block');

	if(cMediacontent[trigger] == eval('nMediacontents_'+trigger) - 3)
		Ext.select('#imagegallery_'+trigger+' #slidernext').applyStyles('display:none');
	else
		Ext.select('#imagegallery_'+trigger+' #slidernext').applyStyles('display:block');
}





