function addEvent(parent_div,child_div) {
	//alert("addEvent"+parent_div+","+child_div);
	var ni = document.getElementById(parent_div);
	var numi = document.getElementById("id_field_no");
	var num = do_convert(get_field_value("id_field_no"),"int") + 1;
	numi.value = num;
	var divIdName = child_div;
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	var inner_div ="";
	    inner_div += "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n";
	    inner_div += "<tr><td>\n";
		inner_div += "<span>Link Name:</span> ";
		inner_div += "</td><td><input type=\"text\" name=\"txt_link_name"+num+"\" id=\"id_link_name"+num+"\" value=\"\" maxlength=\"250\"></td>";
		inner_div += "<td><a href=\"javascript:;\" onclick=\"removeEvent('id_RC','"+divIdName+"');\" title=\"Delete\">[X]</a></td>";
		inner_div += "</tr><tr><td><span>Link Address:</td>\n";
		inner_div += "</td><td colspan=\"2\"><input type=\"text\" name=\"txt_link_address"+num+"\" id=\"id_link_address"+num+"\" value=\"\" maxlength=\"1000\"></span><br></td>";
		inner_div += "</tr>\n";
		inner_div += "</table>\n";
		inner_div +=" <input type=\"hidden\" name=\"hid_link_id\" id=\"id_link_id\" value=\"\">\n";
		set_field_value("id_field_no",num);
	newdiv.innerHTML = inner_div;
	ni.appendChild(newdiv);
}

function addMoreform() {
	var child_count =do_convert(get_field_value("id_child_div_count"),"int");
	
	child_count  =  child_count+1;
	var child_id = "id_child"+child_count+"_div";
	var sub_child_id = "id_sub_child"+child_count+"_div";
	var id_state_option = "id_state"+child_count;
	var id_country_option = "id_country"+child_count;
	//alert("child_id: "+child_id +" sub_child_id:"+sub_child_id );
	add_child("id_parent_div",sub_child_id);
	add_child("id_parent_div",child_id);
	//alert("child div added");
	html = make_html("ex_suite",child_count);
	inner_html(child_id,html);
	var ifrm  = document.getElementById('fid'+child_count);
	var iffrm  = document.getElementById('ffid'+child_count);
	ifrm.src = 'exsuite_upload.php?building_logo=yes&formcount='+child_count;
	iffrm.src = 'exsuite_upload.php?building_image=yes&formcount='+child_count;
	html = make_html("hide_and_seek",child_count);
	inner_html(sub_child_id,html);
	set_field_value("id_child_div_count",child_count);
	state_option_list(id_state_option);
	country_option_list(id_country_option);
}


function add_child(parent_div,chid_divId) {
		var ni = document.getElementById(parent_div);
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id",chid_divId);
		newdiv.setAttribute("style","display:block");
		ni.appendChild(newdiv);
}

function removeEvent(parent_div,child_div) {
	var message = "Are you sure?\nYou want to remove this field set!";
	if (get_confirm(message)){
		var div_to_remove = child_div;
		var d = document.getElementById(parent_div);
		var olddiv = document.getElementById(div_to_remove);
		d.removeChild(olddiv);
	}
}

function remove_allchild(parent_div) {
	var d = document.getElementById(parent_div);
	while(d.firstChild) d.removeChild(d.firstChild);
}

function remove_child(parent_div,child_div){
//alert(parent_div+'vv'+child_div)
		var div_to_remove = child_div;
		var d = document.getElementById(parent_div);
		var olddiv = document.getElementById(div_to_remove);
		d.removeChild(olddiv);
}

function addMorefields() {
	//alert("addMorefields");
	var child_div_count = do_convert(get_field_value('id_field_no'),"int");
	var child_div = "id_secItem"+child_div_count;
	addEvent("id_RC",child_div);
}

function show_element(element_id) {
	document.getElementById(element_id).style.display = "block";
}

function hide_element(element_id) {
  //alert(element_id);
	document.getElementById(element_id).style.display = "none";
}

function inner_html(element_id,html) {
	//alert('sss '+ element_id +' html : '+ html);
	document.getElementById(element_id).innerHTML = html;
}

function close_popup (div_id, field_id) {
     hide_element(div_id);
     if (field_id) {
          set_field_value(field_id);
          do_focus(field_id);
     }
}

function hide_me(div_count) {
	var hide_div_id = "id_child"+div_count+"_div";
	var hide_id = "id_hideme"+div_count;
	var show_id = "id_showme"+div_count;
	hide_element(hide_div_id);
	hide_element(hide_id);
	show_element(show_id);
}

function show_me(div_count) {
	var hide_div_id = "id_child"+div_count+"_div";
	var show_id = "id_hideme"+div_count;
	var hide_id = "id_showme"+div_count;
	show_element(hide_div_id);
	hide_element(hide_id);
	show_element(show_id);
}

function delete_me(div_count) {
	var remove_child_div = "id_child"+div_count+"_div";
	var remove_text = "id_removeme"+div_count;
	var hide_id = "id_hideme"+div_count;
	var show_id = "id_showme"+div_count;
	var message = "Are you sure?\nYou want to remove this Form!";
	if (get_confirm(message))
	{
	
		remove_child("id_parent_div",remove_child_div);
		hide_element(hide_id);
		hide_element(show_id);
		inner_html(remove_text,"[Removed]");
		var id_removed = "id_removed"+div_count;
		set_field_value(id_removed,'removed');
		hide_element(hide_id);
	}
}
