/* PROGRESS DIV */
function pageLoad(sender, args){   
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
}

function beginRequest(sender, args){
    var updateProgressDiv = $get('updateProgressDiv'); 
    updateProgressDiv.style.display = '';
    var arrayPageScroll = getPageScroll();
    Sys.UI.DomElement.setLocation (updateProgressDiv, 0, arrayPageScroll[1]);
    
    var overpopup = $get('overpopup'); 
    if (overpopup != null) overpopup.style.display = 'none';
}
function endRequest(sender, args){
    var updateProgressDiv = $get('updateProgressDiv'); 
    updateProgressDiv.style.display = 'none';
    var arrayPageSize = getPageSize();
    
    var element = $get('overlayer');
    if (element != null)
    {
        element.style.height = arrayPageSize[1] +"px";
    }
    
    var overpopup = $get('overpopup'); 
    if (overpopup != null)
    {
        var overpopupBounds = Sys.UI.DomElement.getBounds(overpopup);
        var arrayPageScroll = getPageScroll();
        if (overpopupBounds.height < arrayPageSize[3])
            var y = (arrayPageScroll[1] + Math.round((arrayPageSize[3] / 2))) - Math.round(overpopupBounds.height / 2);
        else
            var y = ((arrayPageScroll[1] + Math.round((arrayPageSize[3] / 2))) - Math.round(overpopupBounds.height / 2)) + ((overpopupBounds.height-arrayPageSize[3])/2);
        Sys.UI.DomElement.setLocation (overpopup, 0, y); 
    }
}


/* KILL SPECIALS KEYS */
function killBack(evt) 
{
    var mytarget;
    var keyCode;
    var is_ie;
    if (document.all) 
    {
        keyCode = event.keyCode;
        mytarget = window.event.srcElement.type;
        is_ie = true;
    }
    else if (document.addEventListener) {
        // Firefox
        mytarget = evt.target.type;
        keyCode = evt.keyCode;
        is_ie = false;
    } else {
        // Need to add a default or other browser cases here.
        return true; // Just give up and exit for now.
    }
    
    if (keyCode != 8){
        return true;
    }
    switch (mytarget)
    {
        case 'textarea':
        case 'text':
            return true;
        default:
            if (!is_ie) {
                evt.preventDefault();
                evt.stopPropagation();
            }
            return false;
     }
}
document.onkeydown = killBack;

/* NOT KEY IN INPUT */
function notkey()
{
	return false;
}

/* telephone validation */
function validatePhone(source, args)
 {
    nr = args.Value;
    nr = nr.replace(/[^0-9]/g, ""); //avalaible only numbers for checking
    
    var i, equalCount, consCount, equalMax, consMax;
    equalCount = 1;
    equalMax = 0;
    consMax = 0;
    consCount = 1;	
    
    c = 0;
    for(i=0;i<nr.length;i++)
    {
        c++;
	    if(nr.charAt(i) == nr.charAt(i-1)){												
		    if(++equalCount > equalMax){
			    equalMax = equalCount;
		    }				
	    }
	    else{
		    equalCount = 1;					
	    }			
	    if(nr.charAt(i)-1 == nr.charAt(i-1)){
		    if(++consCount > consMax){
			    consMax = consCount;
		    }
	    }
	    else{		
		    consCount = 1;
	    }
		
    }
    if((equalMax > 4) || (consMax > 4)){
        args.IsValid = false;
    }
    else args.IsValid = true;
 }
 
function addBookmark(title, url) {
    if (window.sidebar) { // firefox
          window.sidebar.addPanel(title, url,"");
    } else if( document.all ) { //MSIE
            window.external.AddFavorite( url, title);
    } else {
           alert("Sorry, your browser doesn't support this");
    }
}

function changeUpsellPricesBySize(id, prices)
{
    if ((id!="")&(prices!=""))
    {
        a_id = id.split('-');
        a_prices = prices.split('-');
        for(i=0;i<a_id.length;i++)
            document.getElementById("Extra" + a_id[i]).innerHTML = a_prices[i].replace(".",",");
    }
}

function changeTotalPrice(idtotal, value)
{
    value = value.replace(",",".");
    // all the extras added to the total
    var extras = document.getElementsByName("ckbExtra");
    for(i=0;i<extras.length;i++)
    {
        if (extras[i].checked)
        {
            current = document.getElementById("Extra"+extras[i].value).innerHTML.replace(",",".");
            value = value*1 + current*1;
        }
    }
    current = value;
    if (current.toFixed) current = current.toFixed(2);
    document.getElementById(idtotal).innerHTML = current.replace(".",",");
    checkValue();
}

function addedTotalPrice(checked, idtotal, idadded)
{ 
    var total = document.getElementById(idtotal).innerHTML.replace(",",".");
    var added = document.getElementById(idadded).innerHTML.replace(",",".");
    if (checked)
        total = total*1 + added*1;
    else 
        total = total*1 - added*1;
    if (total.toFixed) total = total.toFixed(2);
    document.getElementById(idtotal).innerHTML = total.replace(".",",");
    checkValue();
}

function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function checkValue()
{
    var box = document.getElementById("qty");
    if(box.value == 0) box.value = 1; else box.value = box.value*1;
    var totalprice = document.getElementById("TotalPrice").innerHTML.replace(",",".");
    var current = (totalprice*1) * (box.value*1);
    if (current.toFixed) current = current.toFixed(2);
    document.getElementById("Total").innerHTML = current.replace(".",",");
}

function changeCross()
{
    var menu = document.getElementsByName("txtCross");
    var current = 0;
    for(i=0;i<menu.length;i++)
    {
        if (menu[i].value != "" & menu[i].value != "0")
            current += menu[i].title.replace(",",".") * menu[i].value;
        else if (menu[i].value == "")
            menu[i].value = "0";
    }
    if (current.toFixed) current = current.toFixed(2);
    document.getElementById("TotalPrice").innerHTML = current.replace(".",",");
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function PayMethod(value)
{
    var panel = $get("panPayMethod");
    panel.style.display = value;
}