/*
 * addrow.js - an example JavaScript program for adding a row of input fields
 * to an HTML form
 *
 * This program is placed into the public domain.
 *
 * The orginal author is Dwayne C. Litzenberger.
 *
 * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY
 * OF ANY KIND, NOT EVEN THE IMPLIED WARRANTY OF
 * MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE,
 * ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE
 * RESULTING FROM THE USE, MODIFICATION, OR
 * REDISTRIBUTION OF THIS SOFTWARE.
 *
 * Home page: http://www.dlitz.net/software/addrow/
 *
 * History:
 *  Version 2 - 2006-01-14  dlitz@dlitz.net
 *   - Add support for MSIE 6
 *   - Separate HTML and JavaScript into separate files
 *   - Tested on:
 *      + Konqueror 3.4.2
 *      + Microsoft Internet Explorer 5.00
 *      + Microsoft Internet Explorer 6.0
 *      + Mozilla Firefox 1.0.4 (via browsershots.org)
 *      + Mozilla Firefox 1.5
 *      + Opera 8.51
 *      + Safari 2.0 (via browsershots.org)
 *  Version 1
 *   - Initial release
 * 
 */

function addRow() {

	var val11=document.getElementById('checkrows1bed').value;

	totw=parseInt(val11)+1
	document.getElementById('checkrows1bed').value=totw;


    /* Declare variables */
    var elements, templateRow, rowCount, row, className, newRow, element;
    var i, s, t;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements = document.getElementsByTagName("tr");
    templateRow = null;
    rowCount = 0;
    for (i = 0; i < elements.length; i++) {
        row = elements.item(i);
        
        /* Get the "class" attribute of the row. */
        className = null;
        if (row.getAttribute)
            className = row.getAttribute('class')
        if (className == null && row.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className = row.attributes['class'];
            if (className && typeof(className) == 'object' && className.value) {
                // MSIE 6
                className = className.value;
            }
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className != "row_to_clone")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow = row;
        rowCount++;
    }
    if (templateRow == null)
        return false; /* Couldn't find a template row. */
    
    /* Make a copy of the template row */
    newRow = templateRow.cloneNode(true);

    /* Change the form variables e.g. price[x] -> price[rowCount] */
    elements = newRow.getElementsByTagName("input");
    for (i = 0; i < elements.length; i++) {
        element = elements.item(i);
        s = null;
        s = element.getAttribute("name");
        if (s == null)
            continue;/*
        t = s.split("[");
	alert(s)
        if (t.length < 2)
            continue;
        s = t[0] + "[" + rowCount.toString() + "]";*/
	//alert(s)
        element.setAttribute("name", s);
        element.value = "";
	element.id ="mandays_"+i;
    }
    
    /* Add the newly-created row to the table */
    templateRow.parentNode.appendChild(newRow);
    return true;
}

/* set ts=8 sw=4 sts=4 expandtab: */

function addRow11() {

	var val1=document.getElementById('checkrows1').value;

	tot=parseInt(val1)+1
	document.getElementById('checkrows1').value=tot;

    /* Declare variables */
    var elements1, templateRow1, rowCount1, row1, className1, newRow1, element1;
    var i1, s1, t1;
    
    /* Get and count all "tr" elements with class="row".    The last one will
     * be serve as a template. */
    if (!document.getElementsByTagName)
        return false; /* DOM not supported */
    elements1 = document.getElementsByTagName("tr");
    templateRow1 = null;
    rowCount1 = 0;
    for (i1 = 0; i1 < elements1.length; i1++) {
        row1 = elements1.item(i1);
        
        /* Get the "class" attribute of the row. */
        className1 = null;
        if (row1.getAttribute)
            className1 = row1.getAttribute('class')
        if (className1 == null && row1.attributes) {    // MSIE 5
            /* getAttribute('class') always returns null on MSIE 5, and
             * row.attributes doesn't work on Firefox 1.0.    Go figure. */
            className1 = row1.attributes['class'];
            if (className1 && typeof(className1) == 'object' && className1.value) {
                // MSIE 6
                className1 = className1.value;
            }
        } 
        
        /* This is not one of the rows we're looking for.    Move along. */
        if (className1 != "row_to_clone1")
            continue;
        
        /* This *is* a row we're looking for. */
        templateRow1 = row1;
        rowCount1++;
    }
    if (templateRow1 == null)
        return false; /* Couldn't find a template row. */
    
    /* Make a copy of the template row */
    newRow1 = templateRow1.cloneNode(true);

    /* Change the form variables e.g. price[x] -> price[rowCount] */
    elements1 = newRow1.getElementsByTagName("input");	
    for (i1 = 0; i1 < elements1.length; i1++) {
        element1 = elements1.item(i1);
        s1 = null;
        s1 = element1.getAttribute("name");
	//alert(s1);
        if (s1 == null)
            continue;
	//if(element1.getAttribute("type")=="checkbox"){
        	t1 = s1.split("[");
        	s1 = t1[0] +"["+t1[1]+"["+t1[2] + "[" + rowCount1.toString() + "]";
	//}
	/*var str=new String(s1);
	var rep="["+rowCount1.toString()+"]";
	var rep1="[0]";
	alert(str);
	str=str.replace(rep1,rep);
	alert(str);	*/
	//alert(s1);
        element1.setAttribute("name", s1);
	if(element1.getAttribute("type")=="checkbox"){
        	element1.value = "1";
		element1.checked = "";
	}
	element1.id ="mandays_"+i1;
    }
    
    /* Add the newly-created row to the table */
    templateRow1.parentNode.appendChild(newRow1);
    return true;
}
