var banner_count = 2;

if (typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}
	var indeks;
	var url;
	var htmlhttp;
	var header_ids ;
	var timeout;
	var iframe;
	indeks=0;

	function pop_up(param){

		//alert("pop_up.php?param="+param);
       	window.open("pop_up.php?param="+param,'','left=300,top=300,height=400,width=500,status=no');


	}
	check_is_group_selected();


function check_is_group_selected(){
		var opt=document.getElementById("group_selected");
		try{
		if (opt!=null && opt.selectedIndex==0)
		{
			dump_table("Group is not selected")

		}
		}catch(e){
		}
	}
	function clear_message(){
    var tbody = document.getElementById("dump");
		while(tbody.childNodes.length>0)
		{
			tbody.removeChild(tbody.firstChild);
		}
	}
	function dump_table(message){
    var slika,text,div;
    var tbody = document.getElementById("dump");
		clear_message();
		div=document.createElement("div");
		div.setAttribute("class","error");
		div.setAttribute("align","left");
		slika=document.createElement("img");
 		slika.setAttribute("src","img/alertsmall.gif");
		div.appendChild(slika);
		text=document.createTextNode(message);
		div.appendChild(text);
		tbody.appendChild(div);


	 }
   function checkForm(formObj){
   var group=document.getElementById("group_select");
 	try{
	if ((group!=null) && group.selectedIndex==0)
		{
			dump_table("Group is not selected");
			return false;
		}
	}catch(e){
	}

	}
   function show(id){
	  if (document.getElementById(id)==null) return;
	   if (document.getElementById(id).style.display == "none"){
		   document.getElementById(id).style.display="";
	   }

   }
   function hide(id){
	  if (document.getElementById(id)==null) return;
	   if (document.getElementById(id).style.display == ""){
		   document.getElementById(id).style.display="none";
	   }

   }

// this function should change name of page title to desired string
   /*function change_page_title(){
	var title= document.getElementById('page_title');
	if (title==null) return;

   }
   */
   function hide_all(){
		 hide('videolink');
	     hide('gallery');
		 hide('by_line_author');
		 hide('page_title');
		 hide('videolink');
		 hide('gallery');
		 hide('by_line_author');
		 hide('page_title');
		 hide('event_time');
		 hide('location');
		 hide('mem_fee');
		 hide('non_mem_fee');
		 hide('st_fee');
		 hide('table_fee');
		 hide('info');
		 hide('cont_tel');
		 hide('cont_email');
		 hide('shopping');
		 hide('promolink');
		 hide('event_date');
		 hide('banner_images');
   }
   function change_template(name){
//        var html_body=document.getElementById("body");
        var opt=document.getElementById("template_select");
 var template_name;

 if (name!=null)
 {
	 template_name=name;
 }else {
	 if (opt!=null)
	 {
	  if(opt.selectedIndex>0){

	 template_name=opt.options[opt.selectedIndex].value;
		}
	 }
 }
 	try{
		if (template_name!=null)
		{
				 hide_all();

			      switch (template_name) {
					 case "article_Full": {
					  //show('videolink');
					  //show('gallery');
					  show('by_line_author');
					  show('page_title');
					 }break;
					 case "event_detail": {
					  show('page_title');
					  show('event_date');
					  show('event_time');
					  show('location');
					  show('mem_fee');
					  show('non_mem_fee');
					  show('st_fee');
					  show('table_fee');
					  show('info');
					  show('cont_tel');
					  show('cont_email');
					  show('shopping');
				//	  show('promolink');
					  show('banner_images');
					 }break;
					 case "event_article": {
					  //show('videolink');
					  show('gallery');
					  show('by_line_author');
					  show('page_title');
					  //show('promolink');
					  show('banner_images');
					 }break;
					 case "show_author_info": {

					   show('page_title');
					   hide('tr_of _sel_image');
					   /*show('by_line_author');*/
					 }break;
					 default:{
				/*		 	  temp=new_link("article_add.php","tpl="+opt.options[opt.selectedIndex].value);
							var gr=document.getElementById("group_select");
                  if (gr!=null && gr.selectedIndex>0){
                     temp+="&group="+gr.options[gr.selectedIndex].value;
                  }
				  if (document.form1!=null)
				  {
					if (checkForm(document.form1)!=false)	{
						self.location=temp;
					}
				  }
                  else {
					  alert('ne proverava postojanje grupe');
					  //self.location=temp;
				  }
				  */
					 }
				  } //end of switch

		  }
		}catch(e){
     alert(e);
	}
   }
  function new_link(old_link,param){
	    var temp=new String(old_link);
		var id=-1;
		if (temp.indexOf('?') != -1)
		{
			old_link+='&'+param;
		}else
			old_link+='?'+param;
		return old_link;
   }
//starting script.
	function new_location(){
		var opt=document.getElementById("group_select");
		var temp=new String(self.location);
		var id=-1;
		if (temp.indexOf('group=') != -1)
		{
			var pos=temp.indexOf('group=');
			id=temp.substring(pos+7,temp.length-1);
			temp=temp.substring(0,pos-1);



		}
		if (opt!=null && opt.options[opt.selectedIndex].value!=id)
		{

			/*if (temp.indexOf('?') != -1)
			{
				self.location=temp+"&group="+opt.options[opt.selectedIndex].value;

			}
			else {

				self.location=temp+"?group="+opt.options[opt.selectedIndex].value;
			}*/
			self.location="category_management.php?group="+opt.options[opt.selectedIndex].value;

		}else{

		}


	}

	function user_changed_group() {
		if (arguments[0]==null){
			getHTTPObject("ajax.php?group=");
		}else{
			getHTTPObject(arguments[0]+"?group=");
		}

	}

	function user_changed_category(){
		var cat = document.getElementById("category_select");
		var i=cat.options[cat.selectedIndex].value;
		alert(i);
	}

//handling  response from server side
	function handleHttpResponse(htmlresponse) {
		if (arguments[0]=='group')
		{
			var opt=document.getElementById("group_select");
			var cat_select = document.getElementById("category_select");
			cat_select.options.length = 0;
			var i=1;
			var length=(arguments.length-1) / 2;
            sLabelFirstElement = opt.options[opt.selectedIndex].text;
			cat_select.options[0]=new Option( sLabelFirstElement,opt.options[opt.selectedIndex].value, false, false);
			while(i<length+1){
				cat_select.options[i] = new Option(arguments[2*i], arguments[2*i-1], false, false);
				i=i+1;
			}
			getHTTPObject("ajax.php?location=");
	//		getHTTPObject("ajax.php?images=");
		}else if (arguments[0]=='gallery'){
			var gal = document.getElementById("gallery");
			gal.options.length = 0;
			if (gal!=null && arguments.length>1)
				{

				var i=1;
				gal.options[0]=new Option( "...select gallery","0", false, false);
				while(i<arguments.length){
					gal.options[i] = new Option(arguments[i], arguments[i], false, false);
					i=i+1;
				}
			}
		}else if (arguments[0]=='location'){
			/*
			var loc_select = document.getElementById("location_opt");
			loc_select.options.length = 0;
			var i=1;
			loc_select.options[0]=new Option( "No location",'', false, false);
			while(i<arguments.length){
				//alert(''+arguments[i] )
				loc_select.options[i] = new Option(arguments[i], arguments[i], false, false);
				i=i+1;
			}
			*/
			getHTTPObject("ajax.php?image=");
		}else if (arguments[0]=='image'){
			var image_select = document.getElementById("image_opt");
			image_select.options.length = 0;
			var i=1;
			image_select.options[0]=new Option( "No image",'', false, false);
			while(i<arguments.length){
				image_select.options[i] = new Option(arguments[i], arguments[i], false, false);
				i=i+1;
			}

			var j = 1;
			var banner_image = document.getElementById("banner_image" + j);
			do{
				banner_image.options.length = 0;
				i=1;
				banner_image.options[0]=new Option( "No image",'', false, false);
				while(i<arguments.length){
					banner_image.options[i] = new Option(arguments[i], arguments[i], false, false);
					i=i+1;
				}
				j++;
				banner_image = document.getElementById("banner_image" + j);
			}while (banner_image != undefined);
			getHTTPObject("ajax.php?gallery=");
		}
	}

	function addBannerImage2()
	{
		var banner_form = document.getElementById("banner_form");
		str = banner_form.innerHTML;
		//alert(str);
		/*"
			<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"10\" style=\"border-bottom:solid black 2px;\">
			<tr>
				<td width=\"30%\">Select sponsor image</td>
				<td width=\"70%\">
		<input name=\"banner_image1\" type=\"text\" class=\"textfield2\" size=\"22\" value=\"".$si_row['file_name']."\">
		<img src=\"img/bullet.gif\" onclick=\"window.open('editor/dialogs/img_library.php?aid=$aid&name=banner_image1','','toolbars=no,resize=yes,height=350,width=350,scrollbars=yes')\">
				</td>
			<tr>
				<td>Sponsor link  (without http://)</td>
				<td><input name=\"banner_link{$i}\" id=\"banner_link{$i}\" type=\"text\" class=\"textfield2\" value=\"{$si_row[link]}\" size=\"45\" /></td>
			</tr>
			 <tr>
				<td>Sponsor image title</td>
				<td><input name=\"banner_title{$i}\" id=\"banner_title{$i}\" type=\"text\" class=\"textfield2\" value=\"{$si_row[title]}\" size=\"45\" /></td>
			</tr>
			</table>";*/
		str +="<table width='100%' border='0' cellpadding='0' cellspacing='10' style='border-bottom:solid black 2px;'><tr><td width='30%'>Select sponsor image</td><td width='70%'><input id='banner_image"+banner_count+"' name='banner_image"+banner_count+"'";
		str+="type='text' class='textfield"+banner_count+"'";
		str+=" size='22' value='' /><img src='img/bullet.gif' onclick =\"window.open('editor/dialogs/img_library.php?aid=&name=banner_image"+banner_count +"','','toolbars=no,resize=yes,height=350,width=350,scrollbars=yes')\"></td><tr><td>Sponsor link  (without http://)</td><td><input name='banner_link"+banner_count+"' id='banner_link"+banner_count+"' type='text' class='textfield"+banner_count+"' value='' size='45' /></td></tr><tr><td>Sponsor image title</td><td><input name='banner_title"+banner_count+"' id='banner_title"+banner_count+"' type='text' class='textfield"+banner_count+"' value='' size='45' /></td></tr></table>";
			banner_count++;
			//alert(str);
			document.getElementById("banner_form").innerHTML = str;
	}

	function addBannerImage(){
		addBannerImage2();
		/*var banner_form = document.getElementById("banner_form");
		var new_banner = document.createElement('table');
		banner_form.appendChild(new_banner);
		new_banner.setAttribute('width', '100%');
		new_banner.setAttribute('border', '0');
		new_banner.setAttribute('cellpadding', '0');
		new_banner.setAttribute('cellspacing', '10');
		new_banner.setAttribute('style', 'border-bottom:solid black 2px;');
		var new_banner_tbody = document.createElement('tbody');
		new_banner.appendChild(new_banner_tbody);
		var new_banner_tr1 = document.createElement('tr');
		new_banner.appendChild(new_banner_tr1);
		var new_banner_tr1_td1 = document.createElement('td');
		new_banner_tr1.appendChild(new_banner_tr1_td1);
		new_banner_tr1_td1.setAttribute('width', '30%');
		new_banner_tr1_td1.appendChild(document.createTextNode('Select sponsor image'));

		var new_banner_tr1_td2 = document.createElement('td');
		new_banner_tr1.appendChild(new_banner_tr1_td2);


		//iqed var new_banner_tr1_td2_select = document.createElement('select');
		//iqed
		var new_banner_tr1_td2_select = document.createElement('input');
		//iqed
		new_banner_tr1_td2.appendChild(new_banner_tr1_td2_select);

		//iqed new_banner_tr1_td2_select.setAttribute('name',"banner_image"+banner_count);
		//iqed new_banner_tr1_td2_select.setAttribute('id',"banner_image"+banner_count);
		//iqed new_banner_tr1_td2_select.setAttribute('class',"textfield2");
		//iqed
		new_banner_tr1_td2_select.setAttribute('name',"banner_image"+banner_count);
		new_banner_tr1_td2_select.setAttribute('id',"banner_image"+banner_count);
		new_banner_tr1_td2_select.setAttribute('class',"textfield2");
		new_banner_tr1_td2_select.setAttribute('type', 'text');
		new_banner_tr1_td2_select.setAttribute('size', '25');
		//iqed
		//new_banner_imglist_win_btn=document.createElement("img");
		//alert("Debug Message: addBannerImage called");
		try {
			new_banner_imglist_win_btn = document.createElement("img");
			new_banner_imglist_win_btn.setAttribute("src", "img/bullet.gif");
		}
		catch (e) {
			new_banner_imglist_win_btn = document.createElement("<img src='img/bullet.gif' />");
		}
		new_banner_tr1_td2.appendChild(new_banner_imglist_win_btn);
		//new_banner_imglist_win_btn.setAttribute("src", "img/bullet.gif");
		//iqed

		//novi tr
		var new_banner_tr2 = document.createElement('tr');
		new_banner.appendChild(new_banner_tr2);

		var new_banner_tr2_td1 = document.createElement('td');
		new_banner_tr2.appendChild(new_banner_tr2_td1);
		new_banner_tr2_td1.setAttribute('width', '30%');

		new_banner_tr2_td1.appendChild(document.createTextNode('Sponsor link (without http://)'));

		var new_banner_tr2_td2 = document.createElement('td');
		new_banner_tr2.appendChild(new_banner_tr2_td2);

		var new_banner_tr2_td2_input = document.createElement('input');
		new_banner_tr2_td2.appendChild(new_banner_tr2_td2_input);

		new_banner_tr2_td2_input.setAttribute('name',"banner_link"+banner_count);
		new_banner_tr2_td2_input.setAttribute('id',"banner_link"+banner_count);
		new_banner_tr2_td2_input.setAttribute('class',"textfield2");
		new_banner_tr2_td2_input.setAttribute('type', 'text');
		new_banner_tr2_td2_input.setAttribute('size', '45');

		//novi tr
		var new_banner_tr3 = document.createElement('tr');
		new_banner.appendChild(new_banner_tr3);

		var new_banner_tr3_td1 = document.createElement('td');
		new_banner_tr3.appendChild(new_banner_tr3_td1);
		new_banner_tr3_td1.setAttribute('width', '30%');

		new_banner_tr3_td1.appendChild(document.createTextNode('Sponsor image title'));

		var new_banner_tr3_td2 = document.createElement('td');
		new_banner_tr3.appendChild(new_banner_tr3_td2);

		var new_banner_tr3_td2_input = document.createElement('input');
		new_banner_tr3_td2.appendChild(new_banner_tr3_td2_input);

		new_banner_tr3_td2_input.setAttribute('name',"banner_title"+banner_count);
		new_banner_tr3_td2_input.setAttribute('id',"banner_title"+banner_count);
		new_banner_tr3_td2_input.setAttribute('class',"textfield2");
		new_banner_tr3_td2_input.setAttribute('type', 'text');
		new_banner_tr3_td2_input.setAttribute('size', '45');
		var banner_image = document.getElementById("banner_image1");
		var new_banner_image = document.getElementById("banner_image" + banner_count);
		//iqed new_banner_image.options.length = 0;
		i=1;
		/*iqed
		while(i<banner_image.options.length){
			new_banner_image.options[i] = new Option(banner_image.options[i].text, banner_image.options[i].value, false, false);
			i=i+1;
		}
		iqed
		banner_count++;
		//alert(banner_count);*/
	}

    function getHTTPObject(temp_url) {
	   var group=document.getElementById('group_select').value;

	   if (group==0)
		{
		   var cat_select = document.getElementById("category_select");

			cat_select.options.length = 0;
		   return;
		}
	   var get_url=temp_url+group;
		if (window.ActiveXObject) { // IE
                try {
                    htmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        htmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                }
        }
        else if (window.XMLHttpRequest ) { // Mozilla, Safari,...
              htmlhttp =  new XMLHttpRequest();
              if (htmlhttp.overrideMimeType) {
                     htmlhttp.overrideMimeType('text/xml');
              }
        }

		try{
        if (!htmlhttp) { //for non-xml browsers, use IFRAME (bloody OPERA)
            if (iframe==null)
            {
				var iframe = document.createElement('IFRAME');
				iframe.src = get_url+'&i=1';
				// opera 7.54 doesn't like iframe styles
				iframe.style.width = '0px';
				iframe.style.height = '0px';


			}
			else{
				this.iframe.src = temp_url+'&i=1';

			}
		}else {
			htmlhttp.open("GET", get_url, true);
			htmlhttp.send(null);
			htmlhttp.onreadystatechange = function() {
				if (htmlhttp.readyState == 4) {
					try {
						if (htmlhttp.status != 200 || htmlhttp.responseText.charAt(0) == '<') {
							/* some error */
						} else {
							eval(htmlhttp.responseText);
						}
					} catch (e) {
					}
				}
			}
		}

	   }catch (e){
		   alert(e);

	   }
    }


function takeimg(img_name)
{
opener.document.form1.sel_img.value = img_name;
self.close();
}
function takeimg1(img_name)
{
opener.document.form1.banner_image1.value = img_name;
self.close();
}

//9 june 06 swati

/*function doPopUp() {
	var jumpToHere;
	var winOptions;
	var popUpWindow;

	jumpToHere = "applicantshelp.html"
	winOptions = "top=50, left=200, width=350,scrollbars=yes";
	window.open(jumpToHere, '',winOptions+'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0',true);
}*/

function gotoDel() {
	var i=0;

		for(i=0;i<document.frm.elements.length;i++) {
			if(document.frm.elements[i].checked) {
				if(confirm('Are you sure you want to archive the selected record(s)?')) {
					document.frm.submit();
					return true;
				} else {
					return;
				}
			}
		}
		alert('Please select applicant(s) to delete.');
		return;
}

function order(colm) {
	document.frm.orderBy.value = colm;
	document.frm.submit();
}

function gotoRead(apid) {
	document.frm.action = "applicantsmessage.php";
	document.frm.app_id.value = apid;
	document.frm.submit();
}

//swati 12june06
function doPopUp_arch(yr) {
	var jumpToHere;
	var winOptions;
	var popUpWindow;

	jumpToHere = "show_archive.php?yr="+yr;
	winOptions = "top=50, left=200, width=500,scrollbars=yes";
	window.open(jumpToHere, '',winOptions+'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0',true);
}

function show_arch(id, year)
{
	//var yr1 = "yr" + id;
	//var yr = document.getElementById('yr1');

	if(document.getElementById('arch'+id).style.display=='block')
	{
		document.getElementById('arch'+id).style.display='none';
		document.getElementById('img'+id).src='img/plus.gif';
		document.getElementById('yr'+id).value='';
	}
	else
	{
		document.getElementById('arch'+id).style.display='block';
		document.getElementById('img'+id).src='img/minus.gif';
		document.getElementById('yr'+id).value=year;
	}
	//alert (document.getElementById('yr'+id).value);
}

/* edited by Nilesh on 14 June for documet_name.doc */
function checkForm_job(formObj){
alert("test");
if (formObj.fname.value == ""){
alert("Please enter your first name.");
//dump_table("Please enter your first name.");
formObj.fname.focus();
return false;
}

if (formObj.lname.value == ""){
alert("Please enter your last name.");
formObj.lname.focus();
return false;
}

if (formObj.company.value == ""){
alert("Please enter a company name.");
formObj.company.focus();
return false;
}

if (formObj.address1.value == ""){
alert("Please enter a company address.");
formObj.address1.focus();
return false;
}

if (formObj.city.value == ""){
alert("Please enter a city.");
formObj.city.focus();
return false;
}

if (formObj.country.value == ""){
alert("Please enter a country.");
formObj.country.focus();
return false;
}
alert(formObj.country.value+":"+formObj.getElementById('state_int').value);
if (formObj.country.value == "USA." && formObj.state.value == ""){
alert("Please select a US state.");
formObj.state.focus();
return false;
}

if (formObj.country.value != "USA" && formObj.state_int.value != ""){
alert("Only US states allowed with USA as country.");
formObj.state_int.focus();
return false;
}

if (formObj.country.value != "USA" && formObj.state.value != ""){
alert("US state selected for international location.\n Please enter an International state");
formObj.state.focus();
return false;
}

if (formObj.phone.value == ""){
alert("Please enter a phone number.");
formObj.phone.focus();
return false;
}

//--- FGI Member  ----------------------------

membershipflag = 0;
for (i=0;i<formObj.fgi_member.length;i++) {
  if (formObj.fgi_member[i].checked == true) {
  membershipflag = 1;
	}
}

if (membershipflag != 1){
alert("Please tell us if you are an FGI member.");
return false;
}

//--------------------------------------------

}
/* end Nilesh */