// 
// Ralph Rodriguez, 07/13/2008
// Javascript functions used in web work for www.tiasplace.com
// Update: 07/01/11
//
// Globals
var RRStandartImage = new Array();
var RRZoomImage = new Array();
var RRAdditionalView = new Array(); RRAdditionalView[0]="";RRAdditionalView[1]="";RRAdditionalView[2]="";
var RRAdditionalView1 = new Array();
var RRAdditionalViewIconCnt = 0;
var RRAdditionalView = new Array();
var RRVideo = "";
var RRJpgArticle = "";
var RRItemSelectedData = new Array();
var CurrentProductIndex = 0;
var RRProductOriginalPrice = new Array();
var RRProductPrice = new Array();


// Displays special text infor line for Sale items only
// Function displays the SALE price notice in red if USERDEF1 has a value > $1
function RRDisplaySaleInfo(x){
	if(x>1)
	{
		var CurrentSaleText = document.getElementById("SaleItemNoticeText");
		replaceText(CurrentSaleText, "These items are on sale. Items on sale cannot be returned.");
	}
}


// Test for LightBox2 ,Displays opening Image in Product Image Viewer 1
function RRDisplayOpeningImage(Uselected){
	document.write('<table class="ritemstyleview1table">');
	document.write('<tr>');
	document.write('<td class="ritemstyleview1cell" id="zoom1Container">');
    document.write('<a href="/productsimg/'+RRItemSelectedData[Uselected]+'.Lg.jpg" rel="lightbox" name="MainImage" class="MagicZoom" id="zoom1">');
	document.write('<img src="/productsimg/'+RRItemSelectedData[Uselected]+'.jpg" class="MagicZoomLoading" src="/Scripts/ajax-loader.gif" alt="Loading, Please Wait" class="ritemstyleview1picture"/></a>');
	//document.write('<img class="MagicZoomLoading" src="/Scripts/ajax-loader.gif" alt="Loading, Please Wait"/>');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}

// Displays opening Image in Product Image Viewer 1
function RRDisplayOpeningImageMagicZoomWorking(Uselected){
	document.write('<table class="ritemstyleview1table">');
	document.write('<tr>');
	document.write('<td class="ritemstyleview1cell" id="zoom1Container">');
    document.write('<a href="/productsimg/'+RRItemSelectedData[Uselected]+'.Lg.jpg" name="MainImage" class="MagicZoom" id="zoom1">');
	document.write('<img src="/productsimg/'+RRItemSelectedData[Uselected]+'.jpg" class="ritemstyleview1picture"/></a>');
	document.write('<img class="MagicZoomLoading" src="/Scripts/ajax-loader.gif" alt="Loading, Please Wait"/>');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}
// Loads the Style Image SKU
function RRLoadProductData(UIndex,UValue){
	RRItemSelectedData[UIndex] = UValue;
}
// Loads the Style Image SKU
function RRLoadProductData2(UIndex,UItem,UPrice,UOPrice){
	RRItemSelectedData[UIndex] = UItem;
	RRProductPrice[UIndex] = UPrice;
	RRProductOriginalPrice[UIndex] = UOPrice;
}
// Functions for Ajax work
var request = null;
function createRequest() {
     try {
       request = new XMLHttpRequest();
     } catch (trymicrosoft) {
       try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (othermicrosoft) {
         try {
           request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
           request = null;
         }
       }
     } 
	 if (request == null)
       alert("Error creating request object!");
}

// Test of LightBox2, 07/05/11

// Loads new picture in the main picture area of the Sample Item window
function RRUpdateimage(pass){
	// old update image code -- document.my_form.MainImage.src=Images[pass];
	RRClearIcon (); // update 07/04/11
	RRGetProductMedia(RRItemSelectedData[pass],pass);
	MagicZoom_stopZooms();
	document.getElementById('zoom1Container').innerHTML = '<a href="/productsimg/'+RRItemSelectedData[pass]+'.Lg.jpg"'
	+'" name="MainImage" class="MagicZoom" id="zoom1" rel="zoom-position: right; zoom-width: 300px; zoom-height: 375px">'
	+'<img src="/productsimg/'+RRItemSelectedData[pass]+'.jpg" class="ritemstyleview1picture" /></a>';
	//+ '<td id="zoom1-big"></td>';
	//+'<img src="/productsimg/'+RRItemSelectedData[pass]+'.jpg" class="ritemstylezoomview1picture" /></a>';
	setTimeout('MagicZoom_findZooms()', 100);
	//MagicZoom.refresh();
}

// Loads new picture in the main picture area of the Sample Item window
function RRUpdateimageMagicZoomWorking(pass){
	// old update image code -- document.my_form.MainImage.src=Images[pass];
	RRClearIcon (); // update 07/04/11
	RRGetProductMedia(RRItemSelectedData[pass],pass);
	MagicZoom_stopZooms();
	document.getElementById('zoom1Container').innerHTML = '<a href="/productsimg/'+RRItemSelectedData[pass]+'.Lg.jpg"'
	+'" name="MainImage" class="MagicZoom" id="zoom1" rel="zoom-position: right; zoom-width: 300px; zoom-height: 375px">'
	+'<img src="/productsimg/'+RRItemSelectedData[pass]+'.jpg" class="ritemstyleview1picture" /></a>';
	//+ '<td id="zoom1-big"></td>';
	//+'<img src="/productsimg/'+RRItemSelectedData[pass]+'.jpg" class="ritemstylezoomview1picture" /></a>';
	setTimeout('MagicZoom_findZooms()', 100);
}
function RRGetProductMedia(ItemSelected,pass) {
     createRequest();
	 CurrentProductIndex = pass;
     var url = "http://www.tiasplace.com/Scripts/RRGetMediaFiles.php?SelectedItem="+ItemSelected;
     request.open("GET", url, true);
     request.onreadystatechange = RRProcessMediaData;
     request.send(null);
}
function OrigGetMediaFile() {
    if (request.readyState == 4) {
      var MediaFile1 = request.responseText;
      var CurrentMediaText = document.getElementById("MediaFileText");
	  var CurrentMediaText2 = document.getElementById("MediaFileText2");
	  replaceText(CurrentMediaText, "Checking Media for: "+MediaFile1);
    }
}
function RRProcessMediaData() {
    if (request.readyState == 4) {
	  var rindex = 0;
      var MediaFileString = request.responseText;
	  RRAdditionalView1 = MediaFileString.split(" ");
	  RRAdditionalView = RRAdditionalView1.grep(".jpg");
	  RRAdditionalViewIconCnt = RRAdditionalView.length;
	  var CurrentMediaText = document.getElementById("MediaFileText");
	  var CurrentMediaText2 = document.getElementById("MediaFileText2");
	  if ( RRAdditionalViewIconCnt >= 1 ) {
	  	RRConfigureIconElement(RRAdditionalViewIconCnt-1);
	  }
	  else {
	  	RRClearIcon();
	  }
	  // Display Debug info
	  //replaceText(CurrentMediaText, "Media For = "+RRItemSelectedData[CurrentProductIndex]);
	  //replaceText(CurrentMediaText2, "Icon Cnt= "+RRAdditionalViewIconCnt+" Icon0= "+RRAdditionalView[0]+" Icon1= "+RRAdditionalView[1]+" Icon2= "+RRAdditionalView[2]);
    }
}
function RRConfigureIconElement (pass) {
		var RRStatus = document.getElementById("RRGeneralStatusText");
		var cnt = pass;
		var IconStatus = "";
		if ( cnt == 2) {
			// Debug info
			//IconStatus=" cnt = "+cnt+IconStatus+" Bottom,";
			//replaceText(RRStatus, "Media For = "+RRItemSelectedData[CurrentProductIndex]+" "+IconStatus+" Icon");
			document.getElementById("BottomIconLoc").innerHTML = '<a href="#"  onMouseOver="RRDisplayAddView('+cnt+');" onMouseOut="RRClearAddView();">'
			+'<img src="/productsimg/AdditionalViews/'+RRAdditionalView[cnt]+'" class="rpictureiconbottomlocation"></a>';
			document.getElementById("BottomIconLoc").style.visibility="visible";
			cnt--;
		}
		if ( cnt == 1) {
			// Debug info
			//IconStatus=" cnt = "+cnt+IconStatus+" Middle,";
			//replaceText(RRStatus, "Media For = "+RRItemSelectedData[CurrentProductIndex]+" "+IconStatus+" Icon");
			document.getElementById("MiddleIconLoc").innerHTML = '<a href="#"  onMouseOver="RRDisplayAddView('+cnt+');" onMouseOut="RRClearAddView();">'
			+'<img src="/productsimg/AdditionalViews/'+RRAdditionalView[cnt]+'" class="rpictureiconmiddlelocation"></a>';
			document.getElementById("MiddleIconLoc").style.visibility="visible";
			cnt--;
		}
		if ( cnt == 0) {
			// Debug info
			//IconStatus=" cnt = "+cnt+IconStatus+" Top";
			//replaceText(RRStatus, "Media For = "+RRItemSelectedData[CurrentProductIndex]+" "+IconStatus+" Icon");
			document.getElementById("TopIconLoc").innerHTML = '<a href="#"  onMouseOver="RRDisplayAddView('+cnt+');" onMouseOut="RRClearAddView();">'
			+'<img src="/productsimg/AdditionalViews/'+RRAdditionalView[cnt]+'" class="rpictureicontoplocation"></a>';
			document.getElementById("TopIconLoc").style.visibility="visible";
			cnt--;
		}
}
function RRClearIcon () {
		document.getElementById("TopIconLoc").style.visibility="hidden";
		document.getElementById("MiddleIconLoc").style.visibility="hidden";	
		document.getElementById("BottomIconLoc").style.visibility="hidden";	
	
}
function RRClearAddView () {
		document.getElementById("AdditionalViewLoc").style.visibility="hidden";	
}
function RRDisplayAddView (pass) {
		document.getElementById("AdditionalViewLoc").innerHTML = '<img src="/productsimg/AdditionalViews/'+RRAdditionalView[pass]+'" class="rpictureadditionalviewlocation">';
		document.getElementById("AdditionalViewLoc").style.visibility="visible";
}

function RRDoNotSaleThisVendor (VName) {
	var VendorName = VName;
	if ( VendorName == "Tory Burch") {
		//var CurrentAddButtonText = document.getElementById("AddButtonText");
		//replaceText(CurrentSaleText, "To order this item, please call the store directly, 201-451-9358");
			// un display the "Add To bag" button
			document.getElementById('AddButtonText').innerHTML = '<a href="#">This item is available through our retail store only, please call 201-451-9358 to purchase'
			+'<img src="/productsimg/Others/Transparent2.gif" width="10" height="10" border="0" /></a>';
			// document.getElementById("AddButtonText").style.visibility="hidden";
		}
}
// Unix like grep returns a new string array with only the strings that match the pattern
function grep(str)
{
	var ar = new Array();
	var arSub = 0;
	for (var i in this)
	{
		if (typeof this[i] == "string" && this[i].indexOf(str) != -1)
		{
			ar[arSub] = this[i];
			arSub++;
		}
	}
	return ar;
}
Array.prototype.grep = grep;

// This displays the sale price data
// Function displays the SALE price in red if USERDEF1 has a value > $1 , rrsaleprice(x)
function RRDisplayPrice(UIndex,UOPrice){
	if( UOPrice > 1 ){ //The USERDEF1 has a value > 1 which means that the product is in SALE
	// RRProductPrice[UIndex] 
	document.write('<b>Original Price: $<span id="OriginalPrice">'+RRProductOriginalPrice[UIndex]+'</span></b>');
	document.write('<b>Sale Price: <span id="SalePrice">'+RRProductPrice[UIndex]+'</span> </b>');
    }
	else {
	document.write('<b>Price: '+RRProductPrice[UIndex]+'</b>');
	}
}
function RRUpdatePrice() {
    if (request.readyState == 4) {
      var NewPrice = request.responseText;
      var CurrentSalePrice = document.getElementById("SalePrice");
	  var CurrentStyle = document.getElementById("Style");
      // replaceText(CurrentSalePrice, NewPrice); // get's price number from php script run at the tiasplace.com server
	  // replaceText(CurrentStyle, 'Ralph');
    }
}


// removes unwanted stuff
function RRCleanup () {
	//document.getElementById('AdditionalViewBigImage').innerHTML = '<a href="/productsimg/Others/BigPink.300x375.jpg">'
	//+'<img src="/productsimg/Others/BigPink.300x375.jpg" width="300" height="375" border="0" /></a>';
	document.getElementById('RRCleaning').innerHTML = '<a href="#">'
	+'<img src="/productsimg/Others/Transparent2.gif" width="10" height="10" border="0" /></a>';
}

/* other RR cool stuff
<div id="RRCleaning">
</body>
</div>
<script language=javascript>RRCleanup();</script>

*/

/* Other Function Stuff

if(!---PAYPAL_CHECKOUT---){
document.write('\n');
}
else{
document.write('<tr> ');
document.write(' <td colspan="2" align=center class="pdgmain"> ');
document.write(' <br> <br> <br> <font class=pdgmainhdr>Credit Card Information<br></font> ');
document.write(' <small>(Fill out only if paying by credit card on-line.)</small> ');
document.write(' </td>');
document.write('</tr>');
document.write('<tr> ');
document.write(' <td align=right class="pdgmain"> ');
document.write(' (Credit Card) Type of Credit Card ');
document.write(' </td>');
document.write(' <td align=left class="pdgmain">');
document.write(' <select name="cardtype" size="1">');
document.write(' <option selected>Visa</option>');
document.write(' <option>Mastercard</option>');
document.write(' <option value="AMEX">American Express</option>');
document.write(' <option>Discover</option>');
document.write(' </select>');
document.write(' </td>');
document.write('</tr>');
document.write('<tr> ');
document.write(' <td align=right class="pdgmain"> (Credit Card) Credit Card Number ');
document.write(' </td>');
document.write(' <td align=left class="pdgmain">');
document.write(' <input name="cardnumber" size="25">');
document.write(' </td>');
document.write('</tr>');
document.write('<tr> ');
document.write(' <td align=right class="pdgmain"> (Credit Card) Credit Card Verification Value ');
document.write(' </td>');
document.write(' <td align=left class="pdgmain">');
document.write(' <input name="ccv2" size="5">');
document.write(' </td>');
document.write('</tr>');
document.write('<tr> ');
document.write(' <td align=right class="pdgmain">');
document.write(' (Credit Card) Expiration Date');
document.write(' </td>');
document.write(' <td align=left class="pdgmain">');
document.write(' <select name="cardexpmonth">');
document.write(' <option value="">Month</option>');
document.write(' <option value="01">Jan</option>');
document.write(' <option value="02">Feb</option>');
document.write(' <option value="03">Mar</option>');
document.write(' <option value="04">Apr</option>');
document.write(' <option value="05">May</option>');
document.write(' <option value="06">Jun</option>');
document.write(' <option value="07">Jul</option>');
document.write(' <option value="08">Aug</option>');
document.write(' <option value="09">Sep</option>');
document.write(' <option value="10">Oct</option>');
document.write(' <option value="11">Nov</option>');
document.write(' <option value="12">Dec</option>');
document.write(' </select>');
document.write(' <select name="cardexpyear">');
document.write(' <option value="">Year ');
document.write(' <option value="04">2004 ');
document.write(' <option value="05">2005 ');
document.write(' <option value="06">2006 ');
document.write(' <option value="07">2007 ');
document.write(' <option value="08">2008 ');
document.write(' <option value="09">2009 ');
document.write(' <option value="10">2010 ');
document.write(' <option value="11">2011 ');
document.write(' <option value="12">2012 ');
document.write(' <option value="13">2013 ');
document.write(' <option value="14">2014 ');
document.write(' <option value="15">2015 ');
document.write(' </select>');
document.write(' </td>');
document.write('</tr>');
}

*/


