//* This JS file is used to save item/product related data *//
//* This JS file also performs few logic related to item/product *//
var items_available = new Array();
var items_thumbNail = new Array();
var items_fullImage = new Array();
var static_kits = new Array();
var kit_plans = new Array();
var kit_hardwares = new Array();
var kit_MROs = new Array();
var ThumbNailDefault;
var FullImageDefault;
var default_item_price = 0;
var default_item_price_mon;
var def_attributes = new Array();
var def_attributes_combination = new Array ();
var defAttributeIndex;
var defaultItemCount;
var staticArrayCounter = 0;
var duplicateFlag = true;
var presentIndex;
var footNoteCount = 0;
var discFeaturesArray = new Array();
var discSpecArray = new Array();
var discDetailsArray = new Array();
var discIncludesArray = new Array();
var discBonusArray = new Array();
var discRechargingArray = new Array();
var discPlanArray = new Array();
var featuresArray = new Array();
var specArray = new Array();
var detailsArray = new Array();
var includesArray = new Array();
var bonusArray = new Array();
var rechargingArray = new Array();
var plansArray = new Array();
var moreImagesArray = new Array();
var defaultAction;
var showOrText=false;
var changeFlag = true;
var createSelectedStr;
var itemDefaultCount;
var isPrint = false;
var showBackground = false;
//Code inserted to remove javascript error in the Mobile Phones Details Page occured after selecting the defining attribute combination which is not existing.
var countOfProducts;
var curleft = curtop = 0;
// Show appropriate control for defining attributes
function showDefAttr(){
itemDefaultCount = 0;
if (def_attributes.length>1){
for(loopI=0;loopI<def_attributes.length;loopI++){
if(staticArrayCounter==0){
def_attributes_combination[loopI]=new Array(2);
def_attributes_combination[loopI][0] = def_attributes[loopI];
def_attributes_combination[loopI][1] = items_available[loopI];
}
else{
def_attributes_combination[loopI][0] = def_attributes_combination[loopI][0] + '-' + def_attributes[loopI];
}
checkForDuplicates();
if(duplicateFlag){
addOption(def_attributes[loopI]);
document.getElementById('defAttrText'+defAttributeIndex).innerHTML = def_attributes[loopI];
}
if(defaultItemCount == loopI){
var dropObj = document.getElementById('defAttrDrop'+defAttributeIndex);
for(loopJ=0;loopJ<dropObj.length;loopJ++){
if(def_attributes[loopI] == dropObj.item(loopJ).text){
itemDefaultCount = loopJ;
dropObj.selectedIndex=itemDefaultCount;
break;
}
}
}
}
if(document.getElementById('defAttrDrop'+defAttributeIndex).length > 1){
document.getElementById('defAttrDrop'+defAttributeIndex).style.display="";
document.getElementById('defAttrText'+defAttributeIndex).style.display="none";
}
else{
document.getElementById('defAttrText'+defAttributeIndex).style.display="";
document.getElementById('defAttrDrop'+defAttributeIndex).style.display="none";
}
}
else{
document.getElementById('defAttrText'+defAttributeIndex).innerHTML=def_attributes[0];
document.getElementById('defAttrText'+defAttributeIndex).style.display="";
document.getElementById('defAttrDrop'+defAttributeIndex).style.display="none";
}
staticArrayCounter++;
}
function checkForDuplicates(){
duplicateFlag = true;
for(loopJ=0;loopJ<loopI;loopJ++){
if(def_attributes[loopI]==def_attributes[loopJ]){
duplicateFlag = false;
break;
}
}
}
function addOption(attrText){
var optionValue = document.createElement("OPTION");
optionValue.text = attrText;
document.getElementById('defAttrDrop'+defAttributeIndex).options.add(optionValue);
}
function triggerChangeItems(refreshURL){
var dropSelectedIndex;
changeFlag = false;
for(loopI=0;loopI<=defAttributeIndex;loopI++){
dropSelectedIndex = document.getElementById('defAttrDrop'+loopI).selectedIndex;
if(loopI==0){
createSelectedStr = document.getElementById('defAttrDrop'+loopI).item(dropSelectedIndex).text;
}
else{
createSelectedStr = createSelectedStr + '-' + document.getElementById('defAttrDrop'+loopI).item(dropSelectedIndex).text;
}
}
// Pass on the below value to get the catentry id of the item associated with this attribute in the drop down
for(loopI=0;loopI<def_attributes_combination.length;loopI++){
if(createSelectedStr==def_attributes_combination[loopI][0]){
changeFlag = true;
default_item_id = def_attributes_combination[loopI][1];
window.open(refreshURL+"&productId="+default_item_id,'_self');
break;
}
}
if(changeFlag==false){
//var errObj = document.getElementById('error-popup');
//alert(errObj.offsetHeight);
//errObj.style.top = errObj.style.height - 10;
//errObj.style.display = "";
//document.getElementById('colour-selector').options[0].value = createSelectedStr;
curleft = curtop = 0;
obj = document.getElementById('defAttrDrop0');
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}while (obj = obj.offsetParent);
}
}
}
function hideError(){
document.getElementById('error-popup').style.display = "none";
}
function showControlById(controlName, controlLink, controlValue){
var elemObj = document.getElementById(controlName);
elemObj.style.display="";
elemObj.action=controlLink;
elemObj.value=controlValue;
}
function showButton(controlValue){
var elemObj = document.getElementById('add_to_cart');
elemObj.style.display="";
elemObj.value=controlValue;
}
function populateStaticKits(staticKitId){
if(static_kits){
static_kits[static_kits.length] = staticKitId;
}
else{
static_kits[0] = staticKitId;
}
}
function populateKitPlans(kitPlans){
if(kit_plans){
kit_plans[kit_plans.length] = kitPlans;
}
else{
kit_plans[0] = kitPlans;
}
}
function populateKitHardwares(kitHardwares){
if(kit_hardwares){
kit_hardwares[kit_hardwares.length] = kitHardwares;
}
else{
kit_hardwares[0] = kitHardwares;
}
}
function populateKitMROs(kitMROs){
if(kit_MROs){
kit_MROs[kit_MROs.length] = kitMROs;
}
else{
kit_MROs[0] = kitMROs;
}
}
function populateDescAttribute(arrayName,controlDesc,controlValue,imgName,superScriptFlag,startI,endI,descAttrDescFlag,descAttrName){
var i=arrayName.length;
var descFlag = duplicateDesc(arrayName,controlDesc,descAttrName);
if(descFlag>-1){
arrayName[descFlag][0]=controlDesc;
arrayName[descFlag][1]=controlValue;
arrayName[descFlag][2]=imgName;
arrayName[descFlag][6]=descAttrDescFlag;
arrayName[descFlag][7]=descAttrName;
}else{
arrayName[i]=new Array(8);		
arrayName[i][0]=controlDesc;
arrayName[i][1]=controlValue;
arrayName[i][2]=imgName;
if(superScriptFlag==0){
arrayName[i][3]=0;
}else{
arrayName[i][3]=superScriptFlag;
arrayName[i][4]=startI;
arrayName[i][5]=endI;
}
arrayName[i][6]=descAttrDescFlag;
arrayName[i][7]=descAttrName;
}
}
function duplicateDesc(arrayName,controlDesc,descAttrName){
for(loopJ=0;loopJ<arrayName.length;loopJ++){
if(controlDesc.toLowerCase()==(arrayName[loopJ][0]).toLowerCase()&&
descAttrName.toLowerCase()==(arrayName[loopJ][7]).toLowerCase())
{
return loopJ;
}
}
return -1;
}
function showCallText(controlValue){
document.getElementById('call_text').innerHTML=controlValue;
document.getElementById('call_text').style.display="";
}
function showLink(controlName, controlValue){
document.getElementById(controlName).href=controlValue;
document.getElementById(controlName).style.display="";
}
function showCombinedText(controlValue,controlView, controlLink){
if(isPrint)
{
//document.getElementById('combined_sweet_section').style.display="";
document.getElementById("innerHolder").style.display = "";
}
document.getElementById('sweetSpotFS').style.display="";
document.getElementById('combined_text').innerHTML=controlValue;
document.getElementById('combined_text').style.display="";
if(showOrText){
document.getElementById('orSpan').style.display = "";
}
if(! isPrint)
{	
if(controlLink != "" && controlLink != null){
document.getElementById('combined_text_button').action=controlView+'&productId='+controlLink;
document.getElementById('combined_text_button').style.display="";
}
}
}
function showSweetSpot(controlValue){
if(isPrint)
{
//document.getElementById('combined_sweet_section').style.display="";
document.getElementById("innerHolder").style.display = "";
}
document.getElementById('sweetSpotFS').style.display="";
document.getElementById('sweet_spot_text').innerHTML=controlValue;
document.getElementById('sweet_spot_text').style.display="";
}
// Start CP CR
function showMinCost(controlValue){
if(isPrint)
{
document.getElementById("innerHolder").style.display = "";
}
document.getElementById('sweetSpotFS').style.display="";
document.getElementById('minCost').innerHTML=controlValue;
document.getElementById('minCost').style.display="";
}
//End CP CR
function submitProduct(){
if(changeFlag == false)
{
addToCart_Product_Check("300");
return false;
}
else{
document.getElementById('catentry').value = default_item_id;
document.product_details.action = "NGTSOOrderItemAdd";
document.product_details.submit();
}
}
//Start - MR2 Defect #1847
function callActionById(controlName){
window.open(document.getElementById(controlName).action,'','width=752,height=557,status=yes,location=yes,resizable=no');
}
//End - MR2 Defect #1847
function showCombinedView(){
document.product_details.action = document.getElementById('combined_text_button').action;
document.product_details.submit();
}
function errorCheck(position){
alertPosition = (position*120)+600;
if(changeFlag == false)
{
addToCart_Product_Check(alertPosition);
return false;
}
else{
return true;
}
}

