/* events */


function AllowOnly(eh,type,allow_space){
  if (allow_space==null) allow_space=false; else allow_space=true; 
  if(eh.charCode==0) return true;
  var unicode=eh.charCode? eh.charCode : eh.keyCode;
  if(allow_space && unicode==32)  
   	return true;
  switch(type)
  {
  case 'NUM_ONLY':
    if(unicode < 48 || unicode > 57) return false; else return true;
  case 'ALPHA_ONLY':
    if(unicode <65 || unicode >90) 
      if(!(unicode >= 97 && unicode <=122))
        return false;
      else
        return true;
  case 'ALPHA_NUM_ONLY':
   if(unicode >= 65 && unicode <= 90)
      return true;
   if(unicode >= 97 && unicode <= 120)
        return true;
   if(unicode >= 48 && unicode <= 57)
      return true;
   else
      return false;
   
  }
}

/* print specific functions */

	function Print(printPage, id, title)
	{
		if(title == '')
			title = document.title;
		var url = printPage + "@id=" + id + "&title=" + title
		var p = window.open(url, "print", "width=600, height=600, left=100, top=100, location=no, menubar=no, resizable=no, scrollbars=yes, status=no, toolbar=no, fullscreen=no");
	}

function GetData(id)
{
	var content = document.getElementById(id);
	if(content == null)
		return("");
	return(content.innerHTML);
}
	
function PrintThisPage(id, printId)
{
	var content = document.getElementById(printId);
	if(content == null)
		return;
	if(window.opener == null)
		return;
	var html = window.opener.GetData(id);
	html = DisableHyperlinks(html);
	content.innerHTML = html;
	make_visible();
	window.print();
}
	
function DisableHyperlinks(html)
{
	return(html.replace(/href\s*=\s*\"*[^\">]*"/ig,"href=\"#\""));
}

	
/* email specific functions */

	function Email(url)
	{
		url = url + "&page_title=" + document.title;
		var p = window.open(url, "email", "width=420, height=385, left=100, top=100, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, fullscreen=no");
	}


	var req=null;
		var READY_STATE_COMPLETE=4;
		
		function sendRequest(url, params, callback, HttpMethod)
		{
			if(!HttpMethod) {
				HttpMethod="GET";
			}
			req=initXMLHTTPRequest();
			if(req) {
				req.onreadystatechange=callback;
				req.open(HttpMethod,url,true);
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				req.send(params);
			}
		}
		function initXMLHTTPRequest()
		{
			var xRequest=null;
			if(window.XMLHttpRequest) {
				xRequest=new XMLHttpRequest();
			}
			else if(window.ActiveXObject) {
				xRequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			return(xRequest);
		}
	 	
		function openpage()
		{
			var url = 'wp-content/includes/ajax-permalink.php';
			if(document.getElementById('collection').value != 0 ) {
					var params = 'id=' + document.getElementById('collection').value;
					url = url + '?' + params;
					
				} else {			
					return false;	
			}
		}
		
		function onReadyState()
		{
			var ready=req.readyState;
			var data=null;
			if (ready==READY_STATE_COMPLETE) {
				data=req.responseText;
				//openpage(data);
				//document.getElementById('msgshow').innerHTML = data;
				//document.getElementById('msgshow').style.display='inline';
				//alert(''+data);
				
				document.getElementById('emailtxt').value = 'Email';
				document.getElementById('firstnametxt').value = 'First Name';
				document.getElementById('lastnametxt').value = 'Last Name';
				window.location.href = "thank-you/@message="+data;
				
			}
		}

		
function isValidEmail(str) {
		filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		return(filter.test(str));
	
	}
	
	function signup() {
		var url = 'wp-content/includes/ajax-newsletter.php';
		//var msgshow = document.getElementById('msgshow');
		var email = '';var firstname = ''; var lasttname ='';
		email = document.getElementById('emailtxt').value;
		firstname = document.getElementById('firstnametxt').value;
		lastname = document.getElementById('lastnametxt').value;
		//alert(email+firstname+lastname);
		if(firstname == 'First Name') {
			alert('First name required.');
			document.getElementById('firstnametxt').focus();
			return false;
		}
		if(lastname == 'Last Name') {
			alert('Last name required.');
			document.getElementById('lastnametxt').focus();
			return false;
		}				
		if(email == 'Email') {
		    alert('Email required.')
			document.getElementById('emailtxt').focus();
			return false;
		} else {
			if(!isValidEmail(email)) {
				alert('Valid email required.');
				document.getElementById('emailtxt').focus();
				return false;
			}
		}
		var params = '';
		params = 'firstname=' + firstname + '&lastname=' + lastname + '&emailid=' + email + '&lang=en';
		url = url + '?' + params;
		sendRequest(url, '', onReadyState, 'GET');
		return false;
	}
	
function toggleTextOut(e,txtval) {
	if(e.value=="") e.value = txtval;
	
}
function toggleTextIn(e,txtval) {
	if(e.value==txtval) e.value="";
	else e.select();
}

function PreloadImage()
{ 
  	var args = PreloadImage.arguments;
 	document.imageArray = new Array(args.length);
 	for(var i=0; i<args.length; i++)
	{
	document.imageArray[i] = new Image;
	document.imageArray[i].src = args[i];
  	}
}
