url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
row_no=2; 

function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
			url = base_url + url;
	}

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
}

function getobject_main(obj){
	  if (document.getElementById)
		 return document.getElementById(obj)
	  else if (document.all)
		 return document.all[obj]
}

function submitQuestion() {
	var myfirstname = getobject_main("firstname").value;
	var mylastname = getobject_main("lastname").value;
	var myemail = getobject_main("email").value;
	var myphone = getobject_main("myphone").value;
	var mycompany = getobject_main("company").value;
	var myshipping1 = getobject_main("shipping1").value;
	var myshipping2 = getobject_main("shipping2").value;
	var myshipping3 = getobject_main("shipping3").value;
	var mycontact = getobject_main("mycontact").value;
	var mymanufacturer = getobject_main("manufacturer").value;
	var myproductname = getobject_main("prodname").value;
	var mycolor = getobject_main("color").value;
	var mydaterequired = getobject_main("daterequired").value;
	var myproject = getobject_main("project").value;
	var mybudget = getobject_main("budget").value;
	var mysize = getobject_main("size").value;
	var myrequirebudget = getobject_main("requirebudget").value;
	var myhavematerial = getobject_main("havematerial").value;
	var mycost = getobject_main("havematerial").value;
	var myhavematerial = getobject_main("havematerial").value;
	var mycomments = getobject_main("comments").value;
	
	var randomString = new Date().getTime();
	
	// var where_is_xanadu=myquestion.indexOf('Xanadu');
	// name company phone besttime email timeframe objective business

	if (myfirstname.length > 1 && myemail.length > 1 && myphone.length > 1 && myshipping1.length > 1 && myproductname.length > 1 && myproject.length > 1) {
		
		ajax_do('save_question.php?myfirstname=' + myfirstname + '&mylastname=' + mylastname + '&myemail=' + myemail + '&myphone=' + myphone + '&mycompany=' + mycompany + '&myshipping1=' + myshipping1 + '&myshipping2=' + myshipping2 + '&myshipping3=' + myshipping3 + '&mycontact=' + mycontact + '&mymanufacturer=' + mymanufacturer + '&myproductname=' + myproductname + '&mycolor=' + mycolor + '&mydaterequired=' + mydaterequired + '&myproject=' + myproject + '&mybudget=' + mybudget + '&mysize=' + mysize + '&myrequirebudget=' + myrequirebudget + '&myhavematerial=' + myhavematerial + '&mycomments=' + mycomments + '&m=' + randomString);
	
	} else {
		
		alert("Please fill in all of the fields in order to send a request for samples. Thank you.");
	
	}
	
}

function isEmailAddr(str) {
  return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}

function addRow(tbl,row){ 
   		var tbl = 'costtable';
		var row = 'myrow';
        
       var remove= '<a href="javascript:removeRow(' + row_no + ')"/><img src="images/remove.gif" width="14" border="0" height="14" /></a></div>'; 

        var tbl = document.getElementById(tbl);//to identify the table in which the row will get insert 
        var rowIndex = document.getElementById(row).value;//to identify the row after which the row will be inserted 
        try { 
            var newRow = tbl.insertRow(row_no);//creation of new row 
            var newCell = newRow.insertCell(0);//first  cell in the row 
            newCell.innerHTML = '<select name="manufacturer[]" id="manufacturer[]"><option value="Amtico International" selected="selected">Amtico International</option><option value="ECOsurfaces">ECOsurfaces</option><option value="Constantine">Constantine</option><option value="Templeton">Templeton</option></select>';//insertion of the 'text' variable in first cell 
            var newCell = newRow.insertCell(1);//second cell in the row 
            newCell.innerHTML = '<div align="left" class="style49"><input name="prodname[]"  type="text" id="prodname[]" size="25" />';//insertion of the text box and the remove text using their variable 
			var newCell = newRow.insertCell(2);//second cell in the row 
            newCell.innerHTML = '<div align="left" class="style49"><input name="color[]" type="text" id="color[]" size="40" />' + " " + remove;//insertion of the text box and the remove text using their variable 
            row_no++; 
        } catch (ex) { 
            alert(ex); //if exception occurs 
        } 
            
                          
} 
function removeRow(num) 
{ 
    var table = document.getElementById('costtable');//adentification of table 
   try { 

      if(num >= row_no){ 
        row_no--; 
      table.deleteRow(row_no);//deletion of the clicked row 
      }else{ 
        row_no--; 
        table.deleteRow(num);//deletion of the clicked row 
      } 

    } catch (ex) { 
        alert(ex); 
    } 


} 
