var eGlobal;
var firstClick = new Array(100);
var blendStep, slideCurrent;
var objToHide, timerFly, flyoverMain, flyoverSelect;
var fUnlock = new Array();
var fUnlockAnchor = new Array();

function firstRemove(x) {
    for (i=1; i<firstClick.length; i++)
        if (firstClick[i]==x) return;
    firstClick[firstClick.length]=x;
    x.value='';
    return(false);
}

function FIND(item) {
    if( window.mmIsOpera ) return(document.getElementById(item));
    if (document.all) return(document.all[item]);
    if (document.getElementById) return(document.getElementById(item));
    return(false);
}

function setBg() {
    document.body.style.backgroundPosition=''+(0+eGlobal.offsetLeft)+'px top';
}

function getAbsolutePosition(el) {
    var r = {
        x: el.offsetLeft,
        y: el.offsetTop
    };
    if (el.offsetParent) {
        var tmp = getAbsolutePosition(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
}

function hideObj() {
    if (objToHide) objToHide.style.display='none';
    clearTimeout(timerFly);
}
function hideFlyoverMain() {
    objToHide=flyoverMain;
    timerFly=setTimeout(hideObj, 500);
}
function showFlyoverMain() {
    flyoverMain.style.display='block';
    clearTimeout(timerFly);
}
function hideFlyoverSelect() {
    objToHide=flyoverSelect;
    timerFly=setTimeout(hideObj, 500);
}
function showFlyoverSelect() { 
    obj=FIND('anchorDrop');
    x=getAbsolutePosition(obj).x;
    y=getAbsolutePosition(obj).y;
    flyoverSelect.style.top=''+(y+obj.clientHeight+1)+'px';
    flyoverSelect.style.left=''+x+'px';
    flyoverSelect.style.marginLeft='0';
    flyoverSelect.style.display='block';
    clearTimeout(timerFly);
}

function flyoversMainInit() {
    x=FIND('anchorFlyMain');
	
    flyoverMain=FIND('fly_main');
    if (x && flyoverMain) {
        x.onmouseover=showFlyoverMain;
        x.onmouseout=hideFlyoverMain;
        flyoverMain.onmouseover=showFlyoverMain;
        flyoverMain.onmouseout=hideFlyoverMain;
    }
    x=FIND('anchorDrop');
    flyoverSelect=FIND('fly_select');
    if (x && flyoverSelect) {
        x.onmouseover=showFlyoverSelect;
        x.onmouseout=hideFlyoverSelect;
        flyoverSelect.onmouseover=showFlyoverSelect;
        flyoverSelect.onmouseout=hideFlyoverSelect;
    }
}

function fUnlockDisplay1() { 
	   $j('#f_unlock_1').css('display','block')
	    $j('#f_unlock_2').css('display','none')
	    $j('#f_unlock_3').css('display','none')
	
    if (x = FIND('b_unlock_my_phone')) {
        x.style.backgroundPosition='-170px 0';
        x.style.cursor='default';
        x.disabled = true;
    }
	
    if (fUnlockAnchor[1]) fUnlockAnchor[1].focus();
}

function fUnlockDisplay2(val,val1) { 

	    $j('#f_unlock_1').css('display','none')
	    $j('#f_unlock_2').css('display','block')
	    $j('#f_unlock_3').css('display','none')
    //flyoverSelect.display='none';
    document.getElementById('manu_id').value=val;
    document.getElementById('manu_nam').value=val1;
    getGSMModel(val);
    if(document.getElementById('manuname')!=null)
    {
        document.getElementById('manuname').innerHTML='&bull; '+val1+'&nbsp;&nbsp;<a href="#1" onclick="fUnlockDisplay1();">[x] clear</a>';
    }
    else if(document.getElementById('manu_name')!=null)
    {
        document.getElementById('manu_name').innerHTML='<b>'+val1+'</b>&nbsp;&nbsp;<a href="#1" onclick="fUnlockDisplay1();">[x] clear</a>';
    }
    if (x = FIND('b_unlock_my_phone')) {
        x.style.backgroundPosition='-170px 0';
        x.style.cursor='default';
        x.disabled = true;
    }
    if (fUnlockAnchor[2]) fUnlockAnchor[2].focus();
}

function fUnlock_Display2(val,val1) { 
	
     $j('#f_unlock_1').css('display','none')
    $j('#f_unlock_2').css('display','block')
    $j('#f_unlock_3').css('display','none')
    //flyoverSelect.display='none';
    document.getElementById('manu_id').value=val;
    document.getElementById('manu_nam').value=val1;
    if(document.getElementById('manuname')!=null)
    {
        document.getElementById('manuname').innerHTML=val1+'&nbsp;&nbsp;<a href="#" onclick="fUnlockDisplay1();">[x] clear</a>';
    }
    else if(document.getElementById('manu_name')!=null)
    {
        document.getElementById('manu_name').innerHTML='<b>'+val1+'</b>&nbsp;&nbsp;<a href="#" onclick="fUnlockDisplay1();">[x] clear</a>';
    }
    if (x = FIND('b_unlock_my_phone')){
        x.disabled = false;
        x.style.cursor='default';
        x.style.display='block';
    }
	
    if (fUnlockAnchor[2]) fUnlockAnchor[2].focus();
}

function fUnlock_Display22(val) { 

    if (val.indexOf(':') != -1) {
        var arr = val.split(":");
        mval = arr[0];
        modname = arr[1];
		//        fUnlock[1].style.display='none';
		//        fUnlock[2].style.display='block';
		//        fUnlock[3].style.display='none';
		        $j('#f_unlock_1').css('display','none')
		        $j('#f_unlock_2').css('display','block')
		        $j('#f_unlock_3').css('display','none')
        document.getElementById('manu_id').value=mval;
        document.getElementById('manu_nam').value=modname;
        getGSMModel(mval);
        if(document.getElementById('manuname')!=null)
        {
            document.getElementById('manuname').innerHTML=modname+'&nbsp;&nbsp;<a href="#" onclick="fUnlockDisplay1();fUnlockDisplay22return(); return false">[x] clear</a>';
        }
        else if(document.getElementById('manu_name')!=null)
        {
            document.getElementById('manu_name').innerHTML='<b>'+modname+'</b>&nbsp;&nbsp;<a href="#" onclick="fUnlockDisplay1();fUnlockDisplay22return(); return false">[x] clear</a>';
        }
        if (x = FIND('b_unlock_my_phone')) {
            //x.style.backgroundPosition='0 0';
            //x.style.cursor='pointer';
            x.disabled = true;
        }
	
        if (fUnlockAnchor[2]) fUnlockAnchor[2].focus();
    }
}

function fUnlockDisplay22return(val) {
    if(document.getElementById('manufacturer-general')) {
      document.getElementById('manufacturer-general').style.display = 'block'
    }
    if(document.getElementById('manufacturer-models')) 
    document.getElementById('manufacturer-models').innerHTML='';
}

/*function fUnlockDisplay3(mval,modname) {
	
	fUnlock[1].style.display='none';
	fUnlock[2].style.display='none';
	fUnlock[3].style.display='block';
	document.getElementById('model_id').value=mval;
	var mn1 = document.getElementById('manu_id').value;
	var mn2 = document.getElementById('manu_nam').value;
	document.getElementById('manuname1').innerHTML=document.getElementById('manuname').innerHTML+"<dl><dt>Model</dt><dd>&bull;"+modname+"&nbsp;<a href='#' onclick=fUnlockDisplay2("+mn1+",'"+mn2+"');>[x] clear</a></dd></d1>";
	
	if (x = FIND('b_unlock_my_phone')) x.style.display='block';
}*/

function fUnlockDisplay3(val) {
    var arr = val.split(":");
    mval = arr[0];
    modname = arr[1];
    url = arr[2];
	url_rest = arr[3];
    if (x = FIND('b_unlock_my_phone')) {
        x.style.backgroundPosition='0 0';
        x.style.cursor='pointer';
        x.disabled = false;
        x.style.display='block';
    } else {
		var url_needed = url_rest.split("/shop/");
        window.location.href = url_needed[1];
        return ;
    }
    $j('#f_unlock_1').css('display','none')
    fUnlock[2].style.display='none';
    fUnlock[3].style.display='block';
    document.getElementById('model_id').value=mval;
    var mn1 = document.getElementById('manu_id').value;
    var mn2 = document.getElementById('manu_nam').value;
    //document.getElementById('manu_id').value=mn1;
    if(document.getElementById('manuname1')!=null)
    {
        document.getElementById('manuname1').innerHTML=document.getElementById('manuname').innerHTML+"<dl><dt>Model</dt><dd>&bull; "+modname+"&nbsp;<a href='#2' onclick=fUnlockDisplay2("+mn1+",'"+mn2+"');>[x] clear</a></dd></d1>";
    }
    else if(document.getElementById('manuname2')!=null)
    {
        document.getElementById('manuname2').innerHTML = document.getElementById('manu_name').innerHTML;
		
        document.getElementById('modname2').innerHTML = "<b>&gt;&nbsp;&nbsp;"+modname+"</b>&nbsp;&nbsp;<a href='#' onclick=fUnlockDisplay2("+mn1+",'"+mn2+"');>[x] clear</a>";
    }
	
}



function unlockNowInit() {
    for (i=1; i<=3; i++) {
        fUnlock[i]=FIND('f_unlock_'+i);
        if (!fUnlock[i]) return(false);
    }
    fUnlockAnchor[1]=FIND('anchorDrop');
    fUnlockAnchor[2]=FIND('modelSelect');
    if (fUnlockAnchor[2]) fUnlockAnchor[2].onchange = fUnlockDisplay3;
    fUnlockDisplay1();
}

function setDefaults() {
	
    if (eGlobal=FIND('global')) {
		
        setBg();
        window.onResize = setBg;
    }
    flyoversMainInit();
    unlockNowInit();
}

function umpFilterManufacture(val){
    if (val.indexOf(':') != -1) {
        var arr = val.split(":");
        mval = arr[0];
        modname = arr[1];
          $j('table#tab_compare').hide()
          $j('#product_display').append('<div id="ajax-preloader" style="width:670px;"><div style="overflow:hidden;"><div style="width:6px; float:left;"></div><div ></div><div style="width:6px; float:right;"></div></div><div align="center" style="overflow:hidden; "><div style="width:700px;"><div id="row" align="center" style="width:100%;height:225px; font-size:16px; color:#000000; margin-top:100px;" class="product-bottom123"><img src="images/ajax_loader/ajax-loader.gif" alt="GSM Liberty" style="vertical-align:middle;" title="GSM Liberty" border="0" />&nbsp;<span class="manuf">Loading.........</span></div></div></div><div style="clear:both;"></div></div>');
          var i = 0
          $j('table#tab_compare_filter').hide().html('');
          var tr = $j('<tr>')
          $j("#tab_compare td.product.m_id_"+mval+"").each(function(index, element){
              td = $j(element).clone()
              tr.append(td);
              i=i+1
              if(i==3){
                  $j('table#tab_compare_filter').append(tr)
                  i = 0
                  tr = $j('<tr>')
              }
            })
          if (i!=0) $j('table#tab_compare_filter').append(tr)
          $j('#ajax-preloader').remove();
          $j('table#tab_compare_filter').show()
          $j("#tab_compare_filter td.product input:checkbox").click(function () {
                $j('table#tab_compare #'+$j(this).attr('id')).get(0).checked = this.checked
          })
//        $j("#products td.product:not(.m_id_"+mval+"):visible").fadeOut('fast',function(){
//            $j("#products td.product.m_id_"+mval).fadeIn()
//        })
    } else {
        $j('table#tab_compare_filter').hide()
        $j('table#tab_compare').show()
    }
}

//fucntion for getting price and turnaround on the basis of group which maps with carrier :: added by Sumit on 12th July,2010
function fget_Attributes_Values(attributeId,pId,taxId) {
	if(attributeId == 0) {
		 document.getElementById('turnaroundId').style.display = 'none';
		 document.getElementById('turnaroundId2').style.display = 'none';
		 document.getElementById('priceId').style.display = 'none'; 
		 return true;
	}
	getAttributesValues(attributeId,pId,taxId);
}

//fucntion for getting price and turnaround on the basis of group which maps with carrier :: added by Sumit on 12th July,2010
 function fget_Attributes_Values_old(attributeId,pId,taxId) {
 	if(attributeId == 0) {
 		 document.getElementById('turnaroundId').style.display = 'none';
 		 if(document.getElementById("turnaroundId2")) {
      document.getElementById('turnaroundId2').style.display = 'none';
      }
 		 document.getElementById('priceId').style.display = 'none'; 
 		 return true;
 	}
 	getAttributesValuesOld(attributeId,pId,taxId);
 }

function fget_Attributes_Values_New(attributeId,pId,taxId) {
	if(attributeId == 0) {
 		 $j('#helptext').html("<p>Please enter phone IMEI and select Carrier for pricing and turnaround time</p>");
		 $j('#helptext').show();		
		 $j('#priceInfo').hide();
		 $j('#turnaroundId').html("&nbsp;&nbsp;&nbsp;");
		 $j('#priceId').html("&nbsp;&nbsp;&nbsp;");
		 
		  //$j('#cartButton').attr("disabled", true);
		  $j('#cartButton').attr("className", "btt btt-add-to-cart-disabled");
		 return true;
	}
	getAttributesValuesNew(attributeId,pId,taxId);
}

function fUnlock_Display22_Nokia_Unlock(val) { 		   
        getGSMModelNokiaUnlcok(val);  
}

window.onload = setDefaults;
