//////////////// function for ajax card recommender \\\\\\\\\\\\\\\\\\\\\\\\\
function searchCards(path) {
		var client_type = document.getElementById('client_type_holder').value;    // consumer, business or student
		var credit_history = document.getElementById('credit_history_holder').value;    // excellent, good, bad, no credit
		var urlToOpen = 'http://'+path+'/cards/searchcards?client_type='+client_type+'&credit_history='+credit_history
		//alert(urlToOpen);
		var req;
		try {
			req=new GeckoActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				req=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				req=null;
			}
		}
		if(!req && typeof XMLHttpRequest != "undefined")
			req = new XMLHttpRequest();
		if (!req)
			alert("Could not create connection object.");
		try
		{
			req.onreadystatechange = function(){
	    	if (req.readyState == 4) 
	    	{
	            if (req.status == 200) {
	                response=req.responseText; //aici facem prelucrarea
	                //if(response < 100 ) {
	                	document.getElementById('nrfound').innerHTML = response;
	               // } else {  // ca sa nu stricam design-ul, daca is mai mult de 100 de carduri punem 99
	              //  	document.getElementById('nrfound').innerHTML = '99';
	              //  }
	                
	            } else {
		                alert(urlToOpen+' '+req.status+' There was a problem with the request.');
		        }
	        }
			};
			req.open('GET', urlToOpen, true);
			req.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');
			req.send(null);
			//document.write(urlToOpen);
		}
		catch(ex)
		{
			alert('Ex ' + ex.name + " - " + ex.message);
		}
	}
	
function searchCardsWithOptions(path, option) {
		var mode;
		var client_type = document.getElementById('client_type_holder').value;
		var credit_history = document.getElementById('credit_history_holder').value;
		if(document.getElementById(option).checked == true) {
			mode = 'on';
		} else {
			mode = 'off';
		}
		var urlToOpen = 'http://'+path+'/cards/searchcards?client_type='+client_type+'&credit_history='+credit_history+'&option='+option+'&mode='+mode
		//alert(urlToOpen);
		var req;
		try {
			req=new GeckoActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
				req=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				req=null;
			}
		}
		if(!req && typeof XMLHttpRequest != "undefined")
			req = new XMLHttpRequest();
		if (!req)
			alert("Could not create connection object.");
		try
		{
			req.onreadystatechange = function(){
		    	if (req.readyState == 4) 
		    	{
		            if (req.status == 200) {
		                response=req.responseText; //aici facem prelucrarea
		                //alert(response);
		                if(response < 100) {
		                	document.getElementById('nrfound').innerHTML = response;
		                } else {
		                	document.getElementById('nrfound').innerHTML = '99';
		                }
		            } else {
			                alert(urlToOpen+' '+req.status+' There was a problem with the request.');
			        }
		        }
			};
			req.open('GET', urlToOpen, true);
			req.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');
			req.send(null);
		}
		catch(ex)
		{
			alert('Ex ' + ex.name + " - " + ex.message);
		}
	}	
	
///////// functions for save this card / remove this cards from saved cards \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+	((expiredays==null) ? ""+"; path=/" : ";expires="+exdate.toGMTString()+"; path=/")
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
    {
	    c_start=document.cookie.indexOf(c_name + "=")
	    if (c_start!=-1)
	    { 
	      c_start=c_start + c_name.length+1 
	      c_end=document.cookie.indexOf(";",c_start)
	      if (c_end==-1) c_end=document.cookie.length
	           return unescape(document.cookie.substring(c_start,c_end))
	    } 
	}
	return ""
}
	
function savecard(id) {
	// get number of saved cards
	var nr = getCookie('nrcards');
	if(nr == "") {
		setCookie("card_order", "_");
	}
	if(nr == 6) {
		alert('You have already saved 6 cards');
		return;
	}
	nr ++;
	setCookie("nrcards", nr);
	setCookie("card_"+id, id);
	var card_order = getCookie("card_order");
	setCookie("card_order", card_order+id+"_");
	checkSaved(id);
		
	var val = parseFloat(document.getElementById('val').innerHTML);
	if(val==0) {
		document.getElementById('on').style.display = 'block';
		document.getElementById('off').style.display = 'none';
	}
	document.getElementById('val').innerHTML = val + 1;
}
	
function removecard(id) {

	setCookie('card_'+id, '', -1);
	var nr = getCookie('nrcards');
	nr --;
	setCookie('nrcards', nr);
	var card_order = getCookie("card_order");
	
	setCookie("card_order", card_order.replace("_"+id+"_","_"));
	//alert(document.cookie)
	checkSaved(id);
	
	var val = parseFloat(document.getElementById('val').innerHTML);
	if(val==1) {
		document.getElementById('on').style.display = 'none';
		document.getElementById('off').style.display = 'block';
	}
	document.getElementById('val').innerHTML = val-1;
}

function checkSaved_(id)     // old checkSaved function, (when a card couldn't appear twice on the same page)
{
	var check = getCookie('card_'+id);
	if(check != "") {
		// found 
		document.getElementById('add'+id).style.display = 'none';
		document.getElementById('remove'+id).style.display = 'block';
	} else {
		// not found 
		document.getElementById('add'+id).style.display = 'block';
		document.getElementById('remove'+id).style.display = 'none';
	}
}

function checkSaved(cardid) {
	
	var arr;          // array of elements displaying "save this card"
	var arr2;          // array of elements displaying "remove this card"
	arr = document.getElementsByClassName('add'+cardid);
	arr2 = document.getElementsByClassName('remove'+cardid);
	
	var i; 
	
	var check = getCookie('card_'+cardid);
	if(check != "") {
		// found 
		for(i = 0; i<arr.length; i++) {        
			arr[i].style.display = 'none';         // we are hiding "save this card"  - for each appearance of the card on page
			arr2[i].style.display = 'block';       // we are showing "remove this card"  - for each appearance of the card on page
		}
	} else {
		// not found 
		for(i = 0; i<arr.length; i++) {            // reverse operation in case card is not found in saved list
			arr[i].style.display = 'block';
			arr2[i].style.display = 'none';
		}
	}
	
}	

//////// FUNCTION FOR BOOKMARK US \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
function CreateBookmarkLink(url) {
   if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, url,"");
   } else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, document.title); 
   }
   else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

//////// FUNCTION FOR LEFT MENU \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//the main function, call to the effect object
	function init(){
		
		var stretchers = document.getElementsByClassName('slide'); //div that stretches
		var toggles = document.getElementsByClassName('slideTitle');       
		//accordion effect
		var myAccordion = new fx.Accordion(toggles, stretchers, {opacity: true, duration: 0});
		//hash functions
		var found = false;
		toggles.each(function(div, i){});
		//myAccordion.showNoToggle();
	}

// after clicking the title of a main category, which triggers the appearance of the subcategories, 
// the title becomes a link to the main category
	function transform(id)
	{ 
	   var current_id = document.getElementById('selected').innerHTML;    // the title previously clicked
	   																	// we have to restore it's state
	   
	   if(current_id) {
	   	 document.getElementById("href"+current_id).style.display = 'none';
	   	 document.getElementById("title"+current_id).style.display = 'block';
	   }
	   
	   document.getElementById("title"+id).style.display = 'none';  // the clicked title becomes invisible
	   document.getElementById("href"+id).style.display = 'block';  // the link title becomes visible
	    
	   document.getElementById('selected').innerHTML = id;   // keep this value for we need it for the next click
	   
	}
	
	
//show/hide functionality
	function showhide(id)
	{ 
		if (document.getElementById)
		{ 
			obj = document.getElementById(id); 
			if (obj.style.display == "none")
			{ 
				obj.style.display = ""; 
			} 
			else
			{ 
				obj.style.display = "none"; 
			} 
		} 
	}