/*print preview*/
function togglePrintPreview()
{

	var togglePrintLink = document.getElementById('printLink');
	var currCSS = document.getElementById('printCSS');
	if(currCSS.media == 'screen') {currCSS.media = 'print'; togglePrintLink.innerHTML = 'Print preview';} else {currCSS.media = 'screen'; togglePrintLink.innerHTML = 'Back';}
}

function togglePrintLink()
{
	var currCSS = document.getElementById('printCSS');
	if(currCSS.media == 'screen') {document.write('Back');} else {document.write('Print preview');}
}


/*frame breaker*/
if (parent.frames.length > 0) top.location.replace(document.location);


/*for click all checkboxes*/
function chkBoxes(form) {
	var state;
	for (i=0;i<form.elements.length;i++) {
	var obj = form.elements[i];
		if (obj.type == 'checkbox') {
		state = obj.checked; // true or false
		obj.checked = (state==true)?false:true;
		}
	}
}

/* for identity - select all checkboxes*/
function select(a) {
    var theForm = document.myForm;
    for (i=0; i<theForm.elements.length; i++) {
        if (theForm.elements[i].name=='chkCids[]')
            theForm.elements[i].checked = a;
    }
}



/* gallery */
function switch_img(divName, totalImgs) {
	for (var i=0; i < totalImgs; i++) {
		var showDivName = 'photo_' + i;
		var showObj = document.getElementById(showDivName);
		if (showDivName == divName) {
			showObj.style.display = 'block';
		} else {
			showObj.style.display = 'none';
		}
	}
}

function switch_th(divName, totalPages) {
	for (var i=0; i < totalPages; i++) {
		var showDivName = 'th_' + i;
		var showObj = document.getElementById(showDivName);
		if (showDivName == divName) {
			showObj.style.display = 'block';
		} else {
			showObj.style.display = 'none';
		}
	}
}
/* end gallery */



/*for region dropdown */
/*
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
*/


/* for show/hide div on fabric search */
/* 
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
*/


/* show/hide password fields */
window.onload = function() 
{
	if(document.getElementsByTagName) 
	{
		var inputs = document.getElementsByTagName('input');
		
		for(var i in inputs) 
		{
			var input = inputs[i];
		
			if(input.type == 'password') 
			{
				toggle_control = document.createElement('label');
				toggle_control.innerHTML = "<input type=\"checkbox\" "+
				"onclick=\"toggle_password('"+
				input.id+"',this.checked)\" />"+
				"show/hide";
				input.parentNode.insertBefore(toggle_control, input.nextSibling);
			}
		}
	}
}

function toggle_password(element_id, show_text) 
{
	if(document.getElementById) 
	{
		var password_input = document.getElementById(element_id);
		var new_input      = document.createElement('input');
		
		with(new_input) 
		{
			id = password_input.id;
			name = password_input.name;
			value = password_input.value;
			size = password_input.size;
			className = password_input.className;
			type = show_text ? 'text' : 'password';
		}
	
		password_input.parentNode.replaceChild(new_input,password_input);
	}
}
/* END show/hide password fields */
