var common;
common = function(){
	var urllink = location.toString();
	var obj = Ext.urlDecode(urllink.substring(urllink.lastIndexOf('?')+1, urllink.length));
	
	return {
		backupPic: null,
		
		init: function(){
			var display = Ext.query('div[class=support_list_led_div2]');
			for(i=0;i<display.length;i++){
				display[i].style.height = 0;
				display[i].style.display = 'none';
			}
			var display1 = Ext.query('div[class=products_more_div3-2]');
			for(i=0;i<display1.length;i++){
				display1[i].style.height = 0;
				display1[i].style.display = 'none';
			}
			var area = Ext.query('textarea[area]')
			for(i=0;i<area.length;i++){
				var thename = new Ext.form.TextArea({
					emptyText: area[i].area,
					fieldClass: '',
					invalidClass: '',
					emptyClass: '',
					focusClass: '',
					applyTo: area[i].id
				});
				thename.getEl().removeClass('x-form-text')
				thename.getEl().removeClass('x-form-empty-field')
			}
			if(Ext.get('keyword')){
				var textf = Ext.getDom('keyword');
				var thename = new Ext.form.TextField({
					emptyText: textf.value,
					fieldClass: '',
					invalidClass: '',
					emptyClass: '',
					focusClass: '',
					value: '', 
					applyTo: textf.id
				});
				this.searchField = thename;
				thename.getEl().removeClass('x-form-text')
				thename.getEl().removeClass('x-form-empty-field')
				thename.getEl().addKeyListener({key:13},function(){
					this.gotosearch('keyword');
				},this);
			}
			if(Ext.get('salseSearch')){
				var kw = Ext.isEmpty(obj.SSS) ? '' : decodeURIComponent(obj.SSS);
				var textf = Ext.getDom('salseSearch');
				var thename = new Ext.form.TextField({
					emptyText: textf.bvalue,
					fieldClass: '',
					invalidClass: '',
					value: kw, 
					emptyClass: '',
					focusClass: '',
					applyTo: textf.id
				});
				thename.getEl().removeClass('x-form-text')
				thename.getEl().removeClass('x-form-empty-field')
				thename.getEl().addKeyListener({key:13},function(){
					this.gotoSalse('salseSearch');
				},this);
			}
			if(Ext.get('inquiryList')){
				var cb = function(a,success,rspn){
					if(success){
						var info = eval(rspn.responseText);
						el = Ext.get('inquiryList');
						Ext.get('inquiryNum').update(info.length);
						if(info.length == 0){
							Ext.get('signMenu').remove();
							Ext.get('buttonEnd').remove();
						}else{
							el.update(this.inquiryWhile(info),true);
						}
					}
				}
				var cn = new Ext.data.Connection({url:"getdata.php?Type=getInquiry"}).request({
					scope: this, 
					method: "POST", 
					callback:cb
				});
			}
		},
		
		gotosearch: function(theid){
			var keyword = Ext.getDom(theid).value.trim();
			if (this.searchField.getRawValue().trim() == ""){
				alert(keyword);
			}else{
				keyword = encodeURIComponent(keyword);
				var strURL="products.php?Type=search&Keyword="+keyword.trim();
				location.href=strURL;
			}
		},
		
		gotoSalse: function(theid){
			var keyword = Ext.getDom(theid).value;
			var rather = Ext.getDom(theid).bvalue;
			if (keyword.trim() == "" || keyword.trim() == rather.trim()){
				alert('Please Enter Keyword');
			}else{
				keyword = encodeURIComponent(keyword);
				var strURL="customer.php?Type=global&SSS="+keyword.trim();
				location.href=strURL;
			}
		},
		
		theSlideOut: function(num, type){
			var type = type == null ? '' : type;
			boxel = Ext.get('ans'+num);
			boxel.slideOut('t',{
				afterStyle: {height:"0px"},
				block: false,
				useDisplay: true,
				stopFx: true
			});
			boxdom = Ext.getDom('click'+num);
			boxdom.href = "javascript:common.theSlideIn("+num+",'"+type+"')";
			switch(type){
				case 'B': 
					Ext.get('click'+num).parent().replaceClass('products_more_div3-3','products_more_div3');
					break;
					
				default:
					Ext.get('click'+num).removeClass('link_support');
			}
		},
		
		theSlideIn: function(num, type){
			var type = type == null ? '' : type;
			boxel = Ext.get('ans'+num);
			if(Ext.isIE6){
				boxel.slideIn('t',{
					afterStyle: {height:"auto"},
					block: false,
					useDisplay: false,
					stopFx: true
				});
			}else{
				boxel.dom.style.display = 'block';
				boxel.autoHeight(true);
			}
			boxdom = Ext.getDom('click'+num);
			boxdom.href = "javascript:common.theSlideOut("+num+",'"+type+"')";
			switch(type){
				case 'B': 
					Ext.get('click'+num).parent().replaceClass('products_more_div3','products_more_div3-3');
					break;
					
				default:
					Ext.get('click'+num).addClass('link_support');
			}
		},
		
		addInquiry: function(num){
			var cb = function(a,success,rspn){
				if(success){
					Ext.MessageBox.confirm('Confirm', Ext.getDom('pdtName').innerHTML + ' added in your inquiry list.<br> Are you sure you want to inquiry?', function(btn){
						if(btn == 'yes')
							window.location.href = "support.php?Type=inquiry";
					}, this);
				}
			}
			var cn = new Ext.data.Connection({url:"getdata.php?Type=addInquiry"}).request({
				scope: this, 
				method: "POST", 
				params: {"paramID": num, "paramTable": obj.Type}, 
				callback:cb
			});
		}, 
		
		delInquiry: function(num,theid,type){
			var cb = function(a,success,rspn){
				if(success){
					var info = eval(rspn.responseText);
					Ext.get('inquiryNum').update(info.length);
					if(info.length != 0){
						Ext.get('inquiryList').update(this.inquiryWhile(info),true);
					}else{
						Ext.get('inquiryOne'+num).remove(true);
						Ext.get('signMenu').remove();
						Ext.get('buttonEnd').remove();
					}
				}
			}
			var cn = new Ext.data.Connection({url:"getdata.php?Type=delInquiry"}).request({
				scope: this, 
				method: "POST", 
				params: {"paramID": theid, "paramTable": type}, 
				callback:cb
			});
		},
		
		fancy: function(el, value){
			el.hide();
			el.removeClass("loading-indicator");
			el.stopFx();
			el.update(value, true);
			el.autoHeight(true);
			el.fadeIn({
			    endOpacity: 1, 
			    easing: 'easeBoth',
			    duration: 1
			})
		},
		
		inquiryWhile: function(store){
			var tpl = new Ext.XTemplate(
				'<tpl for=".">',
				'<div id="inquiryOne{#}"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>',
				'<td width="200" align="left" valign="middle" class="support_inquiry_td1">',
				'<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="50">',
				'<table width="50" border="0" cellpadding="0" cellspacing="3" bgcolor="#A3C500"><tr><td width="44" bgcolor="#000000">',
				'<a href="products.php?Type={Type}more&KindID={UID}&ID={ID}"><img src="{Img}" alt="{PN}" width="44" height="41" border="0" /></a>',
				'</td></tr></table>',
				'</td><td width="10">&nbsp;</td>',
				'<td><div class="support_inquiry_div1"><a href="products.php?Type={Type}more&KindID={UID}&ID={ID}" class="link_support">{PN}</a></div></td>',
				'</tr></table></td>',
				'<td width="190" align="left" valign="middle" class="support_inquiry_td1"><div class="support_inquiry_div2">{UN}</div></td>',
				'<td align="left" valign="middle" class="support_inquiry_td1"><div class="support_inquiry_div2"> {CN}</div></td>',
				'<td width="119" align="center" valign="middle" class="support_inquiry_td1">',
				'<a href="javascript:common.delInquiry({#},{ID},\'{Type}\')"><img src="images/support_inquiry_28.jpg" width="119" height="30" border="0" /></a>',
				'</td></tr><tr>',
				'<td height="3" align="left" valign="middle" bgcolor="#f2f2f2"></td>',
				'<td height="3" align="left" valign="middle" bgcolor="#f2f2f2"></td>',
				'<td height="3" align="left" valign="middle" bgcolor="#f2f2f2"></td>',
				'<td height="3" align="center" valign="middle" bgcolor="#f2f2f2"></td>',
				'</tr></table></div>',
				'</tpl>'
			);
			var word = store.length > 0 ? tpl.apply(store) : noinquiry();
			return word;
		}
	}
}();

Ext.onReady(common.init, common);

function changeCate(droplist){
	var param = droplist.value.split(',');
	cate = Ext.getDom('Cate');
	for(i=cate.length-1;i>0;i--){
		cate.options[i] = null;
	}
	if(droplist.value != 'IP'){
		var cb = function(a,success,rspn){
			if(success){
				var info = eval(rspn.responseText);
				cate = Ext.getDom('Cate');
				for(i=0;i<info.length;i++){
					cate.options[i+1] = new Option(info[i].Name,'products.php?Type='+info[i].Type+'list&KindID='+info[i].CategoryID+'&ID='+info[i].ID)
				}
			}
		}
		var cn = new Ext.data.Connection({url:"getdata.php?Type=dropList"}).request({
			scope: this, 
			method: "POST", 
			params: {"paramID": param[0], "paramTable": param[1]}, 
			callback:cb
		});
	}else{
		cate.options[1] = new Option('Memory IP','products.php?Type=mip')
	}
}

function pdtVerify(){
	if(Ext.getDom('Upper').value != '0,led'){
		if(Ext.getDom('Cate').value != ''){
			window.location.href = Ext.getDom('Cate').value;
		}else{
			alert('You don\'t select any Product Kind!');
		}
	}else{
		alert('You don\'t select any Product Type!');
	}
}