/*
 * $Id: bp.js,v 0.1 2008/09/19 Guojun $
*/

//cache images
cacheImages = ['top.gif','middle.gif','buttom.gif','swg_rollover_top_t.png','swg_rollover_top_r.png','swg_rollover_top_l.png','swg_rollover_top_b.png','close.gif'];
var i = cacheImages.length; while (i--) {eval('var tempImage'+i+'=new Image; tempImage'+i+'.src="/software/cn/solutions/bp/images/'+cacheImages[i]+'";')}

jQuery(function(){

	function moreSelection(selectedObj,displayObj) {
		if(selectedObj.attr('checked')){
			displayObj.slideDown();
		} else {
			displayObj.slideUp();
		}
	}
	
	var searchObj = jQuery('#solution-industry,#solution-type,#solution-challenge,#solution-search');

	jQuery('#btn-continue').click(function(){//click "Continue" button
		if(!jQuery('#selectionIndustry').attr('checked')&&!jQuery('#selectionType').attr('checked')&&!jQuery('#selectionChallenge').attr('checked')){
			//alert("Stoped");
		}else{
			moreSelection(jQuery('#selectionIndustry'),jQuery('#solution-industry'));
			moreSelection(jQuery('#selectionType'),jQuery('#solution-type'));
			moreSelection(jQuery('#selectionChallenge'),jQuery('#solution-challenge'));
			jQuery('#solution-search').slideDown();
			jQuery("#btn-continue").attr("disabled", "disabled");
			jQuery("#selectionIndustry,#selectionType,#selectionChallenge").attr("disabled", "disabled");
		}
	});
	//click "Undo" button
	jQuery('#btn-undo').click(function(){
		searchObj.slideUp();
		jQuery("#btn-continue,#selectionIndustry,#selectionType,#selectionChallenge").attr("disabled", "");
		jQuery("input[type='checkbox']").attr("checked",false); // added by Justin
	});
	//click "Start over" button
	jQuery('#btn-startOver').click(function(){
		searchObj.hide();
		jQuery("#solution-startOver").hide();
		jQuery('#JT').remove();
		jQuery("#solutions").empty();
		jQuery('#ibm-top #ibm-content-main').css('width','530px');
		jQuery('#step-1').slideDown();
		jQuery('#ibm-contact-module').show();
		jQuery('#btn-description').show();
		jQuery("#btn-continue,#selectionIndustry,#selectionType,#selectionChallenge").attr("disabled", "");
		jQuery("input[type='checkbox']").attr("checked",false); // added by Justin
	});
	//search solution
	jQuery('#search').click(function(){
		jQuery('#solutions').html('<p><img src="images/loading.gif" alt="载入中..." /></p>');
		jQuery('#step-1').hide();
		var solutionResult='';
		var solutionTitle,solBp,solType,solIndustry,solBizch,solPdftext,solPdflink,industryPatent='',typePatent='',bizchPatent='',jTipIndex=0;
		// jQuery("input[name=industrys][@checked]").each(function(){industryPatent+=jQuery(this).val()+',';});
		// alert(industryPatent);
		// jQuery("input[name=solTypes][@checked]").each(function(){typePatent+=jQuery(this).val()+',';});
		// jQuery("input[name=bizChs][@checked]").each(function(){bizchPatent+=jQuery(this).val()+',';});
		jQuery("input[name='industrys']:checked").each(function(){industryPatent+=jQuery(this).val()+',';});
		jQuery("input[name='solTypes']:checked").each(function(){typePatent+=jQuery(this).val()+',';});
		jQuery("input[name='bizChs']:checked").each(function(){bizchPatent+=jQuery(this).val()+',';});
		jQuery.ajax({
			type: "GET",
			url: "js/solutions.xml",
			dataType: "xml",
			success: function(xml) {
				jQuery(xml).find('solutionTitle').each(function(){	
					solutionTitle=jQuery(this).text();
					solutionObj=jQuery(this).parent().children();
					solType=solutionObj.eq(1).text();
					solIndustry=solutionObj.eq(2).text();
					// alert(solIndustry);
					solBizch=solutionObj.eq(3).text();
					solPdftext=solutionObj.eq(4).text();
					solPdflink=solutionObj.eq(4).attr('href');
					solIntro=solutionObj.eq(5).text();
					solBp=solutionObj.eq(6).text();
					var test=industryPatent.search(solIndustry);
					// alert(solIndustry+':'+test);
					// search solutions
					// if(industryPatent.search(solIndustry)>-1||typePatent.search(solType)>-1||bizchPatent.search(solBizch)>-1){
					if(industryPatent.search(solIndustry)>=0||typePatent.search(solType)>=0||bizchPatent.search(solBizch)>=0){
						jTipIndex+=1;
						solutionResult=solutionResult+'<tr><th scope="row" class="ibm-table-row"><a href="javascript:void(0);" class="jTip" id="jtip'+jTipIndex+'">'+solutionTitle+'</a><span class="ibm-access">'+solIntro+'</span></th><td>'+solBp+'</td><td width="80">'+solType+'</td><td width="80">'+solIndustry+'</td><td width="80">'+solBizch+'</td><td width="65"><a class="ibm-pdf-link" href="'+solPdflink+'">下载</a></td></tr>';
					}				
				}); //close 'solutionTitle' each
				
				//prepare result
				if(solutionResult==''){ 
					solutionResult='<p>没有发现匹配的解决方案</p>';
				} else {					
					solutionResult='<table cellspacing="0" cellpadding="0" border="0" class="ibm-data-table ibm-sortable-table" summary=""><caption><em style="font-size:12px !important;">解决方案</em></caption><thead><tr><th scope="col">名称</th><th scope="col" width="120">合作伙伴</th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>类型</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>行业</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>IT 问题</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" width="65">成功案例</th></tr></thead><tbody>' + solutionResult + '</tbody></table><br />';
				}
				//print result
				jQuery('#ibm-contact-module').hide();
				jQuery('#btn-description').hide();
				jQuery('#ibm-top #ibm-content-main').css('width','710px');
				jQuery('#solutions').html(solutionResult);
				ibmCommon.initSortableTable(jQuery(".ibm-data-table"));
				jQuery("a.jTip").click(function(){jQuery('#JT').remove();JT_show(this.href,this.id,this.name);return false;});
				jQuery('#solution-startOver').show();
			}
		}); //close jQuery.ajax
	});//close search button function
	
	//list solution
	jQuery('#btn-list').click(function(){
		jQuery('#solutions').html('<p><img src="images/loading.gif" alt="载入中..." /></p>');
		jQuery('#step-1').hide();
		var solutionResult='';
		var solutionTitle,solBp,solType,solIndustry,solBizch,solPdftext,solPdflink,industryPatent='',typePatent='',bizchPatent='',jTipIndex=0;
		
		jQuery.ajax({
			type: "GET",
			url: "js/solutions.xml",
			dataType: "xml",
			success: function(xml) {
				jQuery(xml).find('solutionTitle').each(function(){	
					solutionTitle=jQuery(this).text();
					solutionObj=jQuery(this).parent().children();
					solType=solutionObj.eq(1).text();
					solIndustry=solutionObj.eq(2).text();
					solBizch=solutionObj.eq(3).text();
					solPdftext=solutionObj.eq(4).text();
					solPdflink=solutionObj.eq(4).attr('href');
					solIntro=solutionObj.eq(5).text();
					solBp=solutionObj.eq(6).text();
					// list solutions
					if(solIndustry!=""||solType!=""||solBizch!=""){
						jTipIndex+=1;
						solutionResult=solutionResult+'<tr><th scope="row" class="ibm-table-row"><a href="javascript:void(0);" class="jTip" id="jtip'+jTipIndex+'">'+solutionTitle+'</a><span class="ibm-access">'+solIntro+'</span></th><td>'+solBp+'</td><td width="80">'+solType+'</td><td width="80">'+solIndustry+'</td><td width="80">'+solBizch+'</td><td width="70"><a href="'+solPdflink+'">下载</a></td></tr>';
					}				
				}); //close 'solutionTitle' each
				
				//prepare result
				if(solutionResult!=''){ 
					solutionResult='<table cellspacing="0" cellpadding="0" border="0" class="ibm-data-table ibm-sortable-table" summary=""><caption><em style="font-size:12px !important;">解决方案</em></caption><thead><tr><th scope="col">名称</th><th scope="col" width="120">合作伙伴</th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>类型</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>行业</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" class="ibm-sort" width="80"><a href="#sort"><span>IT 问题</span><span class="ibm-icon">&nbsp;</span></a></th><th scope="col" width="70">成功案例</th></tr></thead><tbody>' + solutionResult + '</tbody></table><br />';
				}
				//print result
				jQuery('#ibm-contact-module').hide();
				jQuery('#btn-description').hide();
				jQuery('#ibm-top #ibm-content-main').css('width','710px');
				jQuery('#solutions').html(solutionResult);
				ibmCommon.initSortableTable(jQuery('.ibm-sortable-table'));
				jQuery("a.jTip").click(function(){jQuery('#JT').remove();JT_show(this.href,this.id,this.name);return false;});
				jQuery('#solution-startOver').show();
			}
		}); //close jQuery.ajax
	});//close list button function
});