/*AJAX begin*/

domain = document.URL.match( /^(https?:\/\/[^\/:]+)/ );
domain = domain[1]?domain[1]:'';
var ht = domain+'/portal/';

function createRequestObject()

  {
	var rez;
	if(window.XMLHttpRequest) {rez = new XMLHttpRequest();}
	else if(window.ActiveXObject) {rez = new ActiveXObject("Microsoft.XMLHTTP");}
	else { alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');}
	return rez;
  }

function in_ajax(nam){
	if (nam)
	     {
			$('hiddenUser').value = document.autoriz.Card_nam.value;
			$('hiddenComp').value = document.autoriz.PIN.value;
		 }
	
	else 
     	 {
			$('hiddenUser').value = $F('Card_nam_ag');
			$('hiddenComp').value = $F('PIN_ag');
		 }
	var req=createRequestObject();
	var myAjax = new Ajax.Request(
    ht,
    	{method: 'post', 
			onComplete: function(req){document.temp.submit();}, 
			onLoading: function(req) 
			{	
				if (nam){
				    var z=$("login");
				    var str='<div id="ajaxObj"><div align="center" valign="center" id="inobj">';
				    str=str+'<img src="/images/portal/spinner.gif"></div></div>';
				    /*str=str+'LOADING........</div></div>';*/
				    z.innerHTML=str;
				}
				else {
				    var z=$("Continue_login");
				    var str='<div id="ajaxObj"><div align="center" valign="center" id="inobj">';
				    str=str+'<img src="/images/portal/spinner.gif"></div></div>';
				    /*str=str+'LOADING........</div></div>';*/
				    z.innerHTML=str;
				}
				
			}
		});
}


function changing_email(){
	alert(1);
	var req	= createRequestObject();
	var myAjax = new Ajax.Request(
    domain+'/portal/user_edit',
    	  {
    		method: 'post', 
			
			onComplete: function( req )
						  {
							  alert(2);
							  document.EditForm.update_email.submit();
						  }, 
			onLoading: function(req) 
			  {	
					alert(3);
				    var z = $("email_info");
				    var str='<div id="ajaxObj"><div align="center" valign="center" id="inobj">';
				    str=str+'<img src="/static/images/portal/spinner.gif"></div></div>';
				    /*str=str+'LOADING........</div></div>';*/
				    z.innerHTML=str;
				
			}
		});
}




/*AJAX end*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//																	 //	
//							PORTAL JAVA SCRIPT						 //
//																	 //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

function clear_data()
{
	document.location.href="/portal/transactions";
}

function fill_table(num)
{
	var table_id = "transactions";
	index_from = index_from_transactions;

	var table = document.getElementById(table_id);
	var count_arr = index_from+num;

	if(count_arr > arr.length)
		{
			count_arr = arr.length;
		}
for( i = index_from; i < count_arr; i++)
{
	var newRow = table.insertRow(-1);
/*	if ( !(i%2) ) 
	{
	newRow.bgColor="#EAF4D9";
	newRow.setAttribute("class", 'stripe');
	}*/
	var newCell = newRow.insertCell(0);
    newCell.innerHTML=arr[i]['timestamp'];
    newCell.setAttribute("id", 'transact');
    var newCell = newRow.insertCell(-1);
    newCell.innerHTML=arr[i]['authno'];
	newCell.setAttribute("id", 'transact');      
    var newCell = newRow.insertCell(-1);
    newCell.innerHTML=arr[i]['description'];    
    newCell.setAttribute("id", 'transact');    
    var newCell = newRow.insertCell(-1);
    newCell.align='right';
    newCell.innerHTML='$' + arr[i]['amount'];    
    newCell.setAttribute("id", 'transact');    
    var newCell = newRow.insertCell(-1);
    newCell.align='right';
    newCell.innerHTML='$' + arr[i]['fee'];

	
}

index_from_transactions = i;
ex = Hide_view(ex)
Stripe_row();
}

function Hide_view(val)
{
    var l_v = document.getElementById('link_view');
    if ( ( val == 1 ) && ( arr.length > 5))
  		{
		  l_v.innerHTML='<a href="#" onclick = "fill_table(20)">View More</a>';val=0;
		}
	else 
		{
		  val=1;
		  l_v.innerHTML = ''; 
		}
return val;		
	
}


function select_country()
{


  box = document.forms[0].country;
	var destination = box.options[box.selectedIndex].value;

     if (destination == 'USS' ) destination = 'US';

	  if (destination)
	  {

		  var card = document.getElementById("card_f");
		  var card_f = card_fee[destination]/100;		  
		  card.innerHTML= "$"+card_f;
		  var sel = document.getElementById("method");
		  sel.value = 0;
		  sel.options[1].value = 0;
		  sel.options[1].text = "Select";
		  sel.options[1].value = (ship1_fee[destination]/100);
		  sel.options[1].text = "Regular $"+(ship1_fee[destination]/100);
		  sel.options[2].value = (ship2_fee[destination]/100);
		  sel.options[2].text = "Express $"+(ship2_fee[destination]/100);
		  var total = document.getElementById("total");
		  total.innerHTML= "N/A Select shipping Type";  

	  }
	  
}

function select_metod()
{
  box = document.forms[0].country;
	var destination = box.options[box.selectedIndex].value;

     if (destination == 'USS' ) destination = 'US';

	  if (destination)
	  {

		  var sel = document.getElementById("method");
		  sel.options[1].value = 0;
		  sel.options[1].text = "Select";
		  sel.options[1].value = (ship1_fee[destination]/100);
		  sel.options[1].text = "Regular $"+(ship1_fee[destination]/100);
		  sel.options[2].value = (ship2_fee[destination]/100);
		  sel.options[2].text = "Express $"+(ship2_fee[destination]/100);
		  var card_f = card_fee[destination]/100;
		  var total_fee = (Math.round(card_f*100+eval(sel.options[sel.selectedIndex].value)*100))/100;
		  var total = document.getElementById("total");
		  var price = document.getElementById("sum_price");

		  if ( sel.options[sel.selectedIndex].value == 0 )
		  {
			  total.innerHTML= "N/A Select shipping Type";  
			  price.innerHTML= '-';
			  price.style.border="none";
		  }
		  else
		  {	
			  total.innerHTML= "$"+total_fee;
			  price.innerHTML= "$"+eval(sel.options[sel.selectedIndex].value);
/*			  price.innerHTML = '<span align=right>'+price.innerHTML+'<div style="margin:0padding:0px;height:3px; width:35px; border-bottom:solid 1px #78a22f;"></span></div>';*/
  			  price.innerHTML = '<div style="border-bottom: solid 1px #78a22f;">'+ '&nbsp;&nbsp;&nbsp;&nbsp;'+price.innerHTML+'</div>';			  
			  total.innerHTML = '<span align=right>'+total.innerHTML+'<div style="margin:0padding:0px;height:3px; width:35px; border-bottom:solid 1px #78a22f;"></div>'+
					'<div style="margin:0;padding:0px;height:3px; width:35px; border-bottom:solid 1px #78a22f;"></div>';
		  }	  
		  
		  

	  }
}


