function generateFormHtml() {
	var out		= '';
	var count	= 30;
	var temp	= '';
	
	out = '<table align="center" cellspacing="0" cellpadding="0" border="0" class="w100 blankTable">'+						
		'<col width="50"><col width="50"><col width="50"><col width="50"><col width="50">'+
		'<tr><th colspan="5">ÁËÀÍÊ ÇÀÌÎÂËÅÍÍß</th></tr>'+
		'<tr>'+
			'<th>¹</th>'+
			'<th>Àðòèêóë, ¹</th>'+
			'<th>Ê³ëüê³ñòü óïàêîâîê</th>'+
			'<th>Ö³íà óïàêîâêè</th>'+
			'<th>Ñóìà, ãðí.</th>'+
		'</tr>';
		
	for(i = 0; i < 30; i++) {
		temp += '<tr><td class="aC"><input readonly type="text" value="'+ (i+1) + '" name="special['+ (i+1) + '][number]"></td>';
		temp += '<td class="aC"><input type="text" name="special['+ (i+1) + '][article]"></td>';
		temp += '<td class="aC"><input type="text" name="special['+ (i+1) + '][count]"></td>';
		temp += '<td class="aC"><input type="text" name="special['+ (i+1) + '][price]"></td>';
		temp += '<td class="aC"><input readonly type="text" name="special['+ (i+1) + '][sum]"></td></tr>';
	}
	
	temp += '<tr><td colspan="4" class="aR">ÐÀÇÎÌ:</td><td colspan="1" class="aC"><input readonly type="text" name="special[total]"></td></tr>';
	out += temp + '</table>';
	
	return out;
}


//interflora-form1-blank
function assignForm(pId) {
	var obj;
	if( !(obj = document.getElementById(pId)) )
		return;
	
	obj.innerHTML = generateFormHtml();
}

function addHandlers(pId) {
	if( !(obj = document.getElementById(pId)) )
		return;

	for(i = 1; i <= 30; i++) {				
		var handle = function(i) {
			//alert("ok"+i);
			return function() {							
				 a = (parseFloat( obj['special['+i+'][price]'].value.replace(",", ".") ) * parseInt( obj['special['+i+'][count]'].value ) );
				 obj['special['+i+'][sum]'].value = (a) ? a.toFixed(2) : 0;
				
				getTotal(pId);
				//obj['special[totlal]'] = "2";
			}
		}
		
		addEvent(obj['special['+i+'][price]'], "keyup", handle(i), false);
		addEvent(obj['special['+i+'][count]'], "keyup", handle(i), false);		
	}
}

function getTotal(pId) {
	if( !(obj = document.getElementById(pId)) )
		return;
		
	total = 0;
	for(i = 1; i <= 30; i++) {
		if(obj['special['+i+'][sum]'].value > 0) {
			total += parseFloat(obj['special['+i+'][sum]'].value);
		}
	}
	a = total || 0;
	obj['special[total]'].value = (a) ? a.toFixed(2) : 0;
}

function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }
    else {
        elm['on' + evType] = fn;
    }
}


//********************************//
// Cancel submit on "Enter" press //
//********************************//
function cancelSubmitOnEnterPress() {
	var allForms = document.forms;
	//var formsCnt = allForms.length;
	var i = 0;
	
	while(allForms[i]) {
		allForms[i].onsubmit = function(evt) {
			if(evt.keyCode == 13) {
				return false;
			}
		}
		i++;
	}
}

addEvent(document, 'load', cancelSubmitOnEnterPress, true);