<!--
var DetailsSelected=false;
//This function validates the details data for the product details page
function ValidateDetails()
{
	var sCtls=new String(document.forms[0].txtDetailControls.value);
	var aCtls=new Array();
	var aCur=new Array();
	aCtls=sCtls.split("|");
	var sval="";				
	var sText="";
	var sTR=new String();
	DetailsSelected=true;
	for(i=0;i<aCtls.length;i++)
	{
		sTR="";
		aCur=aCtls[i].toString().split(";");
		if (aCur.length>0)
		{
			if (aCur[0]!="")
			{
				eval('sval=document.forms[0].' + aCur[0].toString() + '.value');
				eval('sText=document.forms[0].' + aCur[0].toString() + '.attributes["DetailName"].nodeValue');
			}
		}
		
		if (aCur.length>1)
		{
			if (aCur[1].toString()!="")
			{
				eval('sTR=document.forms[0].' + aCur[1].toString() + '.value');
				if (parseInt(sval)>0)
				{
					if (sTR.length<=0)
					{
						alert("Please enter a valid text for " + sText);
						i=aCtls.length;
						DetailsSelected=false;
					}
				}
				else
				{
					if (sTR.length>0)
					{
						alert("Please select " + sText);
						i=aCtls.length;
						DetailsSelected=false;
					}
				}
			}
		}
		else
		{
			if (parseInt(sval)<=0)
			{
				alert("Please select " + sText);
				i=aCtls.length;
				DetailsSelected=false;
			}
		}
	}
	
	//if details selected is true, retrieve selected details list
	//if (DetailsSelected==true)
	//{
	//	GetSelectedDetailsList();
	//}
}

//This function validates the details data for the wholesale product details page
function ValidateDetailsEx()
{
	var sCtls=new String(document.forms[0].txtDetailControls.value);
	var aCtls=new Array();
	var aCur=new Array();
	var sTRCtl="";
	var aTxtCtls=new Array();
	var sTxtCtls=new String();
	aCtls=sCtls.split("|");
	var sval="";
	var sText="";
	var sTR=new String();
	var ival=0;
	DetailsSelected=true;
	if (aCtls.length>0)
	{
		for(i=0;i<aCtls.length;i++)
		{
			sTR="";
			sTRCtl="";
			sTxtCtls="";
			ival=0;
			aCur=aCtls[i].toString().split(";");
			if (aCur.length>1)
			{
				if (aCur[1]!="")
				{
					if(aCur[0]=="DROPDOWN")
					{
						eval('sval=document.forms[0].' + aCur[1].toString() + '.value');
						eval('sText=document.forms[0].' + aCur[1].toString() + '.attributes["DetailName"].nodeValue');
						ival=parseInt(sval);
						if (aCur.length>2)
						{
							sTRCtl=aCur[2].toString();
						}
					}//if(aCur[0]=="DROPDOWN")
					else if(aCur[0]=="TEXTBOX")
					{
						eval('sText=document.forms[0].' + aCur[1].toString() + '.attributes["DetailName"].nodeValue');
						if (eval('document.forms[0].' + aCur[1].toString() + '.attributes["TRTextControl"]')!=null)
						{
							eval('sTRCtl=document.forms[0].' + aCur[1].toString() + '.attributes["TRTextControl"].nodeValue');
						}
						eval('sTxtCtls=document.forms[0].' + aCur[1].toString() + '.attributes["TextControls"].nodeValue');
						aTxtCtls=sTxtCtls.split("|");
						if (aTxtCtls.length>0)
						{
							for(j=0;j<aTxtCtls.length;j++)
							{
								if (aTxtCtls[j]!="" && aTxtCtls[j]!=null && aTxtCtls[j]!='undefined')
								{
									eval('sval=document.forms[0].' + aTxtCtls[j].toString() + '.value');
									if (parseInt(sval)>0)
									{
										ival=1;
										j=aTxtCtls.length;
									}
								}
							}//for(i=0;i<aTxtCtls.length;i++)
						}//if (aTxtCtls.length>0)
					}//else if(aCur[0]=="TEXTBOX")
				}//if (aCur[1]!="")

				if (sTRCtl!="")
				{
					eval('sTR=document.forms[0].' + sTRCtl + '.value');
					if (ival>0)
					{
						if (sTR.length<=0)
						{
							alert("Please enter a valid text for " + sText);
							i=aCtls.length;
							DetailsSelected=false;
						}
					}
					else
					{
						if (sTR.length>0)
						{
							alert("Please select " + sText);
							i=aCtls.length;
							DetailsSelected=false;
						}
					}
				}
				else
				{
					if (ival<=0)
					{
						alert("Please select " + sText);
						i=aCtls.length;
						DetailsSelected=false;
					}
				}// else of if (aCur.length>2)
			}//if (aCur.length>1)
		}//for(i=0;i<aCtls.length;i++)
	}//if aCtls.length>0
	
}

//This function validates the details data for the wholesale product details combination grid page
function ValidateDetailsCombinationGrid()
{
	var sCtls=new String(document.forms[0].txtDetailControls.value);
	var aCtls=new Array();
	aCtls=sCtls.split("|");
	DetailsSelected=false;
	if (aCtls.length>0)
	{
	    var decQuantity=0;
		for(i=0;i<aCtls.length;i++)
		{
			eval('decQuantity=document.forms[0].' + aCtls[i].toString() + '.value');
			if (parseFloat(decQuantity)>0)
			{
				DetailsSelected=true
				break;				
			}
		}//for(i=0;i<aCtls.length;i++)
		
	}//if aCtls.length>0
	
	if (DetailsSelected==false)
	{
	    alert("Please enter quantity for at least one.");
	}
}

//***************Start of reload details script******************//
function GetSelectedDetailsList(sltCurrentDetailDropDown)
{
	var strSelectedDetails="";
	var sCtls=document.forms[0].txtDetailControls.value;
	var aCtls=sCtls.split("|");
	var strValue="";
	if (aCtls.length==2)
	{
		//Set last selected detail value - the first value indicates whether there are two details or more 1 - indicates there are only two details
		document.forms[0].txtLastSelectedDetail.value="1|" + sltCurrentDetailDropDown.attributes["ParentDetailID"].nodeValue + "|" + sltCurrentDetailDropDown.value;
		strSelectedDetails=sltCurrentDetailDropDown.value;
	}
	else
	{
		//Set last selected detail value - the first value indicates whether there are two details or more 0 - indicates there are more than two details
		document.forms[0].txtLastSelectedDetail.value="0|" + sltCurrentDetailDropDown.attributes["ParentDetailID"].nodeValue + "|" + sltCurrentDetailDropDown.value;

		//Enumerate through the detail items to retrieve selected detail values
		for(i=0;i<aCtls.length;i++)
		{
			aCur=aCtls[i].toString().split(";");
			if (aCur.length>0)//Check if the array has items
			{
				if (aCur[0]!="")
				{
					eval('strValue=document.forms[0].' + aCur[0].toString() + '.value');
					if (parseInt(strValue)>0)
					{
						strSelectedDetails+=((strSelectedDetails.length>0)?"-":"") + strValue;
					}
					
				}//if (aCur[0]!="")

			}//if (aCur.length>0)

		}//for(i=0;i<aCtls.length;i++)
	}//if (aCtls.length==2)

	return strSelectedDetails;
}

//Reloads all details
function ReloadAllDetails(objResetButton)
{
	var sltCurrentDetail=null;
	var strDetailsDataText=objResetButton.attributes["DetailsDataText"].nodeValue;
	var arDetails=strDetailsDataText.split(";");
	var arDetail;
	var arChildDetails;
	var arChildDetail;
	var strChildDescription;
	if (arDetails.length>0)//Make sure that we have at least one item in the array
	{
		//Enumerate through the details drop downs
		for(i=0;i<arDetails.length;i++)
		{
			//split the current details text by | to separate drop down name and child details data
			arDetail=arDetails[i].toString().split("|");
			if (arDetail.length>0)//Check if the array has items
			{
				if (arDetail[0]!="")//Make sure that the detail dropdown name is valid
				{
					//Retrieve the drop down control
					eval('sltCurrentDetail=document.forms[0].' + arDetail[0].toString());
					if (sltCurrentDetail!=null)//Make sure that we got a valid drop down control
					{
						//First, remove all the children
						RemoveAllDetailChildren(sltCurrentDetail);
						//retrieve all child details data into array by splitting the data with ','
						arChildDetails=arDetail[1].toString().split(",");
						if (arChildDetails.length>0)//Make sure that we have at least one child item
						{
							//Enumerate through the child details array
							for(j=0;j<arChildDetails.length;j++)
							{
								arChildDetail=arChildDetails[j].toString().split("-");
								strChildDescription=arChildDetail[1].toString().replace(/\[COMMA]/g, ',');
								strChildDescription=strChildDescription.replace(/\[SEMICOLON]/g, ';');
								strChildDescription=strChildDescription.replace(/\[HYPHEN]/g, '-');
								AddDetailItemToList(sltCurrentDetail,arChildDetail[0].toString(),strChildDescription,arChildDetail[2].toString(),arChildDetail[3].toString());
							}//for(j=0;j<arChildDetails.length;j++)

						}//if (arChildDetails.length>0)

					}//if (sltCurrentDetail!=null)

				}//if (arDetail[0]!="")

			}//if (arDetail.length>0)

		}//for(i=0;i<arDetails.length;i++)

	}//if (arDetails.length>0)
}

//Adds a detail child list item to the passed drop down list
function AddDetailItemToList(sltTargetDetail,strDetailValue,strChildDescription,AdditionalPriceText,AdditionalPriceValue)
{
	//Create detail
	var objOption=document.createElement("OPTION");
	objOption.value=strDetailValue;
	objOption.text=strChildDescription + AdditionalPriceText;

	//Create attrib for detail text
	var objAttr=document.createAttribute("DetailText");
	objAttr.value=strChildDescription;
	objOption.attributes.setNamedItem(objAttr);
	objAttr=null;
	//Create attrib for additional price
	objAttr=document.createAttribute("AdditionalPrice");
	objAttr.value=AdditionalPriceValue;
	objOption.attributes.setNamedItem(objAttr);
	objAttr=null;
	
	//Add the detail to the list
	try
	{
		sltTargetDetail.add(objOption,null)
	}
	catch(ex)
	{
		sltTargetDetail.add(objOption)
	}
	objOption=null;
}

//This function removes all the children except the first one from a passed Details Drop down list
function RemoveAllDetailChildren(sltSelectedDetail)
{
	var intLength=sltSelectedDetail.options.length;
	while(intLength>1)
	{
		sltSelectedDetail.remove(intLength-1);
		intLength=sltSelectedDetail.options.length;
	}//for(i=1;i<intLength;i++)
}

//Reloads detail items in the Details dropdowns
function ReloadDetails(objSelectedDetail)
{
	var intSelectedDetailIDValue=parseInt(objSelectedDetail.value);
	if (intSelectedDetailIDValue>0)
	{
		var objButton=document.getElementById("btnResetSelection");
		var strDetailsDataText=objButton.attributes["DetailsDataText"].nodeValue;
		var arDetails=strDetailsDataText.split(";");
		//Check if there are details
		if (arDetails.length>0)
		{
			var strDetailCombinationsList=objButton.attributes["DetailCombinationsList"].nodeValue;
			//Get related combinations list
			var strRelatedCombinationList=GetRelatedDetailCombinations(strDetailCombinationsList,objSelectedDetail);
			//Enumerate through the details drop downs
			var strCurrentItemValue="";
			var intDetailID=0;
			var sltCurrentDetail=null;
			for(i=0;i<arDetails.length;i++)
			{
				sltCurrentDetail=null;
				//split the current details text by | to separate drop down name and child details data
				arDetail=arDetails[i].toString().split("|");
				if (arDetail.length>0)//Check if the array has items
				{
					if (arDetail[0]!="")//Make sure that the detail dropdown name is valid
					{
						//Retrieve the drop down control
						eval('sltCurrentDetail=document.forms[0].' + arDetail[0].toString());
						if (sltCurrentDetail!=null)//Make sure that we got a valid drop down control
						{
							//If the current detail being processed is the detail of the selected item, then skip
							if (sltCurrentDetail.id!=objSelectedDetail.id)
							{
								strCurrentItemValue=sltCurrentDetail.value;
								//First, remove all the children
								RemoveAllDetailChildren(sltCurrentDetail);
								//retrieve all child details data into array by splitting the data with ','
								arChildDetails=arDetail[1].toString().split(",");
								if (arChildDetails.length>0)//Make sure that we have at least one child item
								{
									//Enumerate through the child details array
									for(j=0;j<arChildDetails.length;j++)
									{
										arChildDetail=arChildDetails[j].toString().split("-");
										intDetailID=parseInt(arChildDetail[0].toString());
										//Verify, if this detail exists in the related combination list
										if(IsDetailFoundInRelatedCombinations(intDetailID,strRelatedCombinationList)==true)
										{
											strChildDescription=arChildDetail[1].toString().replace(/\[COMMA]/g, ',');
											strChildDescription=strChildDescription.replace(/\[SEMICOLON]/g, ';');
											strChildDescription=strChildDescription.replace(/\[HYPHEN]/g, '-');
											AddDetailItemToList(sltCurrentDetail,intDetailID.toString(),strChildDescription,arChildDetail[2].toString(),arChildDetail[3].toString());
										}
									}//for(j=0;j<arChildDetails.length;j++)

								}//if (arChildDetails.length>0)

								if (parseInt(strCurrentItemValue)>0)
								{
									sltCurrentDetail.value=strCurrentItemValue;
								}

								if (sltCurrentDetail.selectedIndex<0)
								{
									sltCurrentDetail.selectedIndex=0;
								}
							}//if (sltCurrentDetail.id!=objSelectedDetail.id)

						}//if (sltCurrentDetail!=null)

					}//if (arDetail[0]!="")

				}//if (arDetail.length>0)

			}//for(i=0;i<arDetails.length;i++)

		}//	if (arDetails.length>0)

	}//if (intSelectedDetailIDValue>0)
}

//Returns detail combinations
function GetRelatedDetailCombinations(DetailCombinationsList,sltCurrentDetailDropDown)
{
	//Retrieve selected details list
	//var arRelatedCombinationList=new Array();
	var strRelatedCombinationList="";
	var strSelectedDetails=GetSelectedDetailsList(sltCurrentDetailDropDown);
	var arSelectedDetails=strSelectedDetails.split("-");
	if (arSelectedDetails.length>0)
	{
		var blnDetailFound=false;
		var intSelectedDetailID=0;
		var intCombinationDetailID=0;
		var arDetailCombinationList;
		var strDetailCombinationList="";
		var arDetailCombinationsList=DetailCombinationsList.split(",");
		var blnalerted=false;
		//Enumerate through the combinations list
		for(i=0;i<arDetailCombinationsList.length;i++)
		{
			arDetailCombinationList=arDetailCombinationsList[i].toString().split("-");
			//Enumerate through the selected combination list item and check if the selected items exist
			for(j=0;j<arSelectedDetails.length;j++)
			{
				blnDetailFound=false;
				intSelectedDetailID=parseInt(arSelectedDetails[j].toString());
				//Enumerate through the details in the current detail combination and check if all the 
				//selected items exist
				for(k=0;k<arDetailCombinationList.length;k++)
				{
					intCombinationDetailID=parseInt(arDetailCombinationList[k].toString());
					if (intCombinationDetailID==intSelectedDetailID)
					{
						blnDetailFound=true;
						break;
					}
				}//for(k=0;k<arDetailCombinationList.length;k++)
				
				//if any of the selected item does not exist, exit the current loop, i.e. for(j=0;j<arSelectedDetails.length;j++)
				if (blnDetailFound==false)
				{
					break;
				}

			}//for(j=0;j<arSelectedDetails.length;j++)
			if (blnDetailFound==true)
			{
				strRelatedCombinationList+=((strRelatedCombinationList.length>0)?",":"") + arDetailCombinationsList[i].toString();
			}

		}//for(i=0;i<arDetailCombinationsList.length;i++)

	}//if (arSelectedDetails.length>0)
	else
	{
		strRelatedCombinationList=DetailCombinationsList;
	}

	//Return the related combination list array
	return strRelatedCombinationList;
}

//Checks if a given 
function IsDetailFoundInRelatedCombinations(TargetDetailID,RelatedCombinationList)
{
	var blnFound=false;
	if (RelatedCombinationList.length>0)
	{
		var arRelatedCombinationList=RelatedCombinationList.split(",")
		var arRelatedCombination=new Array();
		for(var ListKey in arRelatedCombinationList)
		{
			arRelatedCombination=arRelatedCombinationList[ListKey].toString().split("-");
			for(var CombinationKey in arRelatedCombination)
			{
				if (parseInt(arRelatedCombination[CombinationKey].toString())==TargetDetailID)
				{
					blnFound=true;
					break;
				}	
			}//for(j=0;j<arRelatedCombination.length;j++)
			
			if (blnFound==true)
			{
				break;
			}
		}//for(var ArrKey in <arRelatedCombinationList)

	}//if (arRelatedCombinationList.length>0)
	//Return the result	
	return blnFound;
}
//***************End of reload details script********************//

//***************Zoom function scripts***************************//
//This script is placed in this class file because this class file is included all product details pages//
//and this script is required only in product details pages//
function stopMZ() 
{
    try { MagicZoom_stopZooms(); MagicThumb.stop(); } catch(e) { return false;}
    return true;
}

function
flxZoom(strContainer,strHyperlinkCtrl,strMediumImageUrl,strLargeImageUrl,intZoomMode,intWidth,intHeight,intItemID,intBorderWidth,strBorderStyle,strBorderColor,strImageDescription,strCursor)
{
    if ( undefined == window.flxContentTimer ) { window.flxContentTimer = null;  }
    if ( undefined == window.flxZoomTimer ) { window.flxZoomTimer = null; }
    if ( -1 != document.getElementById(strHyperlinkCtrl).href.indexOf(strLargeImageUrl))
    {
        return false;
    }
    var strImgStyle="";
    if ( (isNaN(intBorderWidth)==false && intBorderWidth>0) || strBorderStyle.length>0 || strBorderColor.length>0)
    {
        var strImgStyle1='';
        if (isNaN(intBorderWidth)==false && intBorderWidth>0)
        {
            strImgStyle1='border-width: ' + intBorderWidth.toString() + 'px';
        }
        if(strBorderStyle.length>0)
        {
            strImgStyle1+=((strImgStyle1.length>0)?'; ':'') + 'border-style: ' + strBorderStyle;
        }
        if(strBorderColor.length>0)
        {
            strImgStyle1+=((strImgStyle1.length>0)?'; ':'') + 'border-color: ' + strBorderColor;
        }
        strImgStyle='Style="' + strImgStyle1 + '" ';
    }

    if ( window.flxContentTimer ) {clearTimeout(window.flxContentTimer);window.flxContentTimer = null; }

    if ( window.flxZoomTimer ) {clearTimeout(window.flxZoomTimer);window.flxZoomTimer = null; }
    while (!stopMZ() ) {};

    window.flxContentTimer = setTimeout( function() { 
        document.getElementById(strContainer).innerHTML = '<a href="' + strLargeImageUrl + '" id="' + strHyperlinkCtrl + '" rel="' + ((intZoomMode == 2 || intZoomMode==4)?"zoom-position: inner; ":"") +
        'zoom-width: ' + intWidth.toString() + 'px; zoom-height: ' + intHeight.toString() + 'px" class="MagicZoom' + ((intZoomMode==3 || intZoomMode==4)?' MagicThumb':'') + '"' +
        ((strCursor.length>0)?'style="cursor: ' + strCursor + ';"':'') +  ((intZoomMode!=3 && intZoomMode!=4)?'onclick="javascript:OpenLargeImage(' + intItemID.toString() + ');"':"") + 
        '><img id="imgMedium" alt="" src="' + strMediumImageUrl + '" ' + strImgStyle + '/>' + (((intZoomMode==3 || intZoomMode==4) && strImageDescription.length>0)?'<span>' +
        strImageDescription.replace("[SINGLEQUOTE]","'") + '</span>':'')  + '</a>';
    
                window.flxZoomTimer = setTimeout( function() { 
                    MagicZoom_findZooms(); 
                    try { MagicThumb.refresh(); } catch (e) {}
                }, 100);
        }, 50 );
        setTimeout("PreloadLargeImage('" + strLargeImageUrl + "')", 100);
    }

//This method is called when one of the images have the zoom feature disabled
function flxNoZoom(strContainer,strHyperlinkCtrl,strMediumImageUrl,intItemID,intBorderWidth,strBorderStyle,strBorderColor) {   
    //MagicZoom_stopZooms();
     try { MagicZoom_stopZooms(); MagicThumb.stop(); } catch(e) {}
    var strImgStyle="";
    if ( (isNaN(intBorderWidth)==false && intBorderWidth>0) || strBorderStyle.length>0 || strBorderColor.length>0)
    {
        var strImgStyle1='';
        if (isNaN(intBorderWidth)==false && intBorderWidth>0)
        {
            strImgStyle1='border-width: ' + intBorderWidth.toString() + 'px';
        }
        if(strBorderStyle.length>0)
        {
            strImgStyle1+=((strImgStyle1.length>0)?'; ':'') + 'border-style: ' + strBorderStyle;
        }
        if(strBorderColor.length>0)
        {
            strImgStyle1+=((strImgStyle1.length>0)?'; ':'') + 'border-color: ' + strBorderColor + ';';
        }
        strImgStyle='Style="' + strImgStyle1 + '" ';
    }
    document.getElementById(strContainer).innerHTML = '<a href="javascript:void(0);" onclick="javascript:OpenLargeImage(' + intItemID.toString() + ');"><img src="' + strMediumImageUrl + '" id="imgMedium" border="0" ' + strImgStyle + ' GALLERYIMG="NO" /></a>';
}

function PreloadLargeImage(strImgName)
{
   try {
        objImg = new Image();
        objImg.src = strImgName;
    }
    catch (eRR) {
        //Do nothing
        objImg = null;
    }
    finally {
        objImg = null;
   }
}
//***************End of Zoom function scripts***************************//
//-->

