// JavaScript Document
function toggle(id){
    if(document.getElementById(id).style.display=='none'){
        document.getElementById(id).style.display='';
    }else{
        document.getElementById(id).style.display='none';
    }
}
function calculatePurchaseTotal(base_url){

     var num            = document.getElementById('nos').value;
     var gruppi_money   = document.getElementById('gruppi_money').value;
     var price        = document.getElementById('pricess').value;
     //alert(num+","+gruppi_money+","+price);
     
    if(!isNaN(num) ){
        var total           = num*price;

        

        var obj_bill_money  = document.getElementById('bill_money');

        document.getElementById('noss').innerHTML       = total + " kr";
        document.getElementById('total').value          = total;

        if(obj_bill_money!=null){
            
            if(gruppi_money >= total){
                obj_bill_money.innerHTML                            = '0 kr';
                document.getElementById('with_points').innerHTML    = "-" + total;
                document.getElementById('goNext_btn').src           = base_url + "img/confirmpurchase.jpg";

            }else{
                var diff = total - gruppi_money;
                obj_bill_money.innerHTML                            = diff + " kr";
                if(gruppi_money == 0){
                    document.getElementById('with_points').innerHTML    = gruppi_money;
                }else{
                    document.getElementById('with_points').innerHTML    = "-" + gruppi_money;
                }
                
                document.getElementById('goNext_btn').src           = base_url + "img/gotopayment.jpg";
            }
        }
    }
}
function calculatePurchaseTotal2(base_url){
	
     var num            = document.getElementById('nos').value;
     var gruppi_money   = document.getElementById('gruppi_money').value;
     var price        = document.getElementById('pricess').value;
     
    if(!isNaN(num) ){
        var total           = num*price;
        var obj_v_price     = document.getElementById('v_price');
        var obj_bill_money  = document.getElementById('bill_money');

        document.getElementById('noss').innerHTML       = total+ " kr";
        document.getElementById('total').value          = total;

        if(obj_v_price!=null){
            obj_v_price.innerHTML    = total+ " kr";
        
            if(gruppi_money >= total){
                obj_bill_money.innerHTML = '0 kr';
                document.getElementById('goNext_btn').src=base_url+"img/confirmpurchase.jpg";

            }else{
                var diff = total - gruppi_money;
                obj_bill_money.innerHTML = diff + " kr";
                document.getElementById('goNext_btn').src=base_url+"img/gotopayment.jpg";
            }
        }
        //xajax_need_payment_information(total);
    }
} 
function hideElementById(id){
	document.getElementById(id).style.display = "none";
	
}
function get_company_info(company_id){

    xajax_get_company_info(company_id);
 }
function verify(formname,base_url,isLoggedin){
	var flag= false;
	if(formname == 'loginform'){
		document.myform.action = base_url+'index.php/login/login_ac2/';
		return true;
	}
	else if(formname == 'buyform'){	
		document.myform.action= base_url+'index.php/regbuy/confirmation/';
		return true;
	}
}


var yuanzhi;

function kongzhi(obj){
	yuanzhi=obj.value.replace(/(^\s*)|(\s*$)/g,"");
	//obj.value='';
}
function panzhi(obj){
	var gaizhi=obj.value.replace(/(^\s*)|(\s*$)/g,"");
	if(gaizhi==''){
	obj.value=yuanzhi;
	}
}
 	function buyuser(){
   xajax_buyuser();
   
}
function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; }
//original jindu ver. is below (jindu_bk)
function jindu(){

	var buyusers= document.getElementById('buyusers').innerHTML;
	var last_users= document.getElementById('last_users').innerHTML; 
	
	var bar = document.getElementsByTagName("em")[0];
	if(!isEmpty(bar)){
		for(var i=0;i<=buyusers*100/last_users;i++)
		{
			(function()
			{
				var pos=i;
				setTimeout(function()
				{
				   bar.style.left =pos+"%";
				},pos*50)
			})()
		}
	}
	
}
function jindu_bk(){

	var buyusers= document.getElementById('buyusers').innerHTML;
	var max_users= document.getElementById('max_users').innerHTML; //is getting last_users (minimum)
	
	if(buyusers!=max_users)
	{
 		var bar = document.getElementsByTagName("em")[0];
		for(var i=0;i<=buyusers*100/max_users;i++)
		{
			(function()
			{
				var pos=i;
				setTimeout(function()
				{
				   bar.style.left =pos+"%";
				},pos*50)
			})()
		}
		if(max_users==buyusers)
		{
			document.getElementById('buybutt').innerHTML=
			'<img src="img/home/Gruppi_23.png" style="" alt="inforutaup"/>';
			window.clearInterval(oTimer); 
			window.clearInterval(oTimers); 
		}
	}
	else
	{
			document.getElementById('buybutt').innerHTML=
			'<img src="img/home/Gruppi_23.png" style="" alt="inforutaup"/>';
			window.clearInterval(oTimer); 
			window.clearInterval(oTimers); 
				
	}
}

function yessong(){
	
	       document.getElementById('songyes_no').style.display='';   
			document.getElementById("yes_no_song").value='1';
			
	
	}
function cancelyessong(){
	
	       document.getElementById('songyes_no').style.display='none';   
			document.getElementById("yes_no_song").value='0';
			
	
}	
function IsNumeric(input)
{
   return (input - 0) == input && input.length > 0;
}

function printDiv()
{
	var DocumentContainer = document.getElementById('receipt');
	var WindowObject = window.open('', "Receipt",
	
	"width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
	WindowObject.document.writeln(DocumentContainer.innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
}

