function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Global Variable
num_boutique_categories = 20;

function CalcMessagePrice()
{
	with( document.orderForm )
	{
		totalLength = m.value.length;
		
		
		if( totalLength <= 10 )
			return 0.00;
		else
		{
			matches = m.value.match(/\s/g);
			if( matches )
			{
				
				extraChars = totalLength - 10 - matches.length;

				if( extraChars < 1 )
					return 0.00;
				
				if( f.selectedIndex != 2 && f.selectedIndex != 4 )
					return parseInt(extraChars) * .75;
				else
					return parseInt(extraChars) * 1.00;
			}
			else
			{
				extraChars = totalLength - 10;
				
				if( extraChars < 1 )
					return 0.00;				
				
				if( f.selectedIndex != 2 && f.selectedIndex != 4 )
					return parseInt(extraChars) * .75;
				else
					return parseInt(extraChars) * 1.00;
			}
		}
	}
}



function CheckForm()
{
	document.formOK = true;
	
	errorMessage = '';

	with( document.orderForm )
	{
		if( c.length < 1 )
		{
			errorMessage = errorMessage + 'Please choose a color for your item\n';
			document.formOK = false;			
		}
		
		if( !ot[0].checked && !ot[1].checked )
		{
			errorMessage = errorMessage + 'Please Complete Step 2: A) Shop the Boutique or B) Totally Customize\n';
			document.formOK = false;
		}
		else
		{
			if( ot[1].checked )
			{				
				if( m.value.length == 0 )
				{
					errorMessage = errorMessage + 'You forgot to include a message to put on your item!\n';
					document.formOK = false;		
				}			
			}
			else if( ot[0].checked )
			{
// ------------------- ADD NEW BOUTIQUE INFO HERE!! --------------------------------------------

				found_a_selected_boutique_item = false;
				
				for( i = 1; i <= num_boutique_categories && !found_a_selected_boutique_item; i++ )
				{
					if( document.getElementById('si' + i) )
						found_a_selected_boutique_item = ( document.getElementById('si' + i).selectedIndex != 0 )			
				}

				if( !found_a_selected_boutique_item )
				{
					errorMessage = errorMessage + 'Please choose a boutique design for your item.\n';
					document.formOK = false;
				}
			}

			RcolorChoosen = false;
			for( i = 0; i < r.length && !RcolorChoosen; i++ )
			{
				if( r[i].checked )
					RcolorChoosen = true;
			}
			if( !RcolorChoosen )
			{
				errorMessage = errorMessage + 'You forgot to choose a rhinestone color!\n';
				document.formOK = false;
			}
		}
		
	}
	
	if( !document.formOK )
	{
		alert( errorMessage );
	}

}

function ChangeBoutique()
{


	with( document.orderForm )
	{
		var wVal = '';
		var bMark = '';
		if(  ot[0].checked  )
		{
			wVal = 1;
			bMark = '#S2';
		}
		else if ( ot[1].checked )
		{
			wVal = 2;
			bMark = '#S2';
		}			
	
		var siVal = 5;
		var reloadPage = false;
// ------------------- ADD NEW BOUTIQUE INFO HERE!! ----------------		
		
		for( i = 1; i <= num_boutique_categories; i++ )
		{
			if( document.getElementById('si' + i) )
				if( document.getElementById('si' + i).selectedIndex != 0 )	
				{
					siVal = document.getElementById('si' + i)[document.getElementById('si' + i).selectedIndex].value
					reloadPage = true;
				}
		}

		
		if( reloadPage == true )
		{
			productChoosen = false;
			choosenProduct = 5;
			
			for( i = 0; i < p.length && !productChoosen; i++ )
			{
				if( p[i].checked )
				{
					productChoosen = true;
					choosenProduct = p[i].value;
				}
			}
		
			sVal = s[s.selectedIndex].value;
			cVal = c[c.selectedIndex].value;
	
			window.location='index.php?ot='+wVal+'&s='+sVal+'&c='+cVal+'&si='+siVal+'&p='+choosenProduct+bMark;
		}
	}

}

function BlankOthers( keep )
{
	
// ------------------- ADD NEW BOUTIQUE INFO HERE!! ----------
	with( document.orderForm )
	{		
		for( i = 1; i <= num_boutique_categories; i++ )
		{
			if( document.getElementById('si' + i) )	
				if( keep != document.getElementById('si' + i) )
					document.getElementById('si' + i).selectedIndex = 0;
		}
	}
	
}

function enableDesigns()
{
	with( document.orderForm )
	{
// ------------------- ADD NEW BOUTIQUE INFO HERE!! ----------
		
		for( i = 1; i <= num_boutique_categories; i++ )
		{
			if( document.getElementById('si' + i) )	
				document.getElementById('si' + i).disabled = false
		}			
		
		f.disabled = true;
		m.disabled = true;
		heart[0].disabled = true;
		heart[1].disabled = true;

		position[0].disabled = true;
		position[1].disabled = true;
		position[2].disabled = true;
		
		special.disabled = true;

		for( i = 0; i < cp.length; i++ )
		{
			cp[i].disabled = true;
		}
		for( i = 0; i < r.length; i++ )
		{
			r[i].disabled = false;
		}
		r[0].checked = true;
	}
	identity=document.getElementById('design');
	identity2=document.getElementById('custom');
	
	
 	identity.className = 'en';
	identity2.className = 'dis';
}

function enableCustom()
{

	with( document.orderForm )
	{
// ------------------- ADD NEW BOUTIQUE INFO HERE!! ----------
		for( i = 1; i <= num_boutique_categories; i++ )
		{
			if( document.getElementById('si' + i) )	
				document.getElementById('si' + i).disabled = true
		}	

		f.disabled = false;
		m.disabled = false;
		heart[0].disabled = false;
		heart[1].disabled = false;

		position[0].disabled = false;
		position[1].disabled = false;
		position[2].disabled = false;
		
		special.disabled = false;

		for( i = 0; i < cp.length; i++ )
		{
			cp[i].disabled = false;
		}
		for( i = 0; i < r.length; i++ )
		{
			r[i].disabled = false;
		}
	}
	
	
	
	identity=document.getElementById('design');
	identity2=document.getElementById('custom');
	
	identity.className = 'dis';
	identity2.className = 'en';
}

function changeShirtStyle( newstyle, goURL, extra )
{
	if( typeof(extra) == "undefined" )
		document.orderForm.action = goURL + '?p=' + newstyle;
	else
		document.orderForm.action = goURL + '?p=' + newstyle + extra;

	document.orderForm.submit();
}

function changeSize( goURL, extra )
{
	with( document.orderForm )
	{
		for( i = 0; i < p.length; i++ )
		{
			if( p[i].checked )
				selectedPID = i;
		}		
		
		PID     = p[ selectedPID ].value;
		newsize = s.value;
	}

	if( typeof(extra) == "undefined" )
		document.orderForm.action = goURL + '?p=' + PID + '&s=' + newsize;
	else
		document.orderForm.action = goURL + '?p=' + PID + '&s=' + newsize + extra;
	
	document.orderForm.submit();
}

function CrystalOnly()
{
	with( document.orderForm )
	{
		if(  ot[0].checked  )
		{
			wrongOneSet = false;
		
			for( i = 1; i < r.length; i++ )
			{
				if( r[i].checked )
					wrongOneSet = true;
			}		
		
		
			if( wrongOneSet )
			{
				alert( 'This stock design is only available in what\nis shown on our site. If you would like\nto select different colors, please contact\ncustomer service at 1-877-744-6378\nor email sales@rhinestonerevival.com');
				
				for( i = 1; i < r.length; i++ )
				{
					r[i].checked = false;
				}				
				r[0].checked = true;
			}
		} 
	}
}

function enlargePhoto( theURL )
{
	window.open( '/products/showLarger.php?show=' + theURL, 'DetailView', 'height=300,width=350' );
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}