function submitPage(formName,actionUrl)
{
	var f = document.getElementById(formName);
	f.action = actionUrl;
	f.submit();
}
function doShowCalendar(textinput)
{
		var it=document.getElementById("e"+textinput);
		if(it == null)
		  it=document.getElementById("ee"+textinput);
		 if(it == null)
		 	it= document.getElementById(textinput);
		showCalendarControl(it);
}

function personType(typeP)
{
	if(typeP == "1")
	{		
		document.getElementById("dvConv").style.display="none";
		//document.getElementById("dvConv").style.lineHeight="0px";
		document.getElementById("dvConv").style.visibility="hidden";	
		document.getElementById("dvNat").style.display="block";
	}
	else
	{
		document.getElementById("dvConv").style.display="block";
		document.getElementById("dvConv").style.visibility="visible";
		document.getElementById("dvNat").style.display="none";		
	}
}

function scoreSystem(cb)
{
	if(cb.checked)
	{
		document.getElementById("dvShop").style.display="block";
	}
	else
	{
		document.getElementById("dvShop").style.display="none";
	}	
}


function confCategory(cb)
{
	
	if(cb.checked)
	{
		document.getElementById("dvConf").style.display="block";
	}
	else
	{
		document.getElementById("dvConf").style.display="none";
	}
}
countItem =1;
countImage =1;
countProducts = 1;
countQuestion = 1;
countAnswer = 1;

function addItem(score_cat)
{
	var divParent =document.getElementById("div_parent");
	var newDivId="div_sub"+countItem;
	var newDiv=document.createElement(newDivId);
	newDiv.setAttribute("id",newDivId);
	newDiv.style.cssText = "width:460px; float:left ; padding-bottom:5px;";
	newDiv.innerHTML ="<table width='330' style='border-bottom:solid 1px gray'>"+
							"<tr>"+
								"<td width='70'>Category</td>"+
								"<td><select id='cat"+countItem+"' name='cat[]'>"+score_cat+"</select></td>"+
							"</tr>"+
							"<tr>"+
								"<td>Value</td>"+
								"<td><input type='text' id='v"+countItem+"' name='value[]'  class='addInput1'/></td>"+
							"</tr>"+
							"<tr>"+
								"<td>Expire date</td>"+
								"<td><input type='text' id='e"+countItem+"' name='exp[]'  class='addInput1'/>&nbsp;"+
									 "<a href='javascript:doShowCalendar("+countItem+");' ><img src='../img/admin/btn_calendar.jpg' alt='' /></a>"+
								"</td>"+
							"</tr>"+	
							"<tr>"+
								"<td colspan='2' align='right'>"+
									"<a href='javascript:removeItem("+countItem+");' >Remove</a>"+
								"</td>"+
							"</tr>"+	
						"</table>";							
	
	document.getElementById("countSub").value = countItem;
	countItem++;	
	divParent.appendChild(newDiv);	
	
}
fileNo=1;
function addImage()
{
	if(fileNo >3)
	{
		var lk =document.getElementById("addFile");
		lk.href = "#";
		lk.style.color = "#ff0000";
		lk.innerHTML = "Maximum number of files has been exceeded";
	}
	else
	{
		var divParent =document.getElementById("divparent");
		var newDivId="div_sub"+countImage;
		var newDiv=document.createElement(newDivId);
		newDiv.setAttribute("id",newDivId);
		newDiv.style.cssText = "width:460px; float:left ; padding-bottom:5px;";
		newDiv.innerHTML ="<table width='450' style='border-bottom:solid 1px gray'>"+
								"<tr>"+
									"<td width='80'>File</td>"+
									"<td><input type='file' id='f_"+countImage+"' name='photo[]' class='addInput'/></td>"+
								"</tr>"+
								"<tr>"+
									"<td>Tile en</td>"+
									"<td><input type='text' id='te"+countImage+"' name='ten[]'  class='addInput'/></td>"+
								"</tr>"+
								"<tr>"+
									"<td>Title ro</td>"+
									"<td><input type='text' id='tr"+countImage+"' name='tro[]'  class='addInput'/>&nbsp;"+									
									"</td>"+
								"</tr>"+	
								"<tr>"+
									"<td>Title de</td>"+
									"<td><input type='text' id='td"+countImage+"' name='tde[]'  class='addInput'/>&nbsp;"+									
									"</td>"+
								"</tr>"+
								"<tr>"+
									"<td  valign='top'>Description en</td>"+
									"<td><textarea name='den[]' id='de"+countImage+"' rows='3' cols='51'></textarea>"+																
									"</td>"+
								"</tr>"+	
								"<tr>"+
									"<td  valign='top'>Description ro</td>"+
									"<td><textarea name='dro[]' id='dr"+countImage+"' rows='3' cols='51'></textarea>"+																
									"</td>"+
								"</tr>"+
								"<tr>"+
									"<td  valign='top'>Description de</td>"+
									"<td><textarea name='dde[]' id='dd"+countImage+"' rows='3' cols='51'></textarea>"+																
									"</td>"+
								"</tr>"+
								"<tr>"+
									"<td colspan='2' align='right'>"+
										"<a href='javascript:removeFile("+countImage+");' >Remove</a>"+
									"</td>"+
								"</tr>"+	
							"</table>";			
		
		countImage++;	
		fileNo++;
		divParent.appendChild(newDiv);	
	}
}
linkNo=1;
function addLink()
{
	if(linkNo >3)
	{
		var lk =document.getElementById("addLink");
		lk.href = "#";
		lk.style.color = "#ff0000";
		lk.innerHTML = "Maximum number of links has been exceeded";
	}
	else
	{
		var divParent =document.getElementById("divparent");
		var newDivId="div_sub"+countItem;
		var newDiv=document.createElement(newDivId);
		newDiv.setAttribute("id",newDivId);
		newDiv.style.cssText = "width:460px; float:left ; padding-bottom:5px;";
		newDiv.innerHTML ="<table width='450' style='border-bottom:solid 1px gray'>"+							
								"<tr>"+
									"<td width='80'>Link</td>"+
									"<td><input type='text' id='link"+countItem+"' name='link[]'  class='addInput'/></td>"+
								"</tr>"+
								"<tr>"+
									"<td>Tile en</td>"+
									"<td><input type='text' id='te"+countItem+"' name='len[]'  class='addInput'/></td>"+
								"</tr>"+
								"<tr>"+
									"<td>Title ro</td>"+
									"<td><input type='text' id='tr"+countItem+"' name='lro[]'  class='addInput'/>&nbsp;"+									
									"</td>"+
								"</tr>"+	
								"<tr>"+
									"<td>Title de</td>"+
									"<td><input type='text' id='td"+countItem+"' name='lde[]'  class='addInput'/>&nbsp;"+									
									"</td>"+
								"</tr>"+							
								"<tr>"+
									"<td colspan='2' align='right'>"+
										"<a href='javascript:removeLink("+countItem+");' >Remove</a>"+
									"</td>"+
								"</tr>"+	
							"</table>";			
		countItem++;	
		linkNo++;
		divParent.appendChild(newDiv);	
	}
}

function addProduct(products)
{
	var divParent =document.getElementById("divparent");
	var newDivId="div_sub"+countProducts;
	var newDiv=document.createElement(newDivId);
	newDiv.setAttribute("id",newDivId);
	newDiv.style.cssText = "width:460px; float:left ; padding-bottom:5px;";
	newDiv.innerHTML ="<table width='330' style='border-bottom:solid 1px gray'>"+
							"<tr>"+
								"<td width='70'>Product</td>"+
								"<td><select name='prod[]' id='pro"+countProducts+"'>"+products+"</select></td>"+
							"</tr>"+
							"<tr>"+
								"<td>Quantity</td>"+
								"<td><input type='text' id='q"+countProducts+"' name='qp[]'  style='width:50px'/></td>"+
							"</tr>"+
							
							"<tr>"+
								"<td colspan='2' align='right'>"+
									"<a href='javascript:removeItem("+countProducts+");' >Remove</a>"+
								"</td>"+
							"</tr>"+	
						"</table>";							
	
	document.getElementById("countSub").value = countProducts;
	countProducts++;	
	divParent.appendChild(newDiv);	
}
function removeFile(idItem)
{
	fileNo--;
	if(fileNo <= 3)
	{
		var lk =document.getElementById("addFile");
		lk.href = "javascript:addImage()";
		lk.style.color = "#0000ff";
		lk.innerHTML = "Add file";
	}
	removeItem(idItem);
}
function removeLink(idItem)
{
	linkNo--;
	if(linkNo <= 3)
	{
		var lk =document.getElementById("addLink");
		lk.href = "javascript:addLink()";
		lk.style.color = "#0000ff";
		lk.innerHTML = "Add link";
	}
	removeItem(idItem);
}
function removeItem(idItem)
{
	var divParent = document.getElementById("divparent");
	if(divParent == null)
		divParent = document.getElementById("div_parent");
	
	var divItem=document.getElementById('div_sub'+idItem);	
	divParent.removeChild(divItem);
}
function removeItem1(idItem)
{
	//var divParent = document.getElementById("divparent");
	//if(divParent == null)
	var	divParent = document.getElementById("div_parent");
	
	var divItem=document.getElementById('div_sub'+idItem);	
	divParent.removeChild(divItem);
	
}
function removeAnswer(idParent,idItem)
{
	var divParent = document.getElementById("q"+idParent);
	
	var divItem=document.getElementById('div_a'+idItem);	
	divParent.removeChild(divItem);
}

function removeExistingAnswer(idParent,idItem,idElem)
{
	var divParent = document.getElementById("q"+idParent);
	
	var divItem=document.getElementById('div_a'+idItem);	
	divParent.removeChild(divItem);
	
	var deleteAnswer = document.getElementById("delA");
	deleteAnswer.value += idElem+",";
	var existingSub = document.getElementById("eAns");
	
	var indexSub = existingSub.value.indexOf(idElem);
	existingSub.value = existingSub.value.replace(idElem+",","");
}
function removeExistingItem(idSub,idElem)
{
	var divParent = document.getElementById("divparent");	
	if(divParent == null)
		divParent = document.getElementById("div_parent");
	var divItem = document.getElementById('div_sub'+idSub);
	
	divParent.removeChild(divItem);
	
	var deletedSubTheme = document.getElementById("delSub");
	deletedSubTheme.value += idElem+",";
	var existingSub = document.getElementById("eSub");
	
	var indexSub = existingSub.value.indexOf(idElem);
	existingSub.value = existingSub.value.replace(idElem+",","");
	
}
function removeExistingItem1(idSub,idElem)
{
	//var divParent = document.getElementById("divparent");	
	//if(divParent == null)
	var	divParent = document.getElementById("div_parent");
	var divItem = document.getElementById('div_sub'+idSub);
	
	divParent.removeChild(divItem);
	
	var deletedSubTheme = document.getElementById("delSub");
	deletedSubTheme.value += idElem+",";
	var existingSub = document.getElementById("eSub");
	
	var indexSub = existingSub.value.indexOf(idElem);
	existingSub.value = existingSub.value.replace(idElem+",","");
	
}
function ch_lg(language,method)
{
	
	if( method != "")
	{
		document.changeC.lang.value = language;
		document.changeC.submit();
	}
}
var  countOpt= 0;
function addQuestion(itemName,subItem)
{
	var divParent =document.getElementById("div_parent");
	var newDivId="div_sub"+countQuestion;
	var newDiv=document.createElement(newDivId);
	newDiv.setAttribute("id",newDivId);
	newDiv.style.cssText = "width:460px; float:left ; padding-bottom:5px;";
	var innerText ="<table width='450' style='border:solid 1px gray'>"+
							"<tr>"+
								"<td colspan='2' align='right'>"+
									"<a href='javascript:removeItem1("+countQuestion+");' >Remove "+itemName+"</a>"+
								"</td>"+
							"</tr>"	
							"<tr>";
		if(itemName == "Option")
		{			
				innerText +="<tr>"+
								"<td></td>"+
								"<td  align='left'>"+
									"<input type='radio' name='single"+countOpt+"[]'  value='0' checked='checked'/>Multiple choice"+
									"<input type='radio' name='single"+countOpt+"[]' value='1' />Single choice"+
								"</td>"+
							"</tr>";
		}
		countOpt++;
		innerText	+=		"<td>Tile en</td>"+
								"<td><input type='text' id='te"+countQuestion+"' name='ten[]'  class='addInput'/></td>"+
							"</tr>"+
							"<tr>"+
								"<td>Title ro</td>"+
								"<td><input type='text' id='tr"+countQuestion+"' name='tro[]'  class='addInput'/>&nbsp;"+									
								"</td>"+
							"</tr>"+	
							"<tr>"+
								"<td>Title de</td>"+
								"<td><input type='text' id='td"+countQuestion+"' name='tde[]'  class='addInput'/>&nbsp;"+									
								"</td>"+
							"</tr>"+
							"<tr>"+
								"<td  valign='top'>&nbsp;</td>"+
								"<td>"+
									"<div style='width:400px; float:left;'>"+
										"<div style='width:400px; float:left;' id='q"+countQuestion+"'></div>"+
										"<div style='width:400px; float:left;'>"+
											"<a href='javascript:addAnswer("+countQuestion+",\""+subItem+"\");'>Add "+subItem+"</a>"+
										"</div>"+
									"</div>"+
								"</td>"+
							"</tr>"+	
							
							
						"</table>";	
	newDiv.innerHTML = innerText;					
	document.getElementById("noquestion").value =document.getElementById("noquestion").value *1 +1;
	document.getElementById("allquestion").value = countQuestion;
	
	countQuestion++;	
	divParent.appendChild(newDiv);	
	
}

function addAnswer(idQuestion,itemName)
{
	var divParent =document.getElementById("q"+idQuestion);
	var newDivId="div_a"+countAnswer;
	var newDiv=document.createElement(newDivId);
	newDiv.setAttribute("id",newDivId);
	newDiv.style.cssText = "width:400px; float:left ; padding-bottom:5px;";
	var innerText ="<table width='390' style='border-bottom:solid 1px gray'>"+
							
							"<tr>"+
								"<td>Tile en</td>"+
								"<td><input type='text' id='ae"+countAnswer+"_"+idQuestion+"' name='aen_"+idQuestion+"[]'  class='addInput'/></td>"+
							"</tr>"+
							"<tr>"+
								"<td>Title ro</td>"+
								"<td><input type='text' id='ar"+countAnswer+"_"+idQuestion+"' name='aro_"+idQuestion+"[]'  class='addInput'/>"+									
								"</td>"+
							"</tr>"+	
							"<tr>"+
								"<td>Title de</td>"+
								"<td><input type='text' id='ad"+countAnswer+"_"+idQuestion+"' name='ade_"+idQuestion+"[]'  class='addInput'/>"+									
								"</td>"+
							"</tr>";
		
		if(itemName == "Attribute")					
	    {
			innerText += "<tr>"+
								"<td>Value</td>"+
								"<td><input type='checkbox' id='cb"+countAnswer+"_"+idQuestion+"' name='cb_"+idQuestion+"[]'  value='1'/>"+									
								"</td>"+
							"</tr>";
		}
		innerText +=	"<tr>"+
								"<td colspan='2' align='right'>"+
									"<a href='javascript:removeAnswer("+idQuestion+","+countAnswer+");' >Remove "+itemName+"</a>"+
								"</td>"+
							"</tr>"+	
						"</table>";			
	newDiv.innerHTML = innerText;
	countAnswer++;	
	divParent.appendChild(newDiv);
}
function dispCat(idCategory,level)
{
	var divC = document.getElementById("td"+idCategory);
	if(divC != null)
	{
		if(divC.style.display == "none")
		{
			divC.style.display="";
			divC.style.position="relative";
		}
		else
		{
			divC.style.display="none";
		divC.style.position="absolute";
		}

	}
}
function hideCat(idCategory,level)
{
	var divC = document.getElementById("td"+idCategory);
	if(divC != null)
	{
		divC.style.display="none";
		divC.style.position="absolute";

	}
}