// JavaScript Document

function areyousure(linkk) {
	if ( confirm("Are you sure?") ) {
		document.location.href=linkk;
	}
}

function isValidEmail(strg) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strg)){
		return (true);
	}
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

function Cache(url) {
	var MyImage = new Image();
	MyImage.src = url;
	return MyImage;
}

function showhide(id) {
	ob=document.getElementById(id);
	if ( ob.style.display=='' ) {
		ob.style.display='none';
	} else {
		ob.style.display='';
	}
}



function previewTemplate(id){
	//alert("id:"+id);
	window.open('previewTemplate.php?id='+id,'previewTemplate','width=800, height=600, scrollbars=1');
}




function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
    if (!dark) alert('ERROR!!');
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+15+'px';
        var pageHeight = (3*(document.body.scrollHeight+15))+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+15+'px';
      var pageHeight = document.body.offsetHeight+15+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}








function JS_badcharr(p,searchchar) {
	rett=false;
	//searchchar="|!#$%&()/=?'\+*~{}[]^`:;<>";
	for (i=0; i <= searchchar.length-1; i++){
		charr=searchchar.charAt(i);
		if ( p.indexOf(charr) != -1 ) {
			rett=true;
		} 
	}
	return rett;
}

function JS_badchar_upload(p) {
	rett=false;
	searchchar=":*?<>|";
	for (i=0; i <= searchchar.length-1; i++) {
		if ( p.search((searchchar.charAt(i))) != -1 ) {
			rett=true;
		} 
	}
	return rett;
}
