/**

 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)

 *

 * @param   string   container_id  the container id

 * @param   boolean  state         new value for checkbox (true or false)

 * @return  boolean  always true

 */

function setCheckboxes( container_id, state ) {

    var checkboxes = document.getElementById(container_id).getElementsByTagName('input');



    for ( var i = 0; i < checkboxes.length; i++ ) {

        if ( checkboxes[i].type == 'checkbox' ) {

            checkboxes[i].checked = state;

        }

    }



    return true;

} // end of the 'setCheckboxes()' function



function chkAll(frm, arr, mark) {

  for (i = 0; i <= frm.elements.length; i++) {

    try{

      if(frm.elements[i].name == arr) {

        frm.elements[i].checked = mark;

      }

    } catch(er) {}

  }

}





function submitForm(string)

{

return confirm(string);



var get_confirmed = confirm(string);

if(get_confirmed==true){

	return true ;

	}

else {

	return false ;

	

	}

	

}



function SelectAll(id)

{

  document.getElementById(id).focus();

  document.getElementById(id).select();

}





function switchField(divID,mark){

	var html = "";

	if (mark == 1) {

		html = '<input class="field" id="crop_url" name="crop_url" size="75" type="text">';

	}

	else if (mark == 0) {

		html = '<input class="field" id="crop_file" name="crop_file" size="75" type="file">';

	}

	else if (mark == 2) {

		html = '&nbsp; ';

	}

	document.getElementById(divID).innerHTML = html;

}



function scrollWindow(action)

{

	window.frames.thumb_output.scrollTo(0,500000);

	if (action == 'start') {

		t = setTimeout("scrollWindow('start')",10);

	}

	if (action == 'stop') {

		clearTimeout(t);

	}

}



function toggleDiv(divid,title){

    if(document.getElementById(divid).style.display == 'none'){

      document.getElementById(divid).style.display = 'block';

	  document.getElementById(title).className = 'extra_options expanded';

    }else{

      document.getElementById(divid).style.display = 'none';

	  document.getElementById(title).className = 'extra_options expandable';

    }

}



// disable field based on checkbox status

function DisBox(status,formid)

{

	

if(status)

{

document.getElementById(formid).value='';

document.getElementById(formid).disabled=true;

//document.getElementById(formid).style.display = 'none';

}

else

{

document.getElementById(formid).disabled=false;

//document.getElementById(formid).style.display = 'inline';

}

} 



var unghost = function() {

	if (!document.getElementById) return;

	var flds = document.getElementsByTagName('input');

	//var arr2 = document.getElementsByTagName('textarea');

	//alert (flds.length);

	//arr.concat(arr2);

	

	for (var i = 0; i < flds.length; i++) {

		

			if(document.all) {

				// IE

				flds[i].onClick = function() {

					alert ('hi');

					this.className = 'clear_background';

				}

			}

			else {

				flds[i].onfocus=function(){

					alert('hi');

					this.className = "clear_background"; return false

				}

			}

		

	} // end for

}

window.onload = unghost;



var marked_row = new Array;

var stripe = function() {



	if (!document.getElementById) return;

    var trs = document.getElementsByTagName('tbody');

 

    for (var i = 0; i < trs.length; i++) {

		  

	    if ( 'odd' != trs[i].className.substr(0,3) && 'even' != trs[i].className.substr(0,4) ) {

            continue;

        }

		

		// hover

		if(document.all) {

            // for IE

            trs[i].onmouseover = function() {

				this.className += ' hover';

            }

            trs[i].onmouseout = function() {

				this.className = this.className.replace( ' hover', '' );

            }

        }

		

		else {

	        trs[i].onmouseover=function(){

				this.className += " hover"; return false

   	     	}

   	     	trs[i].onmouseout=function(){

   	       		this.className = this.className.replace(' hover', ''); return false

   	     	}

		}

		

  	    // mark the row on click

		

		// Do not set click events if not wanted

       // if (trs[i].className.search(/noclick/) != -1) {

        //    continue;

        //}

		

        trs[i].onmousedown = function() {

            var unique_id;

            var checkbox;

			

            checkbox = this.getElementsByTagName( 'input' )[0];

            if ( checkbox && checkbox.type == 'checkbox' ) {

                unique_id = checkbox.name + checkbox.value;

            } else if ( this.id.length > 0 ) {

                unique_id = this.id;

            } else {

                return;

            }



            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {

                marked_row[unique_id] = true;

            } else {

                marked_row[unique_id] = false;

            }



            if ( marked_row[unique_id] ) {

                this.className += ' marked';

            } else {

                this.className = this.className.replace(' marked', '');

            }



            if ( checkbox && checkbox.disabled == false ) {

                checkbox.checked = marked_row[unique_id];

            }

        }

    }

}

















  function validateForm(myForm) {

    if (myForm == null)

      return false;



    //Loop through the form and validate

    for (var i = 0; i < myForm.length; i++) {

      var curElem = myForm.elements[i];

      if (curElem.getAttribute("req") == "true") {

	if (curElem.value == "") {

	  curElem.focus();

	  alert(curElem.name + " is missing");

	  return false;

	}

      }

      if (curElem.getAttribute("email") == "true") {

	var address = curElem.value;

	var check = (address.indexOf(".") > 2) && (address.indexOf("@") > 0);

	if (check != "1") {

	  alert ("email format is wrong");

	  return false;

	}

      }

      if (curElem.getAttribute("num") == "true") {

	if (isNaN(curElem.value)) {

	  curElem.focus();

	  curElem.select();

	  alert(curElem.name + " must be a number");

	  return false;

	}

	if (curElem.value < 0) {

	  curElem.focus();

	  curElem.select();

	  alert(curElem.name + " must be a positive number");

	  return false;

	}

	if (curElem.getAttribute("nummin")  != null) {

	  if ( (curElem.value-0) < (curElem.getAttribute("nummin")-0) ) {

	    curElem.focus();

	    curElem.select();

	    alert(curElem.name + " must be greater or equal to " + curElem.getAttribute("nummin") );

	    return false;

	  }



	}

	if (curElem.getAttribute("nummax")  != null) {

	  if ( (curElem.value-0) > (curElem.getAttribute("nummax")-0) ) {

	    curElem.focus();

	    curElem.select();

	    alert(curElem.name + " must be smaller or equal to " + curElem.getAttribute("nummax"));

	    return false;

	  }

	}

      }

    }



    return true;

  }









window.onload = stripe;



// GG related

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-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];}
}
