// JavaScript Document
function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

function change_menu_color(button_id, state, url)
{
  var over_textcolor = "#FFFF00";
  var over_cursor_type = "pointer";
  var out_textcolor = "#FFFFFF";
  var out_cursor_type = "default";
  
  //alert(button_id + state);
  
  if (state == 'over')
	  {
			  switch(button_id)
				{
					case 1:
					  document.getElementById('1').style.color = over_textcolor; 
					  document.getElementById('1').style.cursor = over_cursor_type;
					  document.getElementById('1b').style.background = "#cddfc4";
					  document.getElementById('1b').style.cursor = over_cursor_type;
					  break    
					  
					case 2:
					  document.getElementById('2').style.color = over_textcolor; 
					  document.getElementById('2').style.cursor = over_cursor_type;
					  document.getElementById('2b').style.background = "#c05e9d";
					  document.getElementById('2b').style.cursor = over_cursor_type;
					  break    
					
					case 3:
					  document.getElementById('3').style.color = over_textcolor; 
					  document.getElementById('3').style.cursor = over_cursor_type;
					  document.getElementById('3b').style.background = "#1891b1";
					  document.getElementById('3b').style.cursor = over_cursor_type;
					  break 
					
					case 4:
					  document.getElementById('4').style.color = over_textcolor; 
					  document.getElementById('4').style.cursor = over_cursor_type;
					  document.getElementById('4b').style.background = "#d7ddf3";
					  document.getElementById('4b').style.cursor = over_cursor_type;
					  break    
					
					case 5:
					  document.getElementById('5').style.color = over_textcolor; 
					  document.getElementById('5').style.cursor = over_cursor_type;
					  document.getElementById('5b').style.background = "#b2b3b8";
					  document.getElementById('5b').style.cursor = over_cursor_type;
					  break
					
					default:
					  break       
				} 
				
	  }
  
  else if (state == 'out')
	  {
		   switch(button_id)
				{
					case 1:
					  document.getElementById('1').style.color = out_textcolor; 
					  document.getElementById('1').style.cursor = out_cursor_type;
					  document.getElementById('1b').style.background = "#909d8b";
					  document.getElementById('1b').style.cursor = out_cursor_type;
					  break    
					  
					case 2:
					  document.getElementById('2').style.color = out_textcolor; 
					  document.getElementById('2').style.cursor = out_cursor_type;
					  document.getElementById('2b').style.background = "#91477a";
					  document.getElementById('2b').style.cursor = out_cursor_type;
					  break    
					
					case 3:
					  document.getElementById('3').style.color = out_textcolor; 
					  document.getElementById('3').style.cursor = out_cursor_type;
					  document.getElementById('3b').style.background = "#0d6276";
					  document.getElementById('3b').style.cursor = out_cursor_type;
					  break 
					
					case 4:
					  document.getElementById('4').style.color = out_textcolor; 
					  document.getElementById('4').style.cursor = out_cursor_type;
					  document.getElementById('4b').style.background = "#bbbcc0";
					  document.getElementById('4b').style.cursor = out_cursor_type;
					  break    
					
					case 5:
					  document.getElementById('5').style.color = out_textcolor; 
					  document.getElementById('5').style.cursor = out_cursor_type;
					  document.getElementById('5b').style.background = "#808185";
					  document.getElementById('5b').style.cursor = out_cursor_type;
					  break
					
					default:
					  break       
				} 
				
	  }
	  
	  else if (state == 'click')
	  {
		document.location.href = url; 
	  }
}
//--------------------------------------------------
function disp_confirm(n)
{	var record_name = "", value=false, user_had_selected_records = 0;
	
	
	for (X=1; X <= n; X++)
	{	
						
		value = document.forms['delete_form'].elements['delete_'+X].checked; 
		
		if (value)
		{
			user_had_selected_records = 1;
							
				if ( (document.getElementById('picture_name_1_'+X)) && (document.getElementById('picture_name_2_'+X)) )
				{
					//alert(document.getElementById('picture_name_1_'+X).value);
					//alert(document.getElementById('picture_name_2_'+X).value);
					
					if (document.forms['delete_form'].elements['picture_name_1_'+X].value)
					{
						document.forms['delete_form'].elements['picture_1'].value = document.forms['delete_form'].elements['picture_name_1_'+X].value;
						document.forms['delete_form'].elements['picture_2'].value = document.forms['delete_form'].elements['picture_name_2_'+X].value;
					}
				}
			
			if (record_name != "")
				{
					record_name = record_name + " ,  " + document.forms['delete_form'].elements['deleted_record_name_'+X].value;
				}
			else
			   	{
					record_name = document.forms['delete_form'].elements['deleted_record_name_'+X].value;
			   	}
		}
	} // End for loop

	if (user_had_selected_records == 1)
	{	
		var user_feedback=confirm("Do you really want to delete record(s) named: \n' "+record_name+" '")
			if (user_feedback==true)
				{
								
					document.delete_form.delete_confirmed.value = 1;
					
					document.delete_form.all_deleted_record_names.value = record_name;
					
					document.delete_form.submit();
					return 1;
				}
			else
				{
					//jsStr = document.location.href = 'index.php?task=delete';
					//return eval(jsStr)
					return 0;
				}
	}
	else
	{
		alert('Sorry! you have not selected any record to delete');
	}

}

//----------------------------------------------------------------


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

//----------------------------------------------------------------

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

//----------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//----------------------------------------------------------------

function MM_swapImgRestore() { //v3.0
  var i,x, y_1, z_1, a=document.MM_sr; 
  
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
   { 
  	x.src=x.oSrc;
   }
 	
	 z_1=document.getElementById('clearthumb_table').rows[1].cells;
	
	z_1[0].innerHTML= "";
	
}

//----------------------------------------------------------------

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
  
  for(i=0;i<2;i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2]; x.width = a[4]; x.height = a[5];}
   
   x.width = a[4];
   x.height = a[5];
  
  if ((x.width > 640) || (x.height > 300))
																	 
	 { 
																 
		if (x.width <= x.height)
			{
				ratio = x.width / x.height;
													
				while (x.height > 300) 
					{ 
						x.height	 = x.height * 0.99; 
						x.width  = x.height  * ratio; 
					} 
			}
		else 
					{
						ratio = x.height / x.width;
						while (x.width > 640)
						 { 
							x.width 	 = x.width * 0.99; 
							x.height  = x.width  * ratio ; 
							
						 } 
					 }
													
	  }
      
}


//----------------------------------------------------------------

function open_win(url, winwidth, winheight)
{

var width = 'width='+winwidth, height='height='+winheight, left='left='+((screen.availWidth/2)-(winwidth/2)), top='top='+((screen.availHeight/2)-(winheight/2));

var features = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no,"+width+", "+height+", "+left+", "+top;

window.open(url,"_blank", features);

}

//----------------------------------------------------------------
function switchtext(value)
{

	var x=document.getElementById('description_table');
	
	x.innerHTML= value;
	
}

//----------------------------------------------------------------
function switchtextclearthumb(value)
{
	var x=document.getElementById('clearthumb_table').rows[1].cells
	
	x[0].innerHTML= value;
}
//----------------------------------------------------------------

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flvFTLS9(){//v1.2
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4,v5,v6;v4=Math.floor(Math.random()*(v3.TLS6.length));v5=v3.TLS6[v4];v6=v3.TLS6.splice(v4,1);if (v3.TLS6.length<1){flvFTLS7(v2);}return v5;}

function flvFTLS8(){//v1.2
if (!Array.prototype.push){Array.prototype.push=function(){var v1=arguments;for(var v2=v1.length-1;v2>=0;v2--){this[this.length]=v1[v2];}return this.length;}}if (!Array.prototype.splice){Array.prototype.splice=function(){var v1=arguments,v3=new Array(),v4=new Array(),v5=0,v6=v1[0],v7=v1[1];for (v5=0;v5<v6;v5++){v3[v3.length]=this[v5];}for (v5=v6+v7;v5<this.length;v5++){v3[v3.length]=this[v5];}for (v5=0;v5<v7;v5++){v4[v4.length]=this[v6+v5];}this.length=0;for (v5=0;v5<v3.length;v5++){this[this.length]=v3[v5];}return v4;}}}

function flvFTLS7(){//v1.2
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4;v3.TLS6=new Array();for (v4=0;v4<v3.TLS4.length;v4++){v3.TLS6.push(v4);}}

function flvFTLS5(){//v1.2
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4=v1[1];if (v3&&v3.TLS4){flvFTLS4(v2);if (v4>v3.TLS4.length-1){v4=v3.TLS4.length-1;}else if (v4<0){v4=0;}v3.TLS11=v4;if (!v3.TLS9){v3.TLS5=new Image();}v3.TLS5.src=v3.TLS4[v4][0];flvFTLS3(v2,v4);}}

function flvFTLS6(){//v1.2
this.style.filter="";}

function flvFTLS4(){//v1.2
var v1=MM_findObj(arguments[0]);if (v1&&v1.TLS4&&v1.TLS2!=null){clearTimeout(v1.TLS2);}}

function flvFTLS3(){//v1.2
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4=v1[1],v5='<div class="slideImage">',v6,v7,v8;if (!v3.TLS5.complete){v6="flvFTLS3('"+v2+"',"+v4+")";setTimeout(v6,50);return;}if (v3.TLS4[v4][1]!=""){v5+='<a href="'+v3.TLS4[v4][1]+'"';if (v3.TLS3!=""){v5+=' target="'+v3.TLS3+'"';}v5+='>';}v5+='<img src="'+v3.TLS5.src+'" border="0" alt="">';if (v3.TLS4[v4][1]!=""){v5+='</a>';}v5+='</div>';if (v3.TLS4[v4][2]!=""){v5+='<div class="slideDesc">'+unescape(v3.TLS4[v4][2])+'</div>';}v7=v3.TLS4[v4][3];if (!v3.TLS1||v7==25){if (document.layers){v3.document.open();v3.document.write(v5);v3.document.close();}else {v3.innerHTML=v5;}}else {try {v3.contentEditable=true;if (v3.filters[0]&&v3.filters[0].status==2){v3.filters[0].Stop();}if (v7==0){v8="blendTrans(Duration="+v3.TLS10+")";}else {v8="revealTrans(Duration="+v3.TLS10+",Transition="+(v7-1)+")";}v3.onfilterchange=flvFTLS6;v3.style.filter=v8;v3.filters[0].Apply();v3.innerHTML=v5;v3.filters[0].Play();v3.contentEditable=false;}catch (e){v3.TLS1=false;flvFTLS3(v2,v4);}}}

function flvFTLS2(){//v1.2
var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4=v1[1],v5=v1[2],v6,v7,v8,v9;if (v3&&v3.TLS4){flvFTLS4(v2);if (v5==0||v3.TLS7==0){if (v4==1){v6=v3.TLS11+1;if (v6>v3.TLS4.length-1){v6=0;if (v3.TLS12==0){return;}}}else {v6=v3.TLS11-1;if (v6<0){v6=v3.TLS4.length-1;if (v3.TLS12==0){return;}}}}else {v6=v3.TLS11;while (v6==v3.TLS11){v6=flvFTLS9(v2);}}v3.TLS11=v6;if (!v3.TLS9){v3.TLS5=new Image();}v3.TLS5.src=v3.TLS4[v6][0];flvFTLS3(v2,v6);if (v5==1){v7="flvFTLS2('"+v2+"',"+v4+","+v5+")";v3.TLS2=setTimeout(v7,v3.TLS8);}}}

function flvFTLS1(){//v1.2

var v1=arguments,v2=v1[0],v3=MM_findObj(v2),v4,v5,v6,v7=navigator.userAgent.toLowerCase(),v8,v9;if (v3){flvFTLS8();v3.TLS8=v1[1];v5=v1[2];v3.TLS12=v1[3];v3.TLS3=v1[4];v3.TLS10=v1[5]/1000;v3.TLS7=v1[6];v3.TLS4=new Array();for (v6=7;v6<v1.length;v6+=4){v3.TLS4[v3.TLS4.length]=new Array(v1[v6],v1[v6+1],unescape(v1[v6+2]),parseInt(v1[v6+3]));}v9=0;if (v3.TLS7==1){flvFTLS7(v2);v9=flvFTLS9(v2);}v3.TLS11=v9;v3.TLS9=(v7.indexOf("netscape6")!=-1);v3.TLS5=new Image();v3.TLS5.src=v3.TLS4[v9][0];v3.TLS1=v3.filters&&(v7.indexOf("mac")<0);flvFTLS3(v2,v9);if (v5){v4="flvFTLS2('"+v2+"',1,"+v5+")";v3.TLS2=setTimeout(v4,v3.TLS8);}}}

