function CheckthatItemWasSelected(NumItems)
{var Flag=0;
var alertText;
	for(i=0; i<document.forms[0].elements.length; i++){
     if(document.forms[0].elements[i].type == "checkbox")
     	{
     	if(document.forms[0].elements[i].checked)
      	Flag=1;
      }
   }  
if(Flag == 1)
	{
	document.forms[0].submit();
	}
else
	{
	ErrorMessage='Please check item you want to return before continuing.';
	alert(ErrorMessage);
	}
	
}

function CheckReturnForm(MyForm)
{
//Go through each item to make sure return reason is selected
NumItems=MyForm.NumItems.value;
Count=1;
ErrorMessage='';
while(Count<=NumItems)
	{
	varname='RetCode'+Count;
	RetCode=eval('document.ReturnForm.'+varname+'.options[document.ReturnForm.RetCode'+Count+'.options.selectedIndex].value');
	if(RetCode=='')
		{
		//alert(RetCode);
		document.getElementById(varname).className = 'redTD';
		ErrorMessage+='Please select a reason for item '+Count+' of your return.\n';
		}	
	Count++;
	}

OrderNum=document.ReturnForm.OrderNumber.value




var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
CardType='';
	if(MyForm.CardType[0].checked)
		CardType='Visa';
	if(MyForm.CardType[1].checked)
		CardType='MasterCard';
	if(MyForm.CardType[2].checked)
		CardType='Discover';
	if(MyForm.CardType[3].checked)
		CardType='AmExpress';
		
	if(CardType =='')
		{
		document.getElementById('CardTypes').className = 'redTD';
		ErrorMessage+='Please Choose Card Type\n';
		}
	CCNum1=MyForm.CCNum1.value;
	if(CCNum1 == '')
		{
		document.getElementById('CardNum').className = 'redTD';
		ErrorMessage+='Please Fill in Card Box 1\n';
		}
	CCNum2=MyForm.CCNum2.value;	
	if(CCNum2 == '')
		{
		document.getElementById('CardNum').className = 'redTD';
		ErrorMessage+='Please Fill in Card Box 2\n';
		}
	CCNum3=MyForm.CCNum3.value;	
	if(CCNum3 == '')
		{
		document.getElementById('CardNum').className = 'redTD';
		ErrorMessage+='Please Fill in Card Box 3\n';
		}
	CCNum4=MyForm.CCNum4.value;	
	if(CCNum4 == '')
		{
		document.getElementById('CardNum').className = 'redTD';
		ErrorMessage+='Please Fill in Card Box 4\n';
		}
	Last4=MyForm.CCNum4.value;
		
	FullCCNum=CCNum1+CCNum2+CCNum3+CCNum4;
	CVV2=MyForm.CVV2.value;	
	if(CVV2 == '')
		{
		document.getElementById('CVV2Num').className = 'redTD';
		ErrorMessage+='Please Fill in all cvv2\n';
		}
	MonthExp=MyForm.MonthExp.value;	
	YearExp=MyForm.YearExp.value;	
	if(MonthExp <= curr_month)
		{
		if(curr_year == YearExp)
			{
			document.getElementById('ExpireDate').className = 'redTD';
			ErrorMessage+='Please Use a Card that is not expired.\n';
			}
		}


FirstName=MyForm.FirstName.value;
LastName=MyForm.LastName.value;
Address=MyForm.Address.value;
City=MyForm.City.value;
State=MyForm.ShipState.value;
Zip=MyForm.Zip.value;
if(FirstName == '')
	{
	document.getElementById('ShipFirstName').className = 'redTD';
	ErrorMessage+='Please enter First Name to continue.\n';
	}	
if(LastName == '')
	{
	document.getElementById('ShipLastName').className = 'redTD';
	ErrorMessage+='Please enter Last Name to continue.\n';
	}	
if(Address == '')
	{
	document.getElementById('ShipAddress').className = 'redTD';
	ErrorMessage+='Please enter Address to continue.\n';
	}	
if(City == '')
	{
	document.getElementById('ShipCity').className = 'redTD';
	ErrorMessage+='Please enter City to continue.\n';
	}	
if(State == '')
	{
	document.getElementById('ShipState').className = 'redTD';
	ErrorMessage+='Please Choose state before continuing.\n';
	}	
if(Zip == '')
	{
	document.getElementById('ShipZip').className = 'redTD';
	ErrorMessage+='Please enter Zip to continue.\n';
	}	
if(ErrorMessage == '')
	{
	MyForm.submit();
	}
else
	{
	alert(ErrorMessage);
	}
}


function CheckContactUsForm(MyForm)
{
ErrorMessage='';
Code=MyForm.Code.value;
if(Code != '123earth')
	{
	//document.getElementById('Code').className = 'redTD';
	ErrorMessage+='Please Enter Correct Security Code\n';
	}	
if(ErrorMessage == '')
	{
	MyForm.submit();
	}
else
	{
	alert(ErrorMessage);
	}
}

function TrakIt(ThisSrc)
{
//script = document.createElement( 'script' );
//script.src = 'https://www.naturalfootwear.com/phpscripts/pagetraker.php?Page='+ThisSrc;
//document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SizeSearch(Gender,Size)
{
document.getElementById('InvSizes').innerHTML = "Getting All available Sizes...";	
var url =SITE+'/phpscripts/AvailableSizeSearch.php?action=go&Gender='+Gender+'&Size='+Size;	
script = document.createElement( 'script' );
script.src = url;
document.getElementsByTagName( 'head' )[0].appendChild( script );	
}

function SwapColor(ColorCode,Style,ColorDesc,Gender,SubCat)
{
document.getElementById('ColorName').innerHTML = ColorDesc;
ProdN=Gender+' '+Style+' '+ColorDesc;
document.getElementById('ProductName').innerHTML = ProdN;
//alert(Style);
document.getElementById('ImgSwap').innerHTML = "Getting New Image...";	
GetAvailableSizes(ColorCode,Style,Gender);
script = document.createElement( 'script' );
script.src = SITE+'/phpscripts/ProductHandler.php?action=GetNewColorPic&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&SubCat='+SubCat;
//alert(script.src);
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SwapView(ColorCode,Style,Gender,View)
{
document.getElementById('ImgSwap').innerHTML = "Getting New Image...";	
script = document.createElement( 'script' );

script.src = SITE+'/phpscripts/ProductHandler.php?action=GetNewViewPic&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&View='+View;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function GetSelectedColorName(ColorDesc)
{
document.getElementById('ColorName').innerHTML = ColorDesc;
}

function GetColorMini(ColorCode,Style,ColorDescription,Gender)
{
script = document.createElement( 'script' );
script.src = SITE+'/phpscripts/ProductHandler.php?action=GetNewColorPicMini&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&DivID='+Style;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}


function GetAvailableSizes(ColorCode,Style,Gender,Availability)
{
//alert(ColorCode);
document.getElementById('AvailableSizes').innerHTML = 'Please wait, loading available sizes...';
script = document.createElement( 'script' );
Loc=SITE+'/phpscripts/ProductHandler.php?action=AvailableSizes&ColorCode='+ColorCode+'&Style='+Style+'&Gender='+Gender+'&Availability='+Availability
//alert(Loc);
script.src =Loc ;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function LoadMiniCart()
{
script = document.createElement( 'script' );
script.src = SITE+'/NewCart/CartHandler.php?action=LoadMiniCart';
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function SelectSize(SKU)
{
//alert(SKU);
if(SKU != '')
	{document.getElementById('SelectedSize').innerHTML = '<input type=hidden id=UPC12digit name=sku value='+SKU+'>';}

}

var whosChanged = null;
function ChangeColor(el)
{
el.style.backgroundColor = "#FE3000";
el.style.color = "#000000";
if (whosChanged != null)
{
whosChanged.style.backgroundColor = ""
whosChanged.style.color = ""
}
whosChanged = el;
}

function AddToCart(Action)
{		

	if(document.getElementById('UPC12digit'))
		{
		document.getElementById('superminicart').innerHTML = "<img src=\"'+SITE+'/images/AddingBag.jpg\">";
	  document.getElementById('ImgSwap').innerHTML = "<h1><font color=\"#138816\">Adding to cart...</font></h1>";
		var UPC12digit = document.getElementById('UPC12digit').value;			
		var Qty = document.getElementById('Qty').value;	
		//alert(UPC12digit);
		script = document.createElement( 'script' );
		TheScriptCall=SITE+'/NewCart/CartHandler.php?action='+Action+'&sku='+UPC12digit+'&Qty='+Qty;
		//alert(TheScriptCall);
		script.src = TheScriptCall;
		document.getElementsByTagName( 'head' )[0].appendChild( script );
		}
	else
		{
		alert('Please Choose a size.');
		}
}

function TrakPage()
{
//Link='https://'+SITE+'/pagetraker.php?Page='+window.location+'&Referer='+window.history.previous;
//script = document.createElement( 'script' );
//script.src =Link;
//document.getElementsByTagName( 'head' )[0].appendChild( script );
}
//TrakPage();

function LoadStyleDropDown()
{
var url =SECURESITE+'/phpscripts/ProductHandler.php?action=LoadStyleDropDown';	
script = document.createElement( 'script' );
script.src = url;
document.getElementsByTagName( 'head' )[0].appendChild( script );		
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) /1.1;
	var wint = (screen.height - h) / 5;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features?
    winFeatures = "," + winFeatures+',';
  else
    winFeatures = ""
  //window.open('jex5.htm','mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += 'width='+winWidth+',height='+ winHeight+',left='+ winLeft+',top='+ winTop;
  else
    winFeatures += 'width='+winWidth+',height='+ winHeight+',left='+d_winLeft+',top='+ d_winTop
  //alert(winFeatures);
  popWin = window.open(winURL, winName, winFeatures)
  }
  
  
function closePopWin(){    // close pop-up window if it is open
  if (navigator.appName != "Microsoft Internet Explorer"
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close()
  }


function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
  
ParseQuerystring();

function ParseQuerystring(qs) 
{ 
//alert('inside Parse');
// Using this function to grab query string and check for Commission Junction variable ref=cj
	this.params = {};
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) 
		{
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
		if(name == 'ref' || name == 'PID')			
				{
				//Post Cookie
				//alert('posting cj cookie');
				var exdate=new Date();
				var c_name='ref';
				var expiredays=45;
				exdate.setDate(exdate.getDate()+expiredays);
				//Setting cookie for CJ to expire in 45 days
				document.cookie=c_name+ "=" +escape(value)+
				((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
				//Track where visitor came from
				script = document.createElement( 'script' );				
				Loc='https://www.uniquesoles.com/phpscripts/pagetraker2.php?Page='+window.location+'&Referer='+document.referrer;
				//alert(Loc);
				script.src = Loc;
				document.getElementsByTagName( 'head' )[0].appendChild( script );
				}
		}
}