function trim (myString)
{
return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function setText(elem, action){
	if(elem){
		//alert(elem.value);
		if(action == 'enter'){
			if(elem.value == 'Enter item or keyword'){
				elem.value = '';
			}
		} else{
			if(trim(elem.value) == ''){
				elem.value = 'Enter item or keyword';
			}
		}
	}
}


function clearText(field){

    if (field.defaultValue == field.value) {
    
    	field.value = '';
    	
    } else if (field.value == '') {
    
    	field.value = field.defaultValue;
    }
    
}


var current_fs_item = 1; // stores value for Featured Store div which now is displayed. Is is changed by function sfChangeBlock
var total_fs_divs = -1; //stores value for how mutch there are Featured Store divs which will have to be scrolled


function sfChangeBlock(nr){

	var main_div = document.getElementById('featuredStore');
	if(main_div){		
		var inner_divs = sfGetTotalFsDivs();		
		if(inner_divs > 1){ //if there are divs to change
		
			var current_active_div = sfGetCurrentFSItemIndex();
			
			var new_index = sfGetCurrentFSItemIndex() + nr;
			if(new_index < 1){ //if we reached first item, by moving left we jump to the last div (moving around)
				new_index = inner_divs;
			} else if(new_index > inner_divs){
				new_index = 1;			
			}
			sfSetCurrentFSItemIndex(new_index);
			
			var div_id = 'featStor'+new_index;
			
			sfHideDiv(sfGetFsDivIdPrefix()+current_active_div);
			
			var activate_div = sfGetFsDivIdPrefix()+new_index;
			
			sfShowDiv(activate_div);
		}		
		
	}	
}


function sfGetFsDivIdPrefix(){
	return 'featStor';
}

function sfShowDiv(div_id){
	var elem = document.getElementById(div_id);
	if(elem){
		elem.style.display = 'block';
	}
}

function sfHideDiv(div_id){
	var elem = document.getElementById(div_id);
	if(elem){
		elem.style.display = 'none';
	}
}

function sfGetCurrentFSItemIndex(){
	return current_fs_item;
}

function sfSetCurrentFSItemIndex(index){
	current_fs_item = index;
}

function sfGetTotalFsDivs(){
	if(total_fs_divs < 0){
		var main_div = document.getElementById('featuredStore');
		total_fs_divs = sfCountInnerDivs(main_div, 'featStorItem')
	}
	return total_fs_divs;
}


function sfCountInnerDivs(container_div, common_class_name){
	if(container_div && common_class_name){
		var all_inner_divs = container_div.getElementsByTagName("div");
		var inner_divs = 0; //divs which is used for displaying/hiding content
		for( var i = 0; i < all_inner_divs.length; i++ ){
			if(all_inner_divs[i].className == common_class_name){
				inner_divs++;
			}
		}
		return inner_divs;
	} 
}





/* FOR CHANGING DIV IN BOTTOM BANNER (HOMEPAGE) */

var current_bb_item = 1; // stores value for bottom banner div which now is displayed. Is is changed by function sfChangeBannerBlock
var total_bb_divs = -1; //stores value for how mutch there are bottom banner divs which will have to be scrolled


function sfChangeBannerBlock(nr){
	var main_div = document.getElementById('logoHolder');
	if(main_div){		
		var inner_divs = sfGetTotalBbDivs();		
		if(inner_divs > 1){ //if there are divs to change
		
			var current_active_div = sfGetCurrentBbItemIndex();
			
			var new_index = sfGetCurrentBbItemIndex() + nr;
			if(new_index < 1){ //if we reached first item, by moving left we jump to the last div (moving around)
				new_index = inner_divs;
			} else if(new_index > inner_divs){
				new_index = 1;			
			}
			sfSetCurrentBbItemIndex(new_index);
						
			sfHideDiv(sfGetBbDivIdPrefix()+current_active_div);
			
			var activate_div = sfGetBbDivIdPrefix()+new_index;
			
			sfShowDiv(activate_div);
			
			//alert(new_index);
		}		
		
	}	
}


function sfGetBbDivIdPrefix(){
	return 'logoCont';
}

function sfSetCurrentBbItemIndex(index){
	current_bb_item = index;
}

function sfGetCurrentBbItemIndex(){
	return current_bb_item;
}

function sfGetTotalBbDivs(){
	if(total_bb_divs < 0){
		var main_div = document.getElementById('logoHolder');
		total_bb_divs = sfCountInnerDivs(main_div, 'logo')
	}
	return total_bb_divs;
}	

function sfPreloadMenuImages(){
	var full_folder_name = '/template-resources/images/';
	var images = new Array("menu1_a.gif", "menu2_a.gif", "menu3_a.gif", "menu4_a.gif", "menu5_a.gif", "menu6_a.gif", "menu7_a.gif", "menu8_a.gif", "menu9_a.gif", "menu10_a.gif");
	var tmp_img = new Image();
	for(var i = 0; i < images.length; i++){
		tmp_img.src = full_folder_name + images[i];
	}
}