
// create window handle
function handle() {
	day = new Date();
	return day.getTime();
}

// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
 var result = false;
 if (obj.getAttributeNode("class") != null) {
	 result = obj.getAttributeNode("class").value;
 }
 return result;
}   

// zebra tables stripe
function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#F4F4F4";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }


// checkbox check all
var all_checked=false
function CheckAll(_form, element_name) {
	len = _form.elements.length
	for( f=0 ; f<len ; f++) {
		if (_form.elements[f].name==element_name) {
			_form.elements[f].checked=(all_checked==false) ? true : false
		}
	}
	all_checked=(all_checked==false) ? true : false
}

// billing same checkbox
function BillingSame(_form) {
	if (_form.same.checked) {
		with (_form) {
			bname.value = first_name.value + " " + last_name.value;
			baddr.value = addr.value;
			bcity.value = city.value;
			bzip.value = zip.value;
			bcountry.options[country.options.selectedIndex].selected = true;
			bphone.value = phone.value;
			bfax.value = fax.value;
		}
	} else {
		with (_form) {
			bname.value = "";
			baddr.value = "";
			bcity.value = "";
			bzip.value = "";
			bcountry.options[0].selected = true;
			bphone.value = "";
			bfax.value = "";
		}
	}
}

function openPopUp(url, width, height, whandle) {
	if (whandle == '') {
		whandle = handle();
	}
	window.open(url, whandle, 'width=' + width + ',height=' + height + ',scrollbars=yes,resizable=1,status=1');
}

function getXHR() {  
  if (window.XMLHttpRequest) { 
    // Chrome, firefox, IE7+, Opera, Safari 
    return new XMLHttpRequest();  
  }  
  // IE6 
  try {  
    // The latest stable version. It has the best security, performance,  
    // reliability, and W3C conformance. Ships with Vista, and available  
    // with other OS's via downloads and updates.  
    return new ActiveXObject('MSXML2.XMLHTTP.6.0'); 
  } catch (e) {  
    try {  
      // The fallback. 
      return new ActiveXObject('MSXML2.XMLHTTP.3.0'); 
    } catch (e) {  
      alert('This browser is not AJAX enabled.');  
      return null; 
    }  
  }  
}  

function a_create_input(lang, rec_type, rec_key, fee_id, el_person, el_fee) {
	
	if (document.getElementById(el_fee)) {
		e = document.getElementById(el_fee);
		if (e.checked == false) {
			emptyPersonDiv(fee_id);
			return;
		}
	}
	
	if (document.getElementById(el_person)) {
		e2 = document.getElementById(el_person);
		person_count = e2.options[e2.selectedIndex].value; 
	}
	
	url_howmany_person = '';
	if (arguments[6]) {
    var divElement = document.getElementById("person_div_" + fee_id);
		divElement.innerHTML = 'Katılımcılar yükleniyor...';
		    
		// alert('bip: ' + arguments[6]);
		url_howmany_person = '&howmany_person=' + arguments[6];
 	  // alert(LC_SITE + 'ajax.php?lang=' + lang + url_howmany_person + '&rec_type='+rec_type+'&rec_key='+rec_key+'&action=create_input&fee_id='+fee_id+'&person_count='+person_count)
    var http = getXHR();
    http.open('get', LC_SITE + 'ajax.php?lang=' + lang + url_howmany_person + '&rec_type='+rec_type+'&rec_key='+rec_key+'&action=create_input&fee_id='+fee_id+'&person_count='+person_count);
	  http.onreadystatechange = function() {
		  if (http.readyState == 4) {
  		  var responseText = http.responseText;
	  	  divElement.innerHTML = responseText;
		  }
	  }
    http.send(null);
	}
}

function emptyPersonDiv(fee_id) {
	var divElement = document.getElementById("person_div_" + fee_id);
	divElement.innerHTML = "";	
}

function in_array(myValue,myArray)
{
    function equals(a,b)
    {
        return (a === b);
    }

    for (var i in myArray)
    {
        if (equals(i, myValue))
            return true;
    }

    return false;
}

function showNumFields(_fm, _val) {
	tcno = document.getElementById("tcno_inputs");
	passport = document.getElementById("passport_inputs");
	// first hide	
	tcno.style.display = 'none';
	passport.style.display = 'none';
	// second show according to _val
	/*if (_val == 'TR') {
		tcno.style.display = 'inline';
	} else*/ if (_val != '' && _val != 'TR') {
		passport.style.display = 'inline';		
	}
	
}
function showNumFields_(_fm, _val, index) {
	//tcno = document.getElementById("tcno_inputs");
	passport = document.getElementById("passport_inputs_" + index);
	// first hide	
	//tcno.style.display = 'none';
	passport.style.display = 'none';
	// second show according to _val
	/*if (_val == 'TR') {
		tcno.style.display = 'inline';
	} else*/ if (_val != '' && _val != 'TR') {
		passport.style.display = 'inline';		
	}
	
}

