function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  	window.open(theURL,winName,features);
}

function isDefined( variable)
{
    	return (typeof(window[variable]) == "undefined")?  false: true;
}

function strRepeat(cnt)
{
	var retStr = "";
	for(i=0;i<cnt;i++)
		retStr=retStr+",";	
	return retStr;
}

function validateForm(myForm,cArray,cnt)
{
	var i=0;
	var values = "theControl,theMessage,theNumeric,theEmail,theURL,theConfirmPassword,thebadstuff,theinteger,thepercent,thesize,thedecimal,theimage,theempty,themin,themax,thecheckboxlength,thephoneno";
	var leftSide = new Array();
	var rightVals = new Array();
	leftSide = values.split(",");

	var strRepeats = strRepeat(cnt-1);

	for(i=0;i<leftSide.length;i++){
		if(cArray[leftSide[i]]){
			rightVals[i] = (cArray[leftSide[i]]);
		}else{
			rightVals[i] = strRepeats;
		}
		leftSide[i]=rightVals[i];
	}
	
	if(!theValidator(myForm,leftSide[0],leftSide[1],leftSide[2],leftSide[3],leftSide[4],leftSide[5],leftSide[6],leftSide[7],leftSide[8],leftSide[9],leftSide[10],leftSide[11],leftSide[12],leftSide[13],leftSide[14],leftSide[15],leftSide[16]))
		return false;		
		
	return true;
}

function addRowToTable(theForm)
{
	var tbl = document.getElementById('tblDynamic');
	var lastRow = tbl.rows.length;		
	if(lastRow<=5)
	{	
		theForm.tempCounter.value = parseInt(theForm.tempCounter.value)+1;
		var td0 = theForm.mm.value + '/' + theForm.dd.value + '/' + theForm.yy.value ;
		var dob= theForm.yy.value + '-' + theForm.mm.value + '-' + theForm.dd.value ;
			
		if(theForm.enumGender[0].checked)	{	var td1 = 'Boy';	}
		else							{	var td1 = 'Girl';	}
	
		var td2 = document.createElement('img');
		td2.setAttribute('src', 'images/delete-new.gif');
		td2.setAttribute('title', 'Delete');
		td2.setAttribute('alt', 'Delete');
		td2.setAttribute('border', '0');
		td2.setAttribute('onclick', 'delRowTable('+theForm.tempCounter.value+');');
		
		var hidChild = document.createElement('input');
		hidChild.setAttribute('type', 'hidden');
		hidChild.setAttribute('name', 'child[]');		
		if(td1 == 'Boy')			hidChild.setAttribute('value', 'B' + ',' + dob);
		else					hidChild.setAttribute('value', 'G' + ',' + dob);
		
		var row = tbl.insertRow(lastRow);
		row.setAttribute('id', 'child-' + theForm.tempCounter.value);
		
		var cell0 = row.insertCell(0);
		var textNode0 = document.createTextNode(td0);
		cell0.appendChild(textNode0);
		cell0.appendChild(hidChild);

		var cell1 = row.insertCell(1);
		var textNode1 = document.createTextNode(td1);
		cell1.appendChild(textNode1);

		var cell2 = row.insertCell(2);	
		cell2.appendChild(td2);	
	}
	else
		alert('Maximum limit is 5.');
}

function delRowTable(num)
{
	var tbl = document.getElementById('tblDynamic');
	var ind=document.getElementById('child-'+num).rowIndex;	
	tbl.deleteRow(ind);
}

function addRowToTable_associate(theForm)
{
	var tbl = document.getElementById('tblDynamic');
	var lastRow = tbl.rows.length;		
	
	theForm.tempCounter.value = parseInt(theForm.tempCounter.value)+1;
	if(theForm.cat_level3.value != "")
	{
		var x=theForm.cat_level3;
		var cat_id= theForm.cat_level3.value ;		
	}
	else if(theForm.cat_level2.value != "")
	{
		if(theForm.cat_level3.length >1)
		{
			alert('Please select Sub-sub Category.');
			return false;
		}
		var x=theForm.cat_level2;
		var cat_id= theForm.cat_level2.value;
	}
	else
	{
		if(theForm.cat_level2.length >1)
		{
			alert('Please select Sub-Category.');
			return false;
		}

		var x=theForm.vchCategoryName;
		var cat_id= theForm.vchCategoryName.value ;
	}
	
	var cat_name= x.options[x.selectedIndex].text ;
	var td0= '' + cat_name;
	
	var td1 = document.createElement('img');
	td1.setAttribute('src', 'images/delete-new.gif');
	td1.setAttribute('title', 'Delete');
	td1.setAttribute('alt', 'Delete');
	td1.setAttribute('border', '0');
	td1.setAttribute('onclick', 'delRowTable_associate('+theForm.tempCounter.value+');');
		
	var hidCat = document.createElement('input');
	hidCat.setAttribute('type', 'hidden');
	hidCat.setAttribute('name', 'cats[]');		
	hidCat.setAttribute('value', cat_id);		
	
	var row = tbl.insertRow(lastRow);
	row.setAttribute('id', 'cat-' + theForm.tempCounter.value);
		
	var cell0 = row.insertCell(0);
	var textNode0 = document.createTextNode(td0);
	cell0.style.padding='5px';
	cell0.style.width='232';	
	//cell0.class='itemdetail-lightgray';
	cell0.valign='middle';	
	cell0.appendChild(textNode0);
	cell0.appendChild(hidCat);

	var cell1 = row.insertCell(1);		
	//cell1.class='itemdetail-lightgray';
	cell1.style.width='25';
	cell1.valign='middle';	
	cell1.style.padding='5px';
	cell1.appendChild(td1);		
}

function delRowTable_associate(num)
{
	var tbl = document.getElementById('tblDynamic');
	var ind=document.getElementById('cat-'+num).rowIndex;	
	tbl.deleteRow(ind);
}
