var bw = checkBrowser();

function checkBrowser(){
	this.os=navigator.OS
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns6=(!document.all && document.getElementById) ? true : false;
	this.ns5=(this.dom && parseInt(this.ver) == 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5 || this.ns6)
	this.macOS = navigator.userAgent.indexOf('Mac')!=-1;
	this.winOS = navigator.userAgent.indexOf('Win')!=-1;
	return this;
}

if (bw.ie5&&bw.macOS || bw.ie4&&bw.macOS || bw.ie6&&bw.macOS){
	document.location.href="./redirect/index.html";
}

var currSize = "1";
var currBandColor = "black";


function init(section){
  //init calls
  if (section=='menscustomwatchestheclassic') {
  	preloadClassic();
  }
  if (section=='menscustomwatchesscout') {
  	preloadMensScout();
  }
  else if (section == 'menscustomwatchesthejetson') {
  	preloadMensJetson();
  }
  else if (section=='menscustomwatchesthediver') {
  	preloadMensDiver();
  }
  else if (section=='menscustomwatchesthechrono') {
  	preloadChrono();
  }
  else if (section=='menscustomwatcheslemans') {
  	preloadLemans();
  }
  else if (section=='menscustomwatchesgt') {
  	preloadGT();
  }
  else if (section=='menscustomwatchesbomber') {
  	preloadBomber();
  }
  else if (section=='menscustomwatchesnavigator') {
	preloadNavigator();
  }
  else if (section=='ladiescustomwatchestheclassic') {
  	preloadLadiesClassic();
  }
  else if (section=='ladiescustomwatchesthejetson') {
  	preloadLadiesJetson();
  }
  else if (section=='ladiescustomwatchesladiesdiver') {
  	preloadLadiesDiver();
  }
  else if (section=='ladiescustomwatchesl7') {
  	preloadLadiesL7();
  }
  else if (section=='ladiescustomwatchesl7doublewrap') {
  	preloadLadiesL7Double();
  }
  else if (section=='ladiescustomwatchesl7triplewrap') {
  	preloadLadiesL7Triple();
  }
  else if (section=='ladiescustomwatchesladiesbullet') {
  	preloadLadiesbullet();
  }
  else if (section=='unisexcustomwatchesl7') {
  	preloadUnisexL7();
  }
  else if (section=='unisexcustomwatchesvintage') {
  	preloadUnisexVintage();
  }
}

function getTextMinusPrice(text) {
	//get oldSize minus the price
	var text_array=text.split(" (");
	text = text_array[0];
	return text;
}

function swapBand(size, color, section){    
    changeImage('prod_layer_1', 'prod_layer_1', 'band'+'_'+section+'_'+size+'_'+color);  
}

function swapFace(color, section){
    changeImage('prod_layer_2', 'prod_layer_2', 'face'+'_'+section+'_'+color);  
}

function getBandSize(oldSize){
	newSize = "";
	
	//get oldSize minus the price
	//var oldSize_array=oldSize.split(" (+");
	//oldSize = oldSize_array[0];
	oldSize = getTextMinusPrice(oldSize);

	for (i=0; i<oldSize.length; i++){
		if (oldSize.charAt(i) != ' ' && oldSize.charAt(i) != '"' && oldSize.charAt(i)!="/"){
			newSize+=oldSize.charAt(i);	
		}
	}
	return newSize;
}

function getColor(oldColor){
	newColor = "";
	for (i=0; i<oldColor.length; i++){
		if (oldColor.charAt(i) != ' ' &&  oldColor.charAt(i) != '-'){
			newColor+=oldColor.charAt(i);
		}
	}
	newColor = newColor.toLowerCase();
	return newColor;
}

function getName(oldName){
	newName= "";
	for (i=0; i<oldName.length; i++){
		if (oldName.charAt(i) != ' ' && oldName.charAt(i)!="'"){
			newName+=oldName.charAt(i);	
		}
	}
	newName= newName.toLowerCase();
	return newName;
}

function getCustOption(oldCustOption) {
	newCustOption= "";
	
	oldCustOption = getTextMinusPrice(oldCustOption);
	
	for (i=0; i<oldCustOption.length; i++){
		if (oldCustOption.charAt(i) != ' ' && oldCustOption.charAt(i)!= ')'  && oldCustOption.charAt(i)!= '('){
			newCustOption+=oldCustOption.charAt(i);	
		}
	}
	return newCustOption;
}


function getDistressed(oldCustOption) {
	newCustOption= "";
	
	oldCustOption = getTextMinusPrice(oldCustOption);
	
	for (i=0; i<oldCustOption.length; i++){
		if (oldCustOption.charAt(i) != ' ' && oldCustOption.charAt(i)!= ')'  && oldCustOption.charAt(i)!= '('){
			newCustOption+=oldCustOption.charAt(i);	
		}
	}
	return newCustOption;
}


function removePaintedColors() {		
		
	var dropdowns = document.forms[0].elements;	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==leather_color_name) {
			//we have the correct dropdown
			dropdowns[i].options.length=dyed_leather_names.length;
			//dropdowns[i].options.length=0;
			//populate it with dyed leather names and values						
			for (var j=0;j<dyed_leather_names.length;j++) {
				document.forms[0].elements[i].options[j] = new Option(dyed_leather_names[j], dyed_leather_values[j]);
			}
			break;			
		}
	}
}

function addPaintedColors() {
	var dropdowns = document.forms[0].elements;		
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==leather_color_name) {
			//we have the correct dropdown			
			var initLength = dropdowns[i].options.length;						
			//add the painted leather names and values						
			for (var j=0;j<painted_leather_names.length;j++) {
				document.forms[0].elements[i].options[j+initLength] = new Option(painted_leather_names[j], painted_leather_values[j]);
			}
			break;			
		}
	}
}

function removeStitchColors() {		
	//alert("removing stitch colors");
	//don't remove stitch colors if we don't have the dropdown for it!
	if (!has_stitch_dd) return;
	
	var dropdowns = document.forms[0].elements;	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==stitch_name) {
			//we have the correct dropdown			
			dropdowns[i].options.length=0;
			dropdowns[i].options[0] = new Option(stitch_names[0], stitch_values[0]);
		}
	}
	return;
}

function addStitchColors() {		
	if (!has_stitch_dd) return;
	var dropdowns = document.forms[0].elements;	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==stitch_name) {
			//we have the correct dropdown						
			dropdowns[i].options.length=0;					
			//add the stitch color names and values						
			for (var j=0;j<stitch_names.length;j++) {
				dropdowns[i].options[j] = new Option(stitch_names[j], stitch_values[j]);
			}
			break;						
		}
	}
}

function showBandWidth118() {
	
	var dropdowns = document.forms[0].elements;	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==band_width_name) {	
			//we have the correct dropdown						
			dropdowns[i].options.length=0;					
			//add the stitch color names and values						
			var index = bandwidth_names[0].indexOf('&quot;');
			var name = bandwidth_names[0].substring(0,index)+"'' "+bandwidth_names[0].substring(index+6,bandwidth_names[0].length+1);
			
			dropdowns[i].options[0] = new Option(name, bandwidth_values[0]);
			//dropdowns[i].options[0] = new Option(bandwidth_names[0], bandwidth_values[0]);

			break;						
		}
	}
        currSize = "118";
        swapBand(currSize, currColor, section);	
}

function showBandWidth138() {
	
	var dropdowns = document.forms[0].elements;	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==band_width_name) {	
			//we have the correct dropdown						
			dropdowns[i].options.length=0;					
			//add the stitch color names and values						
			var index = bandwidth_names[1].indexOf('&quot;');
			var name = bandwidth_names[1].substring(0,index)+"'' "+bandwidth_names[1].substring(index+6,bandwidth_names[1].length+1);			
			dropdowns[i].options[0] = new Option(name, bandwidth_values[1]);
			break;						
		}
	}
        currSize = "138";
        swapBand(currSize, currColor, section);	
}

function showAllBandWidths() {
	
	var dropdowns = document.forms[0].elements;	
	var orig_value = "";
	
	for (var i=0;i<dropdowns.length;i++) {
		if (dropdowns[i].name==band_width_name) {	
			//we have the correct dropdown
			
			//get the currently selected value!!!
			orig_value = dropdowns[i][dropdowns[i].selectedIndex].text.substring(0,5);

			dropdowns[i].options.length=0;					
			
			//add the stitch color names and values						
			var index = bandwidth_names[0].indexOf('&quot;');
			var name0 = bandwidth_names[0].substring(0,index)+"'' "+bandwidth_names[0].substring(index+6,bandwidth_names[0].length+1);			
			
			index = bandwidth_names[1].indexOf('&quot;');
			var name1 = bandwidth_names[1].substring(0,index)+"'' "+bandwidth_names[1].substring(index+6,bandwidth_names[1].length+1);			
			dropdowns[i].options[0] = new Option(name0, bandwidth_values[0]);
			dropdowns[i].options[1] = new Option(name1, bandwidth_values[1]);
			
			if (orig_value == '1 1/8') {
				dropdowns[i].selectedIndex = 0;			
				currSize = "118";
				swapBand(currSize, currColor, section);		
			}
			else {
				dropdowns[i].selectedIndex = 1;
				currSize = "138";
				swapBand(currSize, currColor, section);		
			}							
			break;						
		}
	}
}

function changeImages() {
    if (document.images) {      
      for (var i=0; i<changeImages.arguments.length; i+=2) {
	  document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
    }
}

function changeClass(id, newClass) {
	alert("changing "+id+" to "+newClass);
	identity=document.getElementById(id);
	alert("retrieved identity "+identity);
	identity.className=newClass;	
}
			
function viewProduct(pulldown, flag){
	var id = pulldown.options[pulldown.selectedIndex].value;
	if (id == -1) return;
	var url;
	if (flag == 1) url = "/store/product_info.php?products_id="+id;
	else if (flag == 2) url = "/store/product_info_custom.php?products_id="+id;
	document.location.href=url;
}

