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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Prod_Swap(color, name)
{
	document.getElementById('prod').src = color;
	document.getElementById('title').innerHTML = name;
	document.prod_purchase.image_holder.value = color;
	for (var i=0;i<document.prod_purchase.form_color.options.length;i++) 
	{
    	if (document.prod_purchase.form_color.options[i].value == name)
		{
      		  document.prod_purchase.form_color.options[i].selected = true;
			  document.getElementById('dropdown_sizes').innerHTML = size_paths[i];
		}
	}
}

function Color_Select()
{
	for (var i=0;i<color_paths.length;i++) 
	{
    	if (document.prod_purchase.form_color.value == color_paths[i][1])
		{
			document.getElementById('prod').src = color_paths[i][0];
			document.getElementById('title').innerHTML = color_paths[i][1];
			document.prod_purchase.image_holder.value = color_paths[i][0];
			document.getElementById('dropdown_sizes').innerHTML = size_paths[i];
		}
	}
}

function URL_Select(style)
{
	window.location = 'http://www.seasideshoes.com/jibbitz.php?style=' + style;
}
function URL_Select_Style(man,style)
{
	window.location = 'http://www.seasideshoes.com/product_view.php?man=' + man + '&style=' + style;
}
function URL_Select_Crocs(style)
{
	window.location = 'http://www.seasideshoes.com/crocs.php?style=' + style;
}

function Submit_Form()
{
	if (document.prod_purchase.form_size.value == '-1') 
	{
		alert('Please select a size from the dropdown menu.');
	}
	else
	{
		document.prod_purchase.submit();
	}
}

var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus)
{
	if(pos=="random")
	{
		myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center")
	{
		myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!='center' && pos!="random") || pos==null)
	{
		myleft=0;
		mytop=20;
	}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
	win.focus();
}

function Submit_Checkout_Form() 
{			
	form = document.form_checkout;
	
// CRDIT CARD INFO
	if(form.CardType.selectedIndex == 0)
	{
		alert('Please select a card type.');
		return false;
	}
	
	if ( (trim(form.CardNum1.value) == '') || (!IsNumeric(form.CardNum1.value)) ) 
	{
		alert('Please include a valid credit card number.');
		//form.CardNum1.value = "";
		form.CardNum1.focus();
		return false;
	}
	
	if ( (trim(form.CSC.value) == '') || (!IsNumeric(form.CSC.value)) ) 
	{
		alert('Please include a valid CSC number.');
		//form.CSC.value = "";
		form.CSC.focus();
		return false;
	}
	
	if(form.ExpirationMonth.selectedIndex == 0)
	{
		alert('Please select the month of expiration on your credit card.');
		return false;
	}
	
	if(form.ExpirationYear.selectedIndex == 0)
	{
		alert('Please select the year of expiration on your credit card.');
		return false;
	}
	
// BILLING INFO
	if (trim(form.x_first_name.value) == '') 
	{
		alert('Please include the first name of the person listed on your credit card.');
		form.x_first_name.value = "";
		form.x_first_name.focus();
		return false;
	}
	
	if (trim(form.x_last_name.value) == '') 
	{
		alert('Please include the last name of the person listed on your credit card.');
		form.x_last_name.value = "";
		form.x_last_name.focus();
		return false;
	}
	
	if (trim(form.x_address.value) == '') 
	{
		alert('Please include a billing address.');
		form.x_address.value = "";
		form.x_address.focus();
		return false;
	}
	
	if (trim(form.x_city.value) == '') 
	{
		alert('Please include a billing city.');
		form.x_city.value = "";
		form.x_city.focus();
		return false;
	}
	
	if(form.x_state.selectedIndex == 0)
	{
		alert('Please select a billing state.');
		return false;
	}
	
	if (trim(form.x_zip.value) == '') 
	{
		alert('Please include a billing zip code.');
		form.x_zip.value = "";
		form.x_zip.focus();
		return false;
	}
	
	if (trim(form.x_phone.value) == '') 
	{
		alert('Please include a contact phone number.');
		form.x_phone.value = "";
		form.x_phone.focus();
		return false;
	}
	
	checkEmail = form.x_email.value;
	if ( (checkEmail.indexOf('@') < 0) || (trim(form.checkEmail.value) == '') ) 
	{
		alert('Please include a contact e-mail address.');
		form.x_email.value = "";
		form.x_email.focus();
		return false;
	}

// SHIPPING INFO
	if (trim(form.x_ship_to_first_name.value) == '') 
	{
		alert('Please include the first name of the person we are shipping to.');
		form.x_ship_to_first_name.value = "";
		form.x_ship_to_first_name.focus();
		return false;
	}
	
	if (trim(form.x_ship_to_last_name.value) == '') 
	{
		alert('Please include the last name of the person we are shipping to.');
		form.x_ship_to_last_name.value = "";
		form.x_ship_to_last_name.focus();
		return false;
	}
	
	if (trim(form.x_ship_to_address.value) == '') 
	{
		alert('Please include a shipping to address.');
		form.x_ship_to_address.value = "";
		form.x_ship_to_address.focus();
		return false;
	}
	
	if (trim(form.x_ship_to_city.value) == '') 
	{
		alert('Please include a shipping to city.');
		form.x_ship_to_city.value = "";
		form.x_ship_to_city.focus();
		return false;
	}
	
	if(form.x_ship_to_state.selectedIndex == 0)
	{
		alert('Please select a shipping to state.');
		return false;
	}
	
	if (trim(form.x_ship_to_zip.value) == '') 
	{
		alert('Please include a shipping to zip code.');
		form.x_ship_to_zip.value = "";
		form.x_ship_to_zip.focus();
		return false;
	}
	
		
	else 
	{
		form.CardNum.value  = form.CardNum1.value;
		form.CardNum1.value = "";
		return true;
	}
}

function CopyFromBilling()
{
	form = document.form_checkout;	
	if(form.x_copy_bill.checked)
	{
		form.x_ship_to_first_name.value = form.x_first_name.value;
		form.x_ship_to_last_name.value = form.x_last_name.value;
		form.x_ship_to_address.value = form.x_address.value;
		form.x_ship_to_city.value = form.x_city.value;
		form.x_ship_to_state.selectedIndex = form.x_state.selectedIndex;
		form.x_ship_to_zip.value = form.x_zip.value;
	}
	else
	{
		form.x_ship_to_first_name.value = "";
		form.x_ship_to_last_name.value = "";
		form.x_ship_to_address.value = "";
		form.x_ship_to_city.value = "";
		form.x_ship_to_state.selectedIndex = 0;
		form.x_ship_to_zip.value = "";
	}
}

function IsNumeric(sText)

{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i=0; (i<sText.length) && (IsNumber == true); i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			IsNumber = false;
	}
	return IsNumber;
}

function Send_Mail_Form(form)
{
	if (trim(form.form_name.value) == '') 
	{
		alert('Please include your name.');
		form.form_name.value = "";
		form.form_name.focus();
		return false;
	}
			
	checkEmail = form.form_email.value
	if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
	{
		alert("Please include a Valid e-mail address.");
		if(trim(form.form_email.value) == '')
			form.form_email.value = "";
		else
			form.form_email.select();
		form.form_email.focus();
		return false;
	} 
	
	if (trim(form.form_message.value) == '') 
	{
		alert('Please include a message.');
		form.form_message.value = "";
		form.form_message.focus();
		return false;
	}
		
	else 
	{
		return true;
	}
}

function trim(inputString) 
{
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") 
		return inputString;
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{ // Check for spaces at the beginning of the string
	  	retValue = retValue.substring(1, retValue.length);
	  	ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") 
	{ // Check for spaces at the end of the string
	  	retValue = retValue.substring(0, retValue.length-1);
	  	ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) 
	{ // Note that there are two spaces in the string - look for multiple spaces within the string
	  	retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; // Return the trimmed string back to the user
}
