function BookmarkLink(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
function CreateBookmarkLink(title,url,text){
		document.write('<a href = "javascript:BookmarkLink(\''+title+'\',\''+url+'\')");" style="text-decoration: none"><img border=0 src="images/star.gif" style="display:inline; width:10px; height:10px">&nbsp;'+text+'</a>'); 
}

function CreateHomePage(url,text){
		document.write('<a href = "javascript: void(0);" onClick="this.style.behavior=\'url(#default#homepage)\'; this.setHomePage(\''+url+'\');" style="text-decoration: none"><img border=0 src="images/homepage.gif" style="display:inline; width:10px; height:10px">&nbsp;'+text+'</a>'); 
}

function checkEmail()
{
	var arg = arg;
	var x = document.enovice.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) 
	{
		return true;
	}
	else
	{
		alert('Vnesli ste napacen email naslov! Prosimo vnesite pravilnega.');
		return false;
	}	
}

function checkRadio(forma,radio)
{
	var form = forma;
	var rad = radion;
	if(NoneWithCheck(document.form.rad))
	{
		alert('Najprej oznacite enega od odgovorov!');
		return false;
	}
	
	function NoneWithCheck(ss) {
		for(var i = 0; i < ss.length; i++) {
			if(ss[i].checked) { return false; }
		}
		return true;
	}
}
function checkTxtField()
{
	if(WithoutContent(document.onlineorder.st_izvodov_1.value) && WithoutContent(document.onlineorder.st_izvodov_2.value) && WithoutContent(document.onlineorder.st_izvodov_3.value) && WithoutContent(document.onlineorder.st_izvodov_4.value))
	{
		alert('Vnesite narocilo in izpolnite polja z osebnimi podatki, ki so oznacena z zvezdico!');
		return true;
	}
	
	function WithoutContent(ss)
	{
		if(ss.length > 0) { return false; }
		else { return true; }
	}
}

function ResetForm(id_form)
{

 var first=-1
  for (i=0;i<id_form.length;i++){
    var obj = id_form.elements[i]
    if (obj.type=="text") {
      eval(obj.value="")
      if (first==-1) {first=i}
    }
  }
  id_form.elements[first].focus()
  return true
}

function addValue(cId,cValue)
{
	document.getElementById(cId).value = cValue;
}

function addMValues(aId,aValue)
{
	var n = aId.length;
	for (i=0; i<n; i++)
	{
		cid = aId[i];
		document.getElementById(cid).value = aValue[i];
	}
}

function checkPoll(cSex)
{
	nAnsValue = -1;
	nCount = document.getElementById('anketa').ans.length;
	
	for (i=0;i<nCount;i++) {
		oAns = document.getElementById('anketa').ans[i];
		
		if (oAns.checked == true) {
			nAnsValue = oAns.value;
			break;
		}
	}

	if (nAnsValue > 0) {
		document.getElementById('sex').value = cSex;
		document.getElementById('anketa').submit();
	} else {
		alert('Pozabili ste izbrati odgovor.');
	}
}

function checkForShow()
{
	if(document.onlineorder.poseba[0].checked==true)
	{
		Show('yes','div_poseba');
	}
	if(document.onlineorder.dostava[0].checked==true)
	{
		Show('yes','div_dostava');
	}
}

function Show(i_name,id_name) 
{
	//alert(i_name);
	document.getElementById(id_name).style.display='none';
	if (i_name=='yes') 
	{
		document.getElementById(id_name).style.display='block';
	}
}


function Display(e_id,e_display)
{
    document.getElementById(e_id).style.display='none';
    if (e_display=='show') {
        document.getElementById(e_id).style.display='block';
    }
}

function quantityCart(item,itemvalue,formid)
{
	if (document.getElementById(item).value != itemvalue) {
		document.getElementById(formid).submit();
	} else {
		return false;
	}
}

function formSubmit(e_id)
{
    document.getElementById(e_id).submit();
	//alert(document.getElementById(e_id));
}

function ShowSignup(checkbox_id,display_id)
{
	document.getElementById(display_id).style.display = "";		
	if(	document.getElementById(checkbox_id).checked)
	{
		document.getElementById(display_id).style.display = "";
	}
	else
	{
		document.getElementById(display_id).style.display = "none";

	}
}

function HideButton(checkbox_id,display_id)
{
	document.getElementById(display_id).style.display = "";		
	if(	document.getElementById(checkbox_id).checked )
	{
		document.getElementById(display_id).style.display = "none";
	}
	else
	{
		document.getElementById(display_id).style.display = "";

	}
}

function HideSignup(checkbox_id,display_id)
{
	document.getElementById(display_id).style.display = "";		
	if(	document.getElementById(checkbox_id).checked)
	{
		document.getElementById(display_id).style.display = "none";
	}
	else
	{
		document.getElementById(display_id).style.display = "";

	}
}

function ShowHide(e_id)
{
    if (document.getElementById(e_id).style.display = "none") {
        document.getElementById(e_id).style.display = "block";
    } else {
        document.getElementById(e_id).style.display = "none";
    }
}

<!--
/*
Plugin detection & banner display
*/

var plugin = 0;
var forcheck = false;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
        if (navigator.plugins && navigator.plugins["Shockwave Flash"])
			plugin = 1;
			
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
   && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)) {
        document.write('<script language="VBScript"\> \n');
        document.write('on error resume next \n');
        document.write('plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))\n');
        document.write('if ( plugin <= 0 ) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))\n');
        document.write('if ( plugin <= 0 ) then plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
		document.write('//plugin= 1;\n');
        document.write('</script\> \n');
}

function flashBannerStr(bannerName, bannerWidth, bannerHeight, bannerLink, bannerSRC) {
                var BannerLinkEncode;
                bannerLinkEncode = escape(bannerLink);
                s = new String();
                s = s + '<object id="flash'+bannerName+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
                s = s + ' codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" ';
                s = s + ' id="' + bannerName + '" width="' + bannerWidth + '" height="' + bannerHeight + '"\> \n';
				//s = s + '<param name="url" valuetype="ref" value="http://www.positiva.si/">'
                s = s + ' <param name="movie" value="' + bannerSRC +'?clickthru=' + bannerLinkEncode +'&clickTAG=' + bannerLinkEncode +'" /> \n';
                s = s + ' <param name="quality" value="high"/> \n';
                s = s + ' <embed src="' + bannerSRC +'?clickthru=' + bannerLinkEncode +'&clickTAG=' + bannerLinkEncode +'" quality="high" ';
                s = s + ' swLiveConnect="false" width="' + bannerWidth + '" height="' + bannerHeight + '" ';
                s = s + ' type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
                s = s + ' </embed> \n';
                s = s + ' </object>\n';
        return(s);
}

function flashBanner(bannerName,bannerSRC,bannerIMG, bannerWidth, bannerHeight, bannerLink, bannerTarget, ccenter, ctitle){
	//alert(ccenter);
	if ( plugin && bannerSRC!="") {
		document.write(flashBannerStr(bannerName, bannerWidth, bannerHeight, bannerLink, bannerSRC));

	}
	else if (!(navigator.appname && navigator.appname.indexOf("Netscape")>=0 && navigator.appVersion.indexOf("2.")>=0)){
		if (bannerTarget == false) {
			cTarget = "";
		} else {
			cTarget = 'onclick="this.target=\'_blank\'"';
		}
		
		if (bannerWidth > 0) {
			cWidth  = "width:" + bannerWidth + "px;";
		} else {
			cWidth = "";
		}

		if (bannerHeight > 0) {
			cHeight = "height:" + bannerHeight + "px;";
		} else {
			cHeight = "";
		}
		
		cStyle = "style=\"border:none;" + cWidth + cHeight + ccenter + "\"";
		if(bannerLink=='') document.write('<img src="' + bannerIMG + '" ' + cStyle + ' alt="'+ctitle+'" title="'+ctitle+'" />');
		else
			document.write('<a href="' + bannerLink + '" ' + cTarget + '><img src="' + bannerIMG + '" ' + cStyle + ' alt="'+ctitle+'" title="'+ctitle+'" /></a>');
	}

}


function openWindowPrint(cHtml,cWidth,cHeight)
{
	var scr= screen.availWidth;
	scr= (scr - 400)/2;
	openW=window.open(cHtml,"openW","'scrolling=no,menubar=yes,toolbar=0,scrollbars=0,resizable=1,left="+scr+",top=100,width="+cWidth+",height="+cHeight,true);

	return false;
}


function menudisplay(cUrl, bHover, cId)
{
	var scr = getElementById(cId);
	scr.style.color = 'blue';
}

function checkUncheckAll(cForm,lSelect) {
	var theForm = document.getElementById(cForm), z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox'){
			theForm[z].checked = lSelect;
		}
	}
}

/**
 *   @description : This function displays user signup form. Form is js driver in manner that no form submiting is required
 *   @param
 *    
 *   @return : returns html form       
 */ 
function showUserSignUpForm(){

}
/**
 *   @description   : Function displays html list of signed users. Each entry has button for deleting signed user and editing users data
 *   @param
 *   
 *   @returns       : Function return html list of all signed users.   
 */ 
function showSignedUserList(){

     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: "asum=3",
        success: function(html_code){
         
          //document.getElementById("user_signup_container").style.display = "none";
          $("#user_signup_container").children().remove();
          document.getElementById("signed_users_list").innerHTML = "<tr><td><div style='display:block;'>" + html_code + "</div></td></tr>";
          document.getElementById("signed_users_list").innerHTML += "<tr><td colspan='2'><div style='position:relative;float:right;' ><p onclick='javascript: showNewContactForm()' style='cursor:pointer;display:block;font-weight:bold;'>Dodaj kontakt</p></div></td></tr>";
          
        }
     });

}
/**
 *   @description   : Function adds user to the html list
 *   @param         : none
 *   
 *   @returns       : html code to append to html list container   
 */  
 
function addUserToTheList(){
     //alert("dodaj userja na html list");
     var id_title             = $("#id_title").val();
     var firstname            = $("#firstname").val();
     var lastname             = $("#lastname").val();
     var email                = $("#email").val();
     var workplace            = $("#workplace").val();
     var person_special_0     = $("#person_special_0:checked").length;
     var person_special       = $("#person_special").val();
     var maillist             = $("#maillist:checked").length;
 
         
     var i = 0;
     var url_string = "asum=1&id_title="+id_title+"&firstname="+firstname+"&lastname="+lastname+"&email="+email+"&workplace="+workplace+"&person_special_0="+person_special_0+"&maillist="+maillist+"action=insert&person_special="+person_special; 
     for(i; i < person_special; i++){
          if($("#person_special_"+i+":checked").length == 1)
               url_string += "&person_special_"+i+"=" + $("#person_special_"+i).val();
     }
     

     //--CO-- send ajax request   
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: url_string,
        success: function(html_code){
         
          //document.getElementById("user_signup_container").style.display = "none";
          $("#user_signup_container").children().remove();
          document.getElementById("signed_users_list").innerHTML = "<tr><td><div style='display:block;'>" + html_code + "</div></td></tr>";
          document.getElementById("signed_users_list").innerHTML += "<tr><td colspan='2'><div style='position:relative;float:right;' ><p onclick='javascript: showNewContactForm()' style='cursor:pointer;display:block;font-weight:bold;'>Dodaj kontakt</p></div></td></tr>";
          
        }
     });
}

/**
 *   @ descriptopn  : Function updates user data.
 *
 */  
function correctUserFromTheList(id_user){
     //alert("dodaj userja na html list");
     var id_title             = $("#id_title").val();
     var firstname            = $("#firstname").val();
     var lastname             = $("#lastname").val();
     var email                = $("#email").val();
     var workplace            = $("#workplace").val();
     var person_special_0     = $("#person_special_0:checked").length;
     var person_special       = $("#person_special").val();
     var maillist             = $("#maillist:checked").length;
     
     var i = 0;
     var url_string = "asum=1&id_title="+id_title+"&firstname="+firstname+"&lastname="+lastname+"&email="+email+"&workplace="+workplace+"&person_special_0="+person_special_0+"&maillist="+maillist+"&action=correct&id_person="+id_user+"&person_special="+person_special 
     for(i; i < person_special; i++){
          if($("#person_special_"+i+":checked").length == "1"){
               url_string += "&person_special_"+i+"=" + $("#person_special_"+i).val();
          }
     }
     

     //--CO-- send ajax request   
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: url_string,
        success: function(html_code){
         
          document.getElementById("user_signup_container").style.display = "none";
          document.getElementById("signed_users_list").innerHTML = "<tr><td><div style='display:block;'>" + html_code + "</div></td></tr>";
          document.getElementById("signed_users_list").innerHTML += "<tr><td colspan='2'><div style='position:relative;float:right;' ><p onclick='javascript: showNewContactForm()' style='cursor:pointer;display:block;font-weight:bold;'>Dodaj kontakt</p></div></td></tr>";
          
        }
     });
}

/**
 *   @description   : Removes user from the list
 *   
 *   @param         : user_id - numeric id of the user  
 */ 
function removePersonFromTheList(id_person){
     
     //--CO-- send ajax request   
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: "asum=1&action=delete&id_person="+id_person,
        success: function(html_code){
         
          document.getElementById("user_signup_container").style.display = "none";
          document.getElementById("signed_users_list").innerHTML = "<tr><td><div style='display:block;'>" + html_code + "</div></td></tr>";
          document.getElementById("signed_users_list").innerHTML += "<tr><td colspan='2'><div style='position:relative;float:right;' ><p onclick='javascript: showNewContactForm()' style='cursor:pointer;display:block;font-weight:bold;'>Dodaj kontakt</p></div></td></tr>";
          
        }
     });
}

function editPersonOnTheList(id_person){
     //--CO-- send ajax request   
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: "asum=1&action=edit&id_person="+id_person,
        success: function(html_code){
         
          document.getElementById("user_signup_container").style.display = "none";
          document.getElementById("signed_users_list").innerHTML = "<tr><td><div style='display:block;'>" + html_code + "</div></td></tr>";
          //document.getElementById("signed_users_list").innerHTML += "<tr><td colspan='2'><div style='position:relative;float:right;' ><p onclick='javascript: showNewContactForm()' style='cursor:pointer;display:block;font-weight:bold;'>Dodaj kontakt</p></div></td></tr>";
          
        }
     });
}


/**
 *   @ description  : function shows hidden add new contact form
 *   @ returns      : nothing 
 */ 
function showNewContactForm(){

     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: "asum=2&action=show_form",
        success: function(html_code){
        
          document.getElementById("user_signup_container").style.display = "";
          document.getElementById("user_signup_container").innerHTML = html_code;
        }
     });
}

/**
 *   @description   : Function toggle button for adding new users
 *   @param bool show_hide    : true    - displays add new user button, 
 *                            : false   - hides   add new user button
 *                            
 *   @returns       : none   
 */ 
function showAddNewUserBtn(){
     alert("show hide add new user button " + show_hide);
}

/**
 * ------------------------------------- NEW JS FUNCTIONS ------------------------------------------
 */ 

function displayAnotherUserSignupForm(){

     var i = 1;
     var append_content = "";
     var id_event;
     
     id_event = $("[name=id_event]").val();
     
     // remove all prior "Dodaj še enega udeleženca" buttons and inserts "Odstrani udele\enca" button
     $("[name=add_another_user_btn_container]").each(function (){

               $(this).children().remove();
               
               append_content = "<td class=\"f_title\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
               append_content += "<td class=\"f_space\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
               append_content += "<td class=\"f_title\" style=\"text-align:right;width:auto;\"><p name=\"remove_user_form_btn_container\" style=\"cursor:pointer;float:right;\" onclick=\"javascript: removeUserSignupForm(this);\">Odstrani udeleženca</p></td>\n";
               
               $(this).append(append_content);
          }
     );
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        data: "display_empty_user_form=1&id_event="+id_event,
        async: false,
        success: function(html_code){
        
          $("#forms_container").children().append(html_code);
        }
     });
     
     if($("[name=add_another_user_btn_container]").length > 0){
          $("[name=remove_user_form_btn_container]").each(function(i){ $(this).css("display",""); });
     }
}

/**
 *   @ description  : This function removes user form at specified ID
 */ 
function removeUserSignupForm(obj){

     // delete table where this paragraph is placed in
     // table - tr - td - p
     $(obj).parent().parent().parent().remove();

     // if there is one form displayed disable remove button under the last form
     if($("[name=add_another_user_btn_container]").length < 2){

          $("[name=add_another_user_btn_container]").children().remove();

          append_content = "<td class=\"f_title\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
          append_content += "<td class=\"f_space\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
          append_content += "<td class=\"f_title\" style=\"text-align:right;width:auto;\"><p style=\"cursor:pointer;float:right;\" onclick=\"javascript: displayAnotherUserSignupForm(2);\">Dodaj še enega udeleženca</p></td>\n";

          $("[name=add_another_user_btn_container]").append(append_content);          
          

     }else{ // the last form must have add and delete buttons
     
          $("[name=add_another_user_btn_container]:last").children().remove();
          
          append_content = "<td class=\"f_title\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
          append_content += "<td class=\"f_space\"><img src=\"images/spacer.gif\" alt=\"\" /></td>";
          append_content += "<td class=\"f_title\" style=\"text-align:right;width:auto;\"><p name=\"remove_user_form_btn_container\" style=\"cursor:pointer;float:right;\" onclick=\"javascript: removeUserSignupForm(this);\">Odstrani udeleženca<p style=\"float:right;margin-left:5px;margin-right:5px;\" name=\"remove_user_form_btn_container\">|</p></p><p style=\"cursor:pointer;float:right;\" onclick=\"javascript: displayAnotherUserSignupForm(2);\">Dodaj še enega udeleženca</p></td>\n";
      
          $("[name=add_another_user_btn_container]:last").append(append_content);
     }
}

/**
 *   @ description  : This function validates all fields in sign up form. If the field is empty or contains anappropriate data then it's preceding label's color change.
 *                    Form is submited when all data is valid!   
 *
 */
 
function validateUserData(){

     /**
      *   ---------  COMPANY DATA VALIDATION --------------
      */
      //alert($("input#myLang").val());
      if($("input#myLang").val()=="hr"){
		var company_fields_values    = new Array("title","address","postnum","postname","cnumber","phone","fax","taxpayer","note");
		var company_fields_types     = new Array("string","string","number","string","string","string","string","number","string");
		var company_fields_requires  = new Array(true,true,true,true,true,true,false,false,false);
	  }
	  else{
		  var company_fields_values    = new Array("title","address","postnum","postname","cnumber","idnum","phone","fax","taxpayer","note");
	      var company_fields_types     = new Array("string","string","number","string","string","string","string","string","number","string");
	      var company_fields_requires  = new Array(true,true,true,true,true,true,true,false,false,false);
	  }
      
      var validate_value;
      var return_value = true;
      
      return_value &= validateLogicCompany(company_fields_values, company_fields_types, company_fields_requires);

      /**
      *   ----------- USER DATA VALIDATION ----------------
      */            
      company_fields_values    = new Array("id_title","firstname","lastname","email","workplace","maillist","person_special");
      company_fields_types     = new Array("string","string","string","email","string","string","string","string");
      company_fields_requires  = new Array(false,true,true,true,true,false,false,false);
      
      return_value &= validateLogicPerson(company_fields_values, company_fields_types, company_fields_requires);

      // if all forms are filled correctly procede to the confirm page
      if(return_value){
          uploadCompanyData();
          uploadPersonData();
          formSubmit("signup");
          
          return true;
      }else{
		alert("Napaka pri vnosu podatkov.\nProsimo pravilno izpolnite obarvana polja.");
        return false;
      }
      
}  

/**
 *
 */
 
function validateLogicCompany(arr1,arr2, arr3){
      var company_fields_values    = arr1;
      var company_fields_types     = arr2;
      var company_fields_requires  = arr3;
      
      var validate_value;
      var return_value = true;
      
      $.each(company_fields_values, function(index, cfv_value){
      
      
         var validating_obj = $("[name="+cfv_value+"]");
         //var validating_obj = document.getElementsByName(cfv_value);

          switch(company_fields_types[index]){
               
               case "string" :
                         if(company_fields_requires[index]){
                         
                              //var x = new Strig(validating_obj.value);
                              
                              //if(validating_obj[0].value == "" || validating_obj[0].value == undefined ){
                              if(validating_obj[0].value.length == 0 ){
                                   //$("#"+cfv_value+"").css("color","#ff7800");
                                   if(cfv_value == "postname")
                                          cfv_value = "postnum1";								   
								   
                                   document.getElementById(cfv_value).style.color = "#ff7800";
                                   //$("span[name="+cfv_value+"]").css("color","#ff7800");
                                   return_value &= false;
                              }else{
									if(cfv_value == "postname")
                                          cfv_value = "postnum1";
                                   $("span[name="+cfv_value+"]").css("color","#646464");
                                   //document.getElementById(cfv_value).style.color = "#646464";
                                   $("#"+cfv_value+"").css("color","#646464");
                                   return_value &= true;
                              }
                         }
                         break;
               case "number" :
                        
                         if(company_fields_requires[index]){
                              //var val = validating_obj.val();
                              var val = validating_obj[0].value;
                              var number = new Number(val);

                              if(!isInteger(val)){
                                   //$("#"+cfv_value+"").css("color","#ff7800");
                                   if(cfv_value == "postnum")
                                          cfv_value = "postnum1"
                                   document.getElementById(cfv_value).style.color = "#ff7800";
                                   return_value &= false;
                              }else{
                                   if(cfv_value == "postnum")
                                          cfv_value = "postnum1"                              
                                   document.getElementById(cfv_value).style.color = "#646464";
                                   return_value &= true;
                              }
                         }                         
                         break;
                         
               case "email" :
                         if(company_fields_requires[index]){
                              var val = validating_obj.val();
                              if(!isEmail(val)){
                                   $("#"+cfv_value+"").css("color","#ff7800");
                                   return_value &= false;
                              }else{
                                   $("#"+cfv_value+"").css("color","#646464");
                                   return_value &= true;
                              }
                         }                          
                         break;                                                  
          }    

          } // end of anonymous function
      );
      
      return return_value;      
} 


/**
 *
 */
 
function validateLogicPerson(arr1,arr2, arr3){
      var company_fields_values    = arr1;
      var company_fields_types     = arr2;
      var company_fields_requires  = arr3;
      
      var validate_value;
      var return_value = true;
      var i = 0;
      var str_i = 1;
      var num_person_special = 0;
      
      $.each(company_fields_values, function(index, cfv_value){
          validating_obj = $("input[name^='"+cfv_value+"']");
          //validating_obj = $("input[rel='"+cfv_value+"']");
          
          // try also select box and checkbox
          if(validating_obj.attr("name") == undefined){
               validating_obj = $("select[name^='"+cfv_value+"']");
          }else if(validating_obj.attr("name") == undefined){
               validating_obj = $("checkbox[name^='"+cfv_value+"']");
          }
         
          
          
          $.each(validating_obj, function(index1, cfv_value1){
              
               var arr_string;
              if(cfv_value == "person_special"){

                    num_person_special  = $("input[name^='"+cfv_value+"']").length;
                    //num_person_special  = $("input[rel='"+cfv_value+"']").length;
                    num_person_form     = $("table[name='person_form']").length;
                    //num_person_form     = document.getElementsByName("person_form").length;
                         
                    arr_string = $(this).attr("name").split("_");
                    arr_string = cfv_value1.name.split("_");
                    $(this).attr("name",cfv_value + "_"+arr_string[2]+"_"+i);
                    //cfv_value1.name = cfv_value + "_" + arr_string[2] + "_" + i;
                    
                    
                    if(str_i == (num_person_special/num_person_form)){
                         str_i = 1;
                         i++;
                    }else{
                         str_i++;
                    }
              }else{
                    
                    //$(this).attr("name",cfv_value + "_" +index1);
                    cfv_value1.name = cfv_value + "_" + index1;  
              }

              //var preceding_label = $("[name^='lab_"+cfv_value+"']");
              var preceding_label = $("span[name^='lab_"+cfv_value+"']");

              // rename preceding lables e.g. from lab_firstname to lab_firstname_0              
              $.each(preceding_label, function(index3, value3){
                     $(this).attr("name", "lab_"+cfv_value + "_" + index3);
                     //value3.name = "lab_" + cfv_value + "_" + index3;
              });

               switch(company_fields_types[index]){                    
                    case "string" :
                              if(company_fields_requires[index]){
                                   //alert("[name=lab_"+cfv_value+"_"+index1+"]");
                                   if($(this).val() == ""){
                                        $("span[name=lab_"+cfv_value+"_"+index1+"]").css("color","#ff7800");
                                        //var _this = document.getElementsByName("lab_"+cfv_value+"_"+index1);
                                        //alert(_this[0]);
                                        //if(_this[0])
                                             //_this[0].style.color = "#ff7800";
                                        return_value &= false;
                                   }else{
                                        $("span[name=lab_"+cfv_value+"_"+index1+"]").css("color","#646464");
                                        //var _this = document.getElementsByName("lab_"+cfv_value+"_"+index1);
                                        //if(_this[0])
                                           //  _this[0].style.color = "#646464";                                        
                                        return_value &= true;
                                   }
                              }
                              break;

                    case "email" :
                              if(company_fields_requires[index]){
                                   if(!isEmail($(this).val())){
                                        $("span[name=lab_"+cfv_value+"_"+index1+"]").css("color","#ff7800");
                                        //var _this = document.getElementsByName("lab_"+cfv_value+"_"+index1);
                                        //if(_this[0])
                                          //   _this[0].style.color="#ff7800";     
                                        return_value &= false;
                                   }else{
                                        $("[name=lab_"+cfv_value+"_"+index1+"]").css("color","#646464");
                                        //var _this = document.getElementsByName("lab_"+cfv_value+"_"+index1);
                                        //if(_this[0])
                                            // _this[0].style.color = "#646464";
                                        return_value &= true;
                                   }
                              }                          
                              break;                                                  
               } 
          });   

          } // end of anonymous function
      );
      
      return return_value;      
}

/**
 *   @ description : this function uploads the company data
 */ 
function uploadCompanyData(){

      var title     = $("input[name='title']").val();
      var address   = $("input[name='address']").val();
      var postnum   = $("input[name='postnum']").val();
      var postname  = $("input[name='postname']").val();
      var cnumber   = $("input[name='cnumber']").val();
      var idnum     = $("input[name='idnum']").val();
      var phone     = $("input[name='phone']").val();
      var taxpayer  = $("#t0:checked").val();
      var note      = $("textarea[name='note']").val();
      var id_event  = $("input[name=id_event]").val();
      var fax       = $("input[name=fax]").val();
      
      $("#action").val("confirm");
      

      
      if(taxpayer == undefined)
          taxpayer = 1;
     else
          taxpayer = 0;
          
     //--CO-- send ajax request
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        async: false,
        //data: "insert_company=1&action=insertcom&title="+title+"&address="+address+"&postnum="+postnum+"&postname="+postname+"&cnumber="+cnumber+"&idnum="+idnum+"&phone="+phone+"&taxpayer="+taxpayer+"&note="+note+"&id_event="+id_event+"&fax="+fax+"",
         data : ({
        	insert_company : 1,
        	action : 'insertcom',
        	title : title,
        	address : address,
        	postnum : postnum,
        	postname : postname,
        	cnumber : cnumber,
        	idnum : idnum,
        	phone : phone,
        	taxpayer : taxpayer,
        	note : note,
        	id_event : id_event,
        	fax : fax
        }),
        success: function(id_company){
          $("#id_company").val(id_company);
        }
     });
          
     


}

function uploadPersonData(){
     
     var num_form = 0;
     var forms = $("[name=person_form]");
     
          
     var id_event   = $("input[name='id_event']").val();
     var id_company = $("#id_company").val();     
     
     // first delete all users for that event in company from db
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        async: false,
        data: "insert_person=1&action=beforeinsert&id_event="+id_event+"&id_company="+id_company,
        success: function(data){
        }
     }); // --- end of ajax request     
     
     $.each(forms, function(index, value){
     
          var id_title   = $("select[name='id_title_"+num_form+"']").val();
          var firstname  = $("input[name='firstname_"+num_form+"']").val();
          var lastname   = $("input[name='lastname_"+num_form+"']").val();
          var email      = $("input[name='email_"+num_form+"']").val();
          var workplace  = $("input[name='workplace_"+num_form+"']").val();
          var person_special = "";
          var maillist   = $("input[name='maillist_"+num_form+"']:checked").length;

                    
          
           // --------------- person special ----------------
          num_person_special  = $("input[name^='person_special']").length;
          num_person_form     = $("table[name='person_form']").length;
          var num_specials = num_person_special/num_person_form;
          
			$(this).find("input[name^='person_special']:checked").each(function(k){
			//if ($(this).is(":checked")){
				if(person_special != "") {
					 person_special += "|";               
				}
				person_special += $(this).val();
			//}
			});
		  
		  /* var ns = 0;
          for(ns = 0; ns <= num_specials; ns++){
               
               var x = "";
               if((x = $("[name='person_special_"+ns+"_"+num_form+"']:checked").val()) != undefined){
                    if(person_special != "")
                         person_special += "|";               
                    person_special += x;
               }     
          } */
		  
		  
          num_form++;
    
     //--CO-- send ajax request
     $.ajax({
        type: "POST",
        url: "ajax_signed_users_manip.php",
        async: false,
        //data: "insert_person=1&action=insert&id_title="+id_title+"&firstname="+firstname+"&lastname="+lastname+"&email="+email+"&workplace="+workplace+"&id_event="+id_event+"&id_company="+id_company+"&person_special="+person_special+"&maillist="+maillist,
        data : ({
        		insert_person : 1,
        		action : 'insert',
        		id_title : id_title,
        		firstname : firstname,
        		lastname : lastname,
        		email : email,
        		workplace : workplace,
        		id_event : id_event,
        		id_company : id_company,
        		person_special : person_special,
        		maillist : maillist
        	}),
        success: function(data){
        }
     }); // --- end of ajax request
     }); // --- end of each
    
}


/**
 *   @ description : validate s
 *   
 *   return : true if s is integer  
 */ 
isInteger = function( s ) {
     return !isNaN( parseInt( s ) );
}

function isEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email
   if(reg.test(address) == false) {
      return false;
   }
   return true;
}



/**
 *   This events are appended to the user sign up form. If user fills all required fileds it enables ADD user button
 */  
 
//$(".f_text").keypress(alert(e));
//$(".f_text").keypress(checkRequiredFiledsValues(e));

function checkRequiredFiledsValues(e){
     alert(e);
}
