function Element(id){
	if(id!='')
	if(document.getElementById(id))
	return document.getElementById(id);
	else
	return false;
}
function isSelected(id){
	if(Element('q'+id).checked)return true;
	else return false;
}
function Hide(e){
	if(e)e.style.display='none';
	else return false;
}
function Show(e){
	if(e)e.style.display='block';
	else return false;
}

function switchLanguage(){
	e = document.getElementById('switch-language');
	if(e.style.display=='none')Show(e);
	else Hide(e);
}

function switchTab(id){
	li = Element('tabswitch'+id);
	li.className='selected';

	Show(Element('tab'+id));
	switch(id){
		case 1:
		removeClass('tabswitch2');
		removeClass('tabswitch3');
		Hide(Element('tab2'));
		Hide(Element('tab3'));
		break;
		case 2:
		removeClass('tabswitch1');
		removeClass('tabswitch3');
		Hide(Element('tab1'));
		Hide(Element('tab3'));
		break;
		case 3:
		removeClass('tabswitch2');
		removeClass('tabswitch1');
		Hide(Element('tab2'));
		Hide(Element('tab1'));
		break;
	}
}
function removeClass(el) {
	var e = Element(el);
	if(e)
	e.className='';
	else return false;
}
function canProceed(id){
	//at least one option HAS TO be picked
	//Hardcoded ranges of questions for each step. Buuuu!
	var range = new Array();
	range[1] = new Array(1,2,3,4);
	range[2] = new Array(5,6,7,8,9);
	range[3] = new Array(10,11,12,13);
	range[4] = new Array(14,15,16);
	//
	for(i=0;i<=range[id].length-1;i++){
		if(isSelected(range[id][i]))return true;
	}
}

function proceed(id,way){
	//validation
	if(way!='back')
	if(!canProceed(id)){
		Element('cantProceed'+id).style.visibility='visible';
		return false;
	} else Element('cantProceed'+id).style.visibility='hidden';

	//close current position
	Element('step'+id).className='';
	Hide(Element('pc-bright'+id));
	Hide(Element('pc-dark'+id));

	//which way to go?
	if(way=='back')idToOpen=id-1;
	else idToOpen = id+1;

	//open new position
	Element('step'+idToOpen).className='selected';
	Show(Element('pc-bright'+idToOpen));
	Show(Element('pc-dark'+idToOpen));

	//last step ->calculate
	if(idToOpen==5)Calculate();
}
//Products (value is just for info)
var products = new Array();
products[0] ='Express';
products[1] ='Pro';
products[2] ='Suite';
products[3] ='Pocket';
products[4] ='NWE';
products[5] ='NLPC';
products[6] ='SDK';
products[7] ='NWEBS';

//Questions (all values HAVE TO be in "value" !)
var q = new Array();
q[1] = new Array();
q[2] = new Array("0");
q[3] = new Array();
q[4] = new Array("0");
q[5] = new Array("3","4","7");
q[6] = new Array("0","1","3","4","7");
q[7] = new Array("0","1","3");
q[8] = new Array("0","1","2","3");
q[9] = new Array("0","1","4","7");
q[10] = new Array("0","4","7");
q[11] = new Array("0","1","3","6");
q[12] = new Array("0","1","6");
q[13] = new Array("6");
q[14] = new Array("0","6");
q[15] = new Array("0","1","2","3","6");
q[16] = new Array();


function Calculate(){
	//at the beginning all products are OK
	qmax = q.length-1;
	var recommend = new Array()
	for(j=0;j<=products.length-1;j++)recommend[j] = true;

	//now, exclude all bad products
	for(i=1; i<=qmax; i++)
	if(isSelected(i)){
		for(k=0;k<=q[i].length-1;k++)
		recommend[parseInt(q[i][k])] = false;
		Show(Element('pick'+i));
	} else
	Hide(Element('pick'+i));
	//and activate the rest
	for(j=0;j<=products.length-1;j++)
	if(recommend[j] == true)
	Show(Element('recommended'+j));
	else
	Hide(Element('recommended'+j));
}
function open_tutorial(tutorial){
	window.open(tutorial,'video','width=640,height=512,status=0,menubar=0,scrollbars=0,toolbar=0');
}


// Faq redirections - we load javascript files dynamicly
function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function faqRedirections() {    
	// Redirections for faq - onyl english	
	if ( (location.href.indexOf("support/knowledge-base") != -1 || location.href.indexOf("Support/FAQ/") != -1) && document.getElementById('l') != false) {
		// Faqs
		var redirections = new Array();
		redirections['#g1'] = "index.php?t=faq&id=101";
		redirections['#g2'] = "index.php?t=faq&id=102";
		redirections['#g3'] = "index.php?t=faq&id=103";
		redirections['#g4'] = "index.php?t=faq&id=104";
		redirections['#g5'] = "index.php?t=faq&id=105";
		redirections['#g6'] = "index.php?t=faq&id=106";
		redirections['#g7'] = "index.php?t=faq&id=107";
		redirections['#g8'] = "index.php?t=faq&id=108";
		redirections['#g9'] = "index.php?t=faq&id=109";
		redirections['#g10'] = "index.php?t=faq&id=110";
		redirections['#g11'] = "index.php?t=faq&id=111";
		redirections['#g12'] = "index.php?t=faq&id=112";
		redirections['#g13'] = "index.php?t=faq&id=113";
		redirections['#g14'] = "index.php?t=faq&id=114";
		redirections['#g14'] = "index.php?t=faq&id=115";
		redirections['#g16'] = "index.php?t=faq&id=116";
		redirections['#g17'] = "index.php?t=faq&id=117";
		redirections['#i1'] = "index.php?t=faq&id=118";
		redirections['#i2'] = "index.php?t=faq&id=119";
		redirections['#i4'] = "index.php?t=faq&id=120";
		redirections['#i5'] = "index.php?t=faq&id=121";
		redirections['#i6'] = "index.php?t=faq&id=122";
		redirections['#i7'] = "index.php?t=faq&id=123";
		redirections['#i8'] = "index.php?t=faq&id=124";
		redirections['#i9'] = "index.php?t=faq&id=125";
		redirections['#i10'] = "index.php?t=faq&id=126";
		redirections['#i11'] = "index.php?t=faq&id=127";
		redirections['#i12'] = "index.php?t=faq&id=128";
		redirections['#i13'] = "index.php?t=faq&id=129";
		redirections['#i14'] = "index.php?t=faq&id=130";
		redirections['#i15'] = "index.php?t=faq&id=131";
		redirections['#d4'] = "index.php?t=faq&id=135";
		redirections['#d5'] = "index.php?t=faq&id=136";
		redirections['#p13'] = "index.php?t=faq&id=147";
		redirections['#p15'] = "index.php?t=faq&id=149";
						
		redirections['Support/FAQ/General']="support/knowledge-base";
    	redirections['Support/FAQ/Installation']="support/knowledge-base";
    	redirections['Support/FAQ/Printing']="support/knowledge-base";
    	redirections['Support/FAQ/Databases']="support/knowledge-base";
    	redirections['Support/FAQ/Enterprise-Series']="support/knowledge-base";
	
		// Urls
		redirections['General'] = "support/knowledge-base";
		redirections['Installation'] = "support/knowledge-base";
		redirections['Databases'] = "support/knowledge-base";
		redirections['Printing'] = "support/knowledge-base";
		redirections['Enterprise-Series'] = "support/knowledge-base";
				
		var isHash    = (location.href.indexOf("#") != -1) ? true : false;
		var faqID     = location.href.substr(location.href.indexOf("#"));
		var faqUrl    = location.href.substr(location.href.indexOf('Support/FAQ/')+12);
		
		if (isHash == true) {
	      faqUrl = faqUrl.replace(location.href.substr(location.href.indexOf("#")), '');
        }
		var	url       = '';		
		var baseUrl   = '';
				
		if ((location.href.indexOf("support/knowledge-base") != -1) && (typeof redirections[faqID] != 'undefined')) {
			url      = redirections[faqID];
			baseUrl  = 'support/knowledge-base';
		} else if (typeof redirections[faqUrl] != 'undefined') {
			url      = (isHash == true) ? redirections[faqUrl]+faqID : redirections[faqUrl];
			baseUrl  = location.href.substr(location.href.indexOf('Support'));

			//http://localhost/creatim/nicelabel/Support/FAQ/Installation#g11		
		}
		
		if (url != '') {		    	
			baseUrl = location.href.replace(baseUrl, '');
						
			if (isHash == true) {
		      baseUrl = baseUrl.replace(location.href.substr(location.href.indexOf("#")), '');
	        }
	        	           
			location.href = baseUrl + url;
		}
		
		return false;
	}
}

addOnLoad(faqRedirections);

//highslide image preloader TODO
//addOnLoad(hs.preloadImages(5));