//include "sideBar.js"


function toggleTabSelection(tabId, tabContentId){
   for (i=1; i<=6; i++) {
   		document.getElementById('tab'+i).className="deselected";
		document.getElementById('tabContent'+i).className="dN";
   }
   document.getElementById(tabId).className = "selected";
   document.getElementById(tabContentId).className = "dB";
}

function $() {
        
	if (arguments.length>1) {
		return false;
	}
	if (arguments.length<1) {
		return false;
	}

	var element = arguments[0];

    if (typeof element == 'string') {
        if (document.getElementById) 
        {
            try 
            {
                element = FCKValue(element);
            }
            catch(err)
            {
                element = document.getElementById(element);            
            }

        } else if (document.all) {
            element = document.all[element];
        }
    }
    
	
	return element;
}

//--Shoping Cart-------------------
function AddToTotal(price)
{
    total = parseFloat($("divTotal").innerHTML.replace(',','.')) * 100 + price * 100;
    total = total / 100;
    $("divTotal").innerHTML = showLei(total);
    $("divCartEmptyMessage").style.display = "none";
    $("divTotal").style.display = "inline";
    $("divTotalCurrency").style.display = "inline";
}

function AddPhoneToCart(pID, cant, sID, name, price, priceWS)
{
    priceType = 0;
    try { priceType = $("rdLiber").checked ? 1 : 0; } catch (e) { }
    try { priceType = priceType == 0 ? ($("rdAbonament").checked ? 2 : 0) : priceType; } catch(e) { }
    
    if(priceType > 0)
    {
        selectedPrice = priceType == 1 ? price : priceWS;
        
        store = priceType - 1;
        var resultAdd=Netlogiq.Controls.Sidebar.AddToCart(pID, cant, sID, name, priceWS, price, store);  
        if(resultAdd.value == null)
        {
            location.reload();
        }
        else
        {
            $("shoppingCartItems").innerHTML=resultAdd.value;
            AddToTotal(selectedPrice);
        }
    }
    else
    {
        alert("Va rugam sa alegeti o varianta de abonament.");
    }
}

function AddToCart(pID, cant, sID, name, price, store)
{
     var resultAdd=Netlogiq.Controls.Sidebar.AddToCart(pID, cant, sID, name, 0, price, store);
     if(resultAdd.value == null)
     {
        location.reload();
     }
     else
     {
         $("shoppingCartItems").innerHTML=resultAdd.value;
         AddToTotal(price);
     }
}
function RemoveProduct(pid, sid,store)
{
    var result=Netlogiq.Controls.Sidebar.RemoveProduct(pid,sid,store);
    var elem = "";
    var price = 0.00;
    if (sid ==1)
    {
        elem+="Phone";
    }
    else
    {
        elem+="Accesory"
    }
    price = parseFloat($("count"+elem+ pid +"_" + store).innerHTML);
    price = price * parseFloat($("price"+elem+ pid +"_" + store).innerHTML.replace(",","."));
    price = price * 100;
    elem = "dv" + elem + pid + "_" +store;
    
    price = -1 * price;
    AddToTotal(price / 100);
    if(result.value == 0)
    {
         $("divTotal").innerHTML = "0.00";
         $("divTotal").style.display = "none";
         $("divTotalCurrency").style.display = "none";
         $("divCartEmptyMessage").style.display = "inline";
    }
    try { eval("document.all." + elem + ".removeChild($(elem))");}
    catch(ex){$(elem).parentNode.removeChild($(elem));}
}
//--End Shoping Cart-------------------


//* Search */
var search_wasCleared = true;

function cautare() {
    tx = $("txSearch").value;
    
    if (trim(tx).length <=1 || tx == "cautare telefon") {
        alert("Va rugam sa specificati cuvintele dupa care doriti sa se caute.");
    } else {
        document.location.href = "/rezultateCautare.aspx?cautare=" + trim(tx);
    }
}

function search_clearText() {
    if ($("txSearch").value=="cautare telefon" ) {
        $("txSearch").value = "";
        search_wasCleared = true;
    }
}

function search_showText() {
    if (search_wasCleared && trim($("txSearch").value).length == 0) {
        $("txSearch").value = "cautare telefon";
        search_wasCleared = false;
    }
}

function search_submitIfEnter(e) {
    if (window.event && window.event.keyCode == 13) {
        cautare();	
	}
	else if (e.keyCode == 13) {
	    cautare();
	}
}
//* END Search */

function popupPic(sPicURL) 
{
    var w = 600;
    var h = 600;
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var winprops = 'height='+w+' ,width='+h+',top='+wint+',left='+winl+',resizable=true,status=0';
    window.open( "/popups/vizualizareFotografie.html?"+sPicURL, "", winprops);
    
}

/*START Newsletter*/
var subscribe_wasCleared = true;

function subscribe_clearText() {
    if ($("txSubscribeEmail").value=="adresa email" ) {
        $("txSubscribeEmail").value = "";
        search_wasCleared = true;
    }
}

function subscribe_showText() {
    if (search_wasCleared && trim($("txSubscribeEmail").value).length == 0) {
        $("txSubscribeEmail").value = "adresa email";
        search_wasCleared = false;
    }
}

function subscribe_submitIfEnter(e) {
    if (window.event && window.event.keyCode == 13) {
        SendSubscriber();	
	}
	else if (e.keyCode == 13) {
	    SendSubscriber();
	}
}

function SendSubscriber()
{
    var txEmail = document.getElementById("txSubscribeEmail").value;  
    var error = "";
        
    if (trim(txEmail).length > 0)
    {
        if (trim(txEmail).length > 0  && !isEmail(txEmail))
        {
            error += "- Campul \"Abonare newsletter\" trebuie sa contina o adresa de email valida;\n";
        }        
    }
    else
    {
        error += "- Campul \"Abonare newsletter\" trebuie sa contina o adresa de email valida;\n";
    }
        
    if (error.length > 0) 
    {
        error = "Va rugam sa remediati urmatoarele probleme:\n" + error;
        alert(error);
    }
    else
    {
        document.location.href='/confirmareInscriere.aspx?sEmail='+txEmail;
    }
}
/*END Newsletter*/


/*START Utilities for header*/
function trim(val)
{
	val = val.replace(/[\s]+$/g,"");
	val = val.replace(/^[\s]+/g,"");
	return val;
}

function isEmail(val)
{
	val = trim(val);
	if(val=="")
	{
		return false;
	}
	if((val != null) && (val != "")){
		
		var m = val.match(/^[\w\.-]+@[\w\.\-]+\.[a-zA-Z]{2,7}$/);
				
		return ((m!=null)&&(m.length>0));
	}
	else{
		return false;
	}
}
/*END Utilities for header*/

function showLei(x) {
    var price = parseFloat(x)*100;
    var priceInt = parseInt(x)*100;
    var dec = parseInt(price - priceInt);
    if (dec < 10) dec = "0" + dec;
    return priceInt/100 + "," + dec;
}

//<![CDATA[
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
//]]>

jQuery(function($) {
	var selectedCateg = $('#nav li#navActive');
	var categName = selectedCateg.attr('class');
	$('#infoText').addClass(categName);
});

