// JavaScript Document
//---------------------------------------------------------------- Function For  Check All / Uncheck All
function Checkall(eform)
{ 
	oElement = eform.elements['select_unselect'];
	
  for (var i = 0; i < eform.elements.length; i++)
  {    
    //eval("form.elements[" + i + "].checked = oElement.checked"); 
	
	ObjOption = eform.elements[ + i ];
	//alert(ObjOption);
	ObjOption.checked = oElement.checked;
	
   } 
} 
//---------------------------------------------------
function toggleChecked(oElement) 
{ 
  oForm = oElement.form; 
  oElement = oForm.elements[oElement.name]; 
  if(oElement.length) 
  { 
    bChecked = oElement[0].checked; 
    for(i = 1; i < oElement.length; i++) 
      oElement[i].checked = bChecked; 
  } 
} 

function emulate(e) 
{ 
	for (var i=0, option; option = e.options[i]; i++) 
	{ 
		if (option.disabled) 
		{ 
			option.style.color = "#CCCCCC"; 
		} 
		else 
		{ 
			option.style.color = "#FFFFFF"; 
		} 
	} 
} 

//----------------------------------------------------------------
function redirect(URLStr) 

{ 
	window.location = URLStr; 
}

//----------------------------------------------------------------

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);

}

//-------------------------------------------------------------------------- Articles Management

function formSubmit_articles_update()
	{
		document.getElementById("MM_update").value = "updatearticle";
		MM_validateForm('Name','','R','edition_title','','R', 'IssueNumber','','R');
		document.MM_returnValue = true;
		document.getElementById("updateform").submit();
	}

function formSubmit_articles()
	{
		document.getElementById("MM_insert").value = "addarticle";
		document.MM_returnValue = true;
		document.getElementById("addform").submit();
	}
function MainFormSubmit()
	{
		MM_validateForm('Name','','R','edition_title','','R', 'IssueNumber','','R');
	}

//-------------------------------------------------------------------------- Photos  Management


function formSubmit_photos_update()
	{
		document.getElementById("MM_update").value = "updatephoto";
		
		 MM_validateForm('MenuItemName','','R','MemberName','','R','MemberUserName','','R','MemberPassword','','R','HeadOfficePostcode','','NisNum','PostalPostcode','','NisNum','MemberContactEmail','','R');
		document.MM_returnValue = true;
		document.getElementById("updateform").submit();
	}

function formSubmit_photos()
	{
		document.getElementById("MM_insert").value = "addphoto";
		document.MM_returnValue = true;
		document.getElementById("addform").submit();
	}
function formSubmit()
	{
		//alert(document.getElementById("MM_insert").value)
		//MM_validateForm('product_title','','R','colour_type','','R','colour_density','','R','red_gy','','R','grn_gy','','R','blue_gy','','R','hex_gy','','R')
		 MM_validateForm('MenuItemName','','R','MemberName','','R','MemberUserName','','R','MemberPassword','','R','HeadOfficePostcode','','NisNum','PostalPostcode','','NisNum','MemberContactEmail','','R');
	}

//--------------------------------------------------------------------------
function assign_same_value(n, m, myform)
{
	//alert(myform);	
	
	switch(myform)
		{
		case 'updateform':
							  if (document.forms['updateform'].elements['SubjectTopicCheckbox_'+m].checked)
								  {
									document.forms['updateform'].elements['SubjectTopic_'+m].value = document.forms['updateform'].elements['SubjectTopic_'+n].value;
								  }
							  else
							  	  {
									document.forms['updateform'].elements['SubjectTopic_'+m].value = '';  
								  }
							  break    
		case 'addform':
							  if (document.forms['addform'].elements['SubjectTopicCheckbox_'+m].checked)
								  {
									document.forms['addform'].elements['SubjectTopic_'+m].value = document.forms['addform'].elements['SubjectTopic_'+n].value;
								  }
							  else
							  	  {
									document.forms['addform'].elements['SubjectTopic_'+m].value = '';  
								  }
							  break   
		default:
		  		break
		}
}

//--------------------------------------------------------------------------

function assign_headoffice_values_to_postal(form_name)
{
	//alert(form_name);
	
	if ( form_name == 'addform')
			{
			
					if (document.addform.same_info_as_headoffice_info.checked)
					//if ( (document.updateform.same_info_as_headoffice_info.checked) || (document.addform.same_info_as_headoffice_info.checked) )
					
					{
						//alert(document.getElementById("firstname").value);
						document.getElementById("PostalAddress").value = document.getElementById("HeadOfficeAddress").value;
						document.getElementById("PostalSuburb").value = document.getElementById("HeadOfficeSuburb").value;
						document.getElementById("PostalState").value = document.getElementById("HeadOfficeState").value;
						document.getElementById("PostalPostcode").value = document.getElementById("HeadOfficePostcode").value;
						document.getElementById("PostalCountry").value = document.getElementById("HeadOfficeCountry").value;
					}
					
					 else 
					
					{
					
						document.getElementById("PostalAddress").value = '';
						document.getElementById("PostalSuburb").value = '';
						document.getElementById("PostalState").value = '';
						document.getElementById("PostalPostcode").value = '';
						document.getElementById("PostalCountry").value = '';
					}
			  }
	
	if ( form_name == 'updateform')
			{
			
					if (document.updateform.same_info_as_headoffice_info.checked)
					//if ( (document.updateform.same_info_as_headoffice_info.checked) || (document.addform.same_info_as_headoffice_info.checked) )
					
					{
						//alert(document.getElementById("firstname").value);
						document.getElementById("PostalAddress").value = document.getElementById("HeadOfficeAddress").value;
						document.getElementById("PostalSuburb").value = document.getElementById("HeadOfficeSuburb").value;
						document.getElementById("PostalState").value = document.getElementById("HeadOfficeState").value;
						document.getElementById("PostalPostcode").value = document.getElementById("HeadOfficePostcode").value;
						document.getElementById("PostalCountry").value = document.getElementById("HeadOfficeCountry").value;
					}
					
					 else 
					
					{
					
						document.getElementById("PostalAddress").value = '';
						document.getElementById("PostalSuburb").value = '';
						document.getElementById("PostalState").value = '';
						document.getElementById("PostalPostcode").value = '';
						document.getElementById("PostalCountry").value = '';
					}
			  }
}

//---------------------------------------------------------------------------------
function disable_me(formfieldname) {
document.addform.formfieldname.disabled = true;
}

function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}


//--------------------------------------------------
function disp_confirm(n)
{	var record_name = "", value=false, user_had_selected_records = 0;
	
	
	//alert(n);
	for (X=1; X <= n; X++)
	{	
		if (document.forms['delete_form'].elements['delete_'+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');
	}

}

//----------------------------		Customized MM_validateForm function     ------------------------------//

function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; //alert(args.type);
  
  for (i=0; i<(args.length-2); i+=3) 
  { 
  	
	test=args[i+2]; 
	val=MM_findObj(args[i]);
    
	if (val) 
	{ 
		nm=val.name; 
		nmID=val.id; 					
		if (nmID != '')		// Change  start 
		{
			nm = nmID;			
		}					// Change  End 
		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 ------------------------------------- \n'+errors); }
  		
  document.MM_returnValue = (errors == '');
}

//---------------------------------------------------------------- Help File(s) Opener Funtions

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 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);}}}

function LoadflvFTLS1()
{

flvFTLS1('slideContainer',3500,1,1,'',20000, 5,'images/home_images/home_image01.jpg','','',3,'images/home_images/home_image02.jpg','','',11,'images/home_images/home_image03.jpg','','',13,'images/home_images/home_image04.jpg','','',24);
}