function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
	
function popWin(url,win,para) {
    var win = window.open(url,win,para);
    win.focus();
}

function showTab(theid, thearray)
{ 			
	for(i = 0; i < thearray.length; i++)
	{ 
		if(thearray[i] == theid)
		{ 
			document.getElementById(theid).style.display="block"; 
		}
		else
		{ 
			document.getElementById(thearray[i]).style.display="none"; 
		} 
	} 
}

function setActiveLink(theid, thearray)
{
	for(i = 0; i < thearray.length; i++)
	{ 
		if(thearray[i] == theid)
		{ 
			document.getElementById(theid).setAttribute("class", "active");
		}
		else
		{ 
			if(thearray[i] != 'TAB3C')
				document.getElementById(thearray[i]).setAttribute("class", "");
			else
				document.getElementById(thearray[i]).setAttribute("class", "last");
		} 
	} 
}

function formSubmit(form)
{
	var f = document.getElementById(form);
	f.submit();
}

function roll_over(img_name, img_src)
{
	document[img_name].src = img_src;
}

function onchange_color(icstring, id)
{	
	var pos = id.selectedIndex;
	//get selected text	
	//+$
	var tempOpt = id.options[pos].text.split('+$');
	var optText;
	if(tempOpt.length > 1){
		optText = trim(tempOpt[0]);
	}	
	else{
		//-$
		tempOpt = id.options[pos].text.split('-$');
		if(tempOpt.length > 1){
			optText = trim(tempOpt[0]);
		}
		else{
			optText = trim(id.options[pos].text);
		}
	}
	
	var colorStr = icstring.split(':');
	if(colorStr.length > 1){
		for(var i=0;i<colorStr.length;i++){			
			var imgStr = colorStr[i].split('|');			
			if(imgStr.length > 1 && imgStr[1] != ''){
				if(imgStr[0].toLowerCase() == optText.toLowerCase()){
					var iName = imgStr[1].toLowerCase();
					var ipath = iName.substring(0,1).toLowerCase() + '/' + iName.substring(1,2).toLowerCase() + '/';
					roll_over('current-product-image', additional_image_url + ipath + iName);
					return;
				}
			}
		}
	}
}

function set_color(formName, sValue){
	var form = document.forms[formName];
	var exit = false;
	for(i = 0; i < form.elements.length; i++)	{
		elm = form.elements[i]		
		if (elm.type == 'select-one')	{			
			for(var j=0;j<elm.options.length;j++){				
				//get selected text	
				//+$
				var tempOpt = elm.options[j].text.split('+$');
				var optText;
				if(tempOpt.length > 1){
					optText = trim(tempOpt[0]);
				}	
				else{
					//-$
					tempOpt = elm.options[j].text.split('-$');
					if(tempOpt.length > 1){
						optText = trim(tempOpt[0]);
					}
					else{
						optText = trim(elm.options[j].text);
					}
				}
				
				if(sValue.toLowerCase() == optText.toLowerCase()){
					try{
						elm.selectedIndex = j;					
					}
					catch(e){}
					exit = true;
					break;
				}				
			}
		}
		
		if(exit){
			opConfig.reloadPrice();
			break;
		}
	} 	 
}

