// JavaScript Document

//source for redesign


<!--


function validate() //check if answer all questions
{

var cnt =0;
var divs = document.getElementsByTagName('div')
for(i=0; i <divs.length;i++)
{
if(divs[i].id.indexOf('checkboxgroup') != -1)
{
var el = divs[i].getElementsByTagName('input')
var cnt =0;
for(j=0; j <el.length; j++)
{

if(el[j].type == "checkbox" && el[j].checked == true)
cnt++;
}

if(cnt == 0)
{
alert("Please answer all the questions on this survey, thank you!");
return false;
}

}
}
}//end validate



function checksubmit(){  //check if shipping to PO Box
var continueCheckout = true;
tempst1=document.getElementById('street').value;
tempst2=document.getElementById('street2').value;
re1=/\./g;re2=/\040/g;

tempst1 = tempst1.toUpperCase(); 
tempst1=tempst1.replace(re1,"");
tempst1=tempst1.replace(re2,"");
tempst2 = tempst2.toUpperCase(); 
tempst2=tempst2.replace(re1,"");
tempst2=tempst2.replace(re2,"");


if(continueCheckout && tempst1.indexOf('POBOX')==-1)
document.getElementById("pass1").innerHTML="";

if(continueCheckout && tempst2.indexOf('POBOX')==-1)
document.getElementById("pass2").innerHTML="";

if(continueCheckout && tempst1.indexOf('POBOX')!=-1) {
continueCheckout = false;
alert("Sorry, we do not ship to PO Boxes.");
document.shipto.street.focus();

document.getElementById("pass1").innerHTML="?";
return false;

}

if(continueCheckout && tempst2.indexOf('POBOX')!=-1) {
continueCheckout = false;
alert("Sorry, we do not ship to PO Boxes.");
document.shipto.street2.focus();
document.getElementById("pass2").innerHTML="?";
return false;

}





if( continueCheckout ){
document.shipto.submit();
}


}  //end checksubmit


function checksubmit2(){  //check if shipping to PO Box
var continueCheckout = true;
tempst1=document.getElementById('street').value;
tempst2=document.getElementById('street2').value;
re1=/\./g;re2=/\040/g;

tempst1 = tempst1.toUpperCase(); 
tempst1=tempst1.replace(re1,"");
tempst1=tempst1.replace(re2,"");
tempst2 = tempst2.toUpperCase(); 
tempst2=tempst2.replace(re1,"");
tempst2=tempst2.replace(re2,"");


if(continueCheckout && tempst1.indexOf('POBOX')==-1)
document.getElementById("pass1").innerHTML="";

if(continueCheckout && tempst2.indexOf('POBOX')==-1)
document.getElementById("pass2").innerHTML="";

if(continueCheckout && tempst1.indexOf('POBOX')!=-1) {
continueCheckout = false;
alert("Sorry, we do not ship to PO Boxes.");
document.shipto.street.focus();

document.getElementById("pass1").innerHTML="?";
return false;

}

if(continueCheckout && tempst2.indexOf('POBOX')!=-1) {
continueCheckout = false;
alert("Sorry, we do not ship to PO Boxes.");
document.shipto.street2.focus();
document.getElementById("pass2").innerHTML="?";
return false;

}

/*
var PromoCode=document.getElementById("promo").value
PromoCode=PromoCode.toUpperCase();
if(PromoCode=='STYLE148'){
document.getElementById("promo").value='STYLE148-2';
}
*/

if( continueCheckout ){
document.shipto.submit();
}


}  //end checksubmit2

function checkQuicksearch(){  //check if search for nothing

	if(!document.quicksearch.keyword.value || document.quicksearch.keyword.value == 'enter search keyword')

		{

			alert("please type in a search term");

			return false;

		}

}  // end checkQuicksearch



function join(){ // submit mailchimp form
document.mailchimp.submit();
}


//show and hide layers

  function showdetail(id) 
  { 
    document.getElementById(id).style.display=''; 
  } 
  function hidedetail(id) 
  { 
    document.getElementById(id).style.display='none'; 
  }
//end show and hide functions



function open_ship(){ // open shipping detail page

window.open('http://www.lafayette148.com/FreeShipping_SP09.html','FreeShipping','toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,width=324,height=288');
}

function open_ship_PS10(){ // open shipping detail page
window.open('http://www.lafayette148.com/FreeShipping_PS10.html','FreeShipping','toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,width=324,height=288');
}


function zoomlayer(){ // write the zoom layer
				var paramString = 'zoomifyImagePath='+newPhotoTemp;

				document.write("	<OBJECT CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'");
				document.write("           CODEBASE='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'");
				document.write("           WIDTH='525'");
				document.write("           HEIGHT='425'");
				document.write("           ID='theMovie'>");
				document.write("    		<PARAM NAME='src' VALUE='/Pages/ZoomifyDynamicViewer_SP09.swf'>");
				document.write("			<PARAM NAME='FlashVars' VALUE='" + paramString + "' >");
				document.write("		<EMBED SRC='/Pages/ZoomifyDynamicViewer_SP09.swf'");
				document.write("		   FlashVars='" + paramString + "'");
				document.write("           PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'");
				document.write("           WIDTH='525'");
				document.write("           HEIGHT='425'");
				document.write("           NAME='theMovie'>");
				document.write("    	</EMBED>");
				document.write("   </OBJECT>");
} // end zoomlayer

//cookies functions

function setCookie2(name, value) { //expires in a month
  var today = new Date()
  var expires = new Date()
  expires.setTime(today.getTime() + 1000*60*60*24*30)
  document.cookie = name + "=" + escape(value)    + "; expires=" + expires.toGMTString() +";path=/"
}

function setCookie(name, value) { // no expires time
  var today = new Date()
  var expires = new Date()

  document.cookie = name + "=" + escape(value)    + ";path=/"
}

function getCookie(Name) {
 var search = Name + "="
 if(document.cookie.length > 0) {
   offset = document.cookie.indexOf(search)
   if(offset != -1) {
     offset += search.length
     end = document.cookie.indexOf(";", offset)
     if(end == -1) end = document.cookie.length
     return unescape(document.cookie.substring(offset, end))
   }
   else return ""
 }
}

//end cookies functions


//start checkout form validation

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateFormCheckout(){
	//var Phone=document.frmSample.txtPhone
	var Phone=document.getElementById('Phone');
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus();
		return false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.focus();
		return false;
	}

  if(document.getElementById('Street')){
var Street=document.getElementById('Street');
StringStreet=Street.value;
StringStreet = StringStreet.replace(/(^\s*)|(\s*$)/g, "");
	if ((StringStreet==null)||(StringStreet=="")){
		alert("Please Enter your Address")
                Street.focus();
		return false;
	}
  }

	return true;
 }


//end checkout form validation


//code to remove yellow background of input box, for ie with google toolbar

  if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }

//end code


function open_scSP09(){ // open size chart popup

window.open('http://www.lafayette148.com/size-charts-SP09.html','SizeChart','height=602,width=850,top=20,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');
}

function dropdown(id,action){
document.getElementById(id).style.display=action;

}

function HelpFocus(id){
document.getElementById(id).style.color = "#6d6d6d";
}

function swClass(status,catid){

if(status=='on'){
document.getElementById(catid).className="catlineON";

}else if(status=='off'){
document.getElementById(catid).className="catline";

}
}

function swSubClass(status,catid){

if(status=='on'){
document.getElementById(catid).className="subcatlineON";

}else if(status=='off'){
document.getElementById(catid).className="subcatline";
}
}

function checkAttrib2(){

	var ColorSubmit = document.getElementById('colors').value;
	var SizeSubmit = document.getElementById('sizes').value;

        if(ColorSubmit!="" && SizeSubmit!=""){

	document.getElementById('color').value = ColorSubmit+" - "+SizeSubmit;
	document.cartadd.submit();

	}else{

		alert("Please choose a color and a size, thanks.");

		return false;
		
	};

}

function writeSizes()
{
  var ColorSelected = document.getElementById('colors').value;

  for(var i=0;i<ColorHasPhoto.length;i++){
    if(ColorSelected == ColorHasPhoto[i]){
    var SelectedPhoto = ColorSelected.replace(reBlank,"-");
    swapIt(SelectedPhoto);
    break;
    }
  };

 if(ColorSelected == ''){
 document.getElementById('sizes').length = 1;
 }else{

  for(i=0;i<colors.length;i++){
    if(ColorSelected == colors[i]){  
      for(j=0;j<sizes[i].length;j++)
      {
    document.getElementById('sizes').options[j+1]=new Option(sizes[i][j],sizes[i][j]);
      }
   document.getElementById('sizes').options.selected=true;
    document.getElementById('sizes').length=j+1;
	}; // end if(ColorSelected == colors[i])
  }; // end for(i=0;i<colors.length;i++)
 }; // end if(ColorSelected == '') 
}

function hideselect(){
if(document.all){
document.getElementById('color').style.visibility="hidden";
document.getElementById('qty').style.visibility="hidden";
}
}
function showselect(){
if(document.all){
document.getElementById('color').style.visibility="visible";
document.getElementById('qty').style.visibility="visible";
}
}

function focusColorFunc(no){

  $('#focusColor').text($('.swatchImage').slice(no, no+1).attr('id'));
  $('.swatchImage').css("border-width","1px");
 // $('.swatchImage').css("margin-top","2px");
 // $('.swatchImage').slice(no, no+1).css("margin-top","0px");
  $('.swatchImage').slice(no, no+1).css("border-width","2px");
 // $('.swatchImage').attr("border","1")
 // $('.swatchImage').slice(no, no+1).attr("border","2");
//alert($('.swatchImage').slice(no, no+1).attr("border"));
}

function selectColorFunc(no){

  $('#colors').attr("value", $('.swatchImage').slice(no, no+1).attr('id'));
  writeSizes(); //fill size dropdown

}


function estimateShipDate(fullDate){

dateArray = fullDate.split("/");

orderDate = new Date('20'+dateArray[2],dateArray[0]-1,dateArray[1]);

orderDate.setDate(orderDate.getDate()+42); //add 5 weeks to order date

shipDate = orderDate.getMonth()+1;
shipDate = shipDate + '/' + orderDate.getDate()
shipDate = shipDate + '/' + orderDate.getFullYear();

return shipDate;

}

--> 
