// JavaScript Document

var total_rows = 0;

function display_menu()
{
    document.write('<div id="ddtopmenubar" class="mattblackmenu">');
    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
    document.write('<tr>');
    document.write('<td class="buttons"><a href="index.aspx">EXHIBITIONS</a></td>');
    document.write('<td width="100" class="buttons"><a href="index.aspx?page=whoweare">WHO WE ARE</a></td>');
    document.write('<td width="120" class="buttons"><a href="#">MY ACCOUNT </a></td>');
    document.write('<td width="150" class="buttons"><a href="#" rel="ddsubmenu1">AT YOUR SERVICE </a></td>');
    document.write('<td width="203">&nbsp;</td>');
    document.write('</tr>');
    document.write('</table>');
	document.write('</div>');
	
	ddlevelsmenu.setup("ddtopmenubar", "topbar") //ddlevelsmenu.setup("mainmenuid", "topbar|sidebar")

	document.write('<ul id="ddsubmenu1" class="ddsubmenustyle">');
	document.write('<li><a href="index.aspx?page=aboutmyorder">&raquo; About my Order</a></li>');
	document.write('<li><a href="index.aspx?page=shipping">&raquo; Shipping</a></li>');
	document.write('<li><a href="index.aspx?page=returns">&raquo; Returns</a></li>');
	document.write('<li><a href="index.aspx?page=contact">&raquo; Contact</a></li>');
	document.write('<li><a href="index.aspx?page=faq">&raquo; FAQ</a></li>');
	document.write('<li><a href="index.aspx?page=policy">&raquo; Policy</a></li>');
	document.write('<li><a href="index.aspx?page=termsofuse">&raquo; Terms of Use</a></li>');
	document.write('</ul>');

}

function inc_trows()
{
    total_rows = +total_rows + 1;
}

function calc_total()
{
    var grand_total1 =7;
    for(i=1;i<=total_rows;i++)
    {
        document.getElementById('Row' + i + '_total').value = (+document.getElementById('Row' + i + '_qty').value)*(+document.getElementById('Row' + i + '_rate').value)
	    grand_total1 = +grand_total1 + +document.getElementById('Row' + i + '_total').value;
    }
    document.getElementById('Grand_Total').value = grand_total1;
}

function button_save()
{
    if(total_rows != 0)
    {
        document.getElementById('form_action').value = 'save';
        document.getElementById('totalrows1').value = total_rows;
        document.getElementById('Grand_Total1').value = document.getElementById('Grand_Total').value;
        return true;
    }
    else
    {
        alert('There are no items in cart!');
        return false;
    }
}

function button_submit()
{
    if(total_rows != 0)
    {
        document.getElementById('form_action').value = 'submit';
        document.getElementById('totalrows1').value = total_rows;
        document.getElementById('Grand_Total1').value = document.getElementById('Grand_Total').value;
        return true;
    }
    else
    {
        alert('There are no items in cart!');
        return false;
    }
}


function button_delete(rownno)
{
    document.getElementById('form_action').value = 'deleterow';
    document.getElementById('totalrows1').value = total_rows;
    document.getElementById('delete_id').value = document.getElementById('Row' + rownno + '_id').value;
}


function addRowToTable()
{

  var tbl = document.getElementById('table1');
  var lastRow = tbl.rows.length - 2;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = +total_rows + 1;
  var rowclass = iteration%2;
  var row = tbl.insertRow(lastRow);
  row.id = 'Row' + iteration + '_Row';
  if(rowclass == 1)
  {
    row.className = 'tr1';
   }
   else
   {
    row.className = 'tr2';
   }
  
  // column1 for delete button
  var cell1 = row.insertCell(0);
  cell1.align = 'center';
  cell1.className = 'cart_css_td_del';
  var b1 = document.createElement('input');
  b1.className = 'button_delete';
  b1.type = 'image';
  b1.name = 'Row' + iteration + '_delete';
  b1.id = 'Row' + iteration + '_delete';
  b1.src = 'images/Delete_Icon.png';
  b1.alt = 'Delete Item';
  b1.onclick = function(){return button_delete(iteration)};
  cell1.appendChild(b1);
  
  
  //column2 for Sr No
  var cell2 = row.insertCell(1);
  cell2.align = 'center';
  cell2.className = 'cart_css_td_srno';
  var lab1 = document.createElement('input');
  lab1.type = 'hidden';
  lab1.runat = 'server';
  lab1.name = 'Row' + iteration + '_id';
  lab1.id = 'Row' + iteration + '_id';  
  cell2.appendChild(lab1);
  var div1 = document.createElement('div');
  div1.className = 'cart_css_div_srno';
  div1.name = 'Row' + iteration + '_srno';
  div1.id = 'Row' + iteration + '_srno';  
  cell2.appendChild(div1);
  
  // column3 for item description
  var cell3 = row.insertCell(2);
  cell3.align = 'left';
  var txl;
  div2 = document.createElement('div');
  div2.name = 'Row' + iteration + '_itemdesc';
  div2.id = 'Row' + iteration + '_itemdesc';
  
  var img1;
  img1 = document.createElement('img');
  img1.alt = '';
  img1.className = 'cart_css_thumb';
  img1.src = 'images/inner1.jpg';
  img1.name = 'Row' + iteration + '_IMG';
  img1.id = 'Row' + iteration + '_IMG';
  
  var tb2;
  tb2 = document.createElement('table');
  tb2.setAttribute('cellPadding', '0');
  tb2.setAttribute('cellSpacing', '0');
  tb2.className = 'combobox';
  
  var tb1_row = tb2.insertRow(0);
  var tb2_cell1 = tb1_row.insertCell(0);
  tb2_cell1.id = 'Row' + iteration + '_Cell3';
  var tb2_cell2 = tb1_row.insertCell(1);
  tb2_cell1.appendChild(img1);
  tb2_cell2.appendChild(div2);
  
  cell3.appendChild(tb2);
  
  
  //column4 for qty dropdown
  var cell4 = row.insertCell(3);
  cell4.align = 'center';
  var sel1 = document.createElement('select');
  sel1.className = 'dropdown_qty';
  sel1.runat = 'server';
  sel1.name = 'Row' + iteration + '_qty';
  sel1.id = 'Row' + iteration + '_qty';
  for(var i=1;i<10;i++)
  {
    sel1.options[i-1] = new Option(i,i);
  }
  sel1.onchange = function(){calc_total()};
  cell4.appendChild(sel1);
  
  
  // column5 for rate textbox
  var cell5 = row.insertCell(4);
  cell5.className = 'col_day';
  cell5.align = 'center';
  var tx1 = document.createElement('input');
  tx1.className = 'shopping_cart_textbox1';
  tx1.type = 'text';
  tx1.name = 'Row' + iteration + '_rate';
  tx1.id = 'Row' + iteration + '_rate';
  tx1.setAttribute('disabled', true);
  cell5.appendChild(tx1);
  
  // column6 for total textbox
  var cell6 = row.insertCell(5);
  cell6.className = 'col_day';
  cell6.align = 'center';
  var tx2 = document.createElement('input');
  tx2.className = 'shopping_cart_textbox1';
  tx2.type = 'text';
  tx2.name = 'Row' + iteration + '_total';
  tx2.id = 'Row' + iteration + '_total';
  tx2.setAttribute('disabled', true);
  cell6.appendChild(tx2);
  
  
  total_rows++;
}

function adddatatorow(id,item_name,item_color,item_size,thumb,qty,rate)
{
    
    addRowToTable();
    
    document.getElementById('Row' + total_rows  +'_qty').value = qty;
    document.getElementById('Row' + total_rows +'_rate').value = rate;
    document.getElementById('Row' + total_rows +'_id').value = id;
    document.getElementById('Row' + total_rows +'_srno').innerHTML = total_rows;
    document.getElementById('Row' + total_rows +'_itemdesc').innerHTML = item_name + '<br />Color: ' + item_color + '<br />Size: ' + item_size;
    if(thumb != '#')
    {
        document.getElementById('Row' + total_rows +'_IMG').setAttribute('src',thumb);
    }
    calc_total();
    document.getElementById('ischanged').value = 'no';
}

function set_paypal_params(total,value1)
{
    document.getElementById('amount_1').value = total;
    document.getElementById('item_name_1').value = value1;
}

function paypal_submit()
{
    document.forms["form_paypal"].submit();
}
