function movewin(win, width, height) {
	var fullWidth = screen.availWidth;
	var fullHeight = screen.availHeight;
	var x = (fullWidth / 2) - (width / 2);
	var y = (fullHeight / 2) - (height / 2);
	win.moveTo(x, y);
}

function viewWin(filenames, width, height) {
	filenames = filenames;

	var newwin = window.open(filenames, 'mydoc', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,maximize=0,width=' + width + ',height=' + height);

	movewin(newwin, width, height);
	if (navigator.appName == "Netscape")
		newwin.location = url;

	newwin.opener = window;
	newwin.focus();
	return false;
}



function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;

}

//Email check 
var testresults
function checkemail(email){
var str=email;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
 alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}

function chk_contact()
{
	var frm=document.contact;
  if(trimAll(frm.txtname.value)==""	)
  {
    alert("Please enter your name");
    frm.txtname.focus();
    return false;	
  }
  
  if(trimAll(frm.txtemail.value)==""	)
  {
    alert("Please enter your Email");
    frm.txtemail.focus();
    return false;	
  }
  else
  {
    var chk=checkemail(frm.txtemail.value);
    
    if (chk==false)
    {
      return false;	
    }
  }
  
  if(trimAll(frm.txtphone.value)==""	)
  {
    alert("Please enter your phone");
    frm.txtphone.focus();
    return false;	
  }
}
function chk_appointment()
{
  var frm=document.appointment;
  if(trimAll(frm.txtname.value)==""	)
  {
    alert("Please enter your name");
    frm.txtname.focus();
    return false;	
  }
  
  if(trimAll(frm.txtemail.value)==""	)
  {
    alert("Please enter your Email");
    frm.txtemail.focus();
    return false;	
  }
  else
  {
    var chk=checkemail(frm.txtemail.value);
    
    if (chk==false)
    {
      return false;	
    }
  }
  
  if(trimAll(frm.txtphone.value)==""	)
  {
    alert("Please enter your phone");
    frm.txtphone.focus();
    return false;	
  }
  
  
}

function chk_contact()
{
	var frm=document.contact;
  if(trimAll(frm.txtname.value)==""	)
  {
    alert("Please enter your name");
    frm.txtname.focus();
    return false;	
  }
  
  if(trimAll(frm.txtemail.value)==""	)
  {
    alert("Please enter your Email");
    frm.txtemail.focus();
    return false;	
  }
  else
  {
    var chk=checkemail(frm.txtemail.value);
    
    if (chk==false)
    {
      return false;	
    }
  }
  
  if(trimAll(frm.txtphone.value)==""	)
  {
    alert("Please enter your phone");
    frm.txtphone.focus();
    return false;	
  }
}
function chk_tour()
{
  var frm=document.tour;
  if(trimAll(frm.txtname.value)==""	)
  {
    alert("Please enter your name");
    frm.txtname.focus();
    return false;	
  }
  
  if(trimAll(frm.txtemail.value)==""	)
  {
    alert("Please enter your Email");
    frm.txtemail.focus();
    return false;	
  }
  else
  {
    var chk=checkemail(frm.txtemail.value);
    
    if (chk==false)
    {
      return false;	
    }
  }
  
  if(trimAll(frm.txtphone.value)==""	)
  {
    alert("Please enter your phone");
    frm.txtphone.focus();
    return false;	
  }
  
  
}


// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s
var IE;
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  
  return true
}
function show_position()
{
	
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
 IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;


var str = "xMousePos=" + tempX + ", yMousePos=" + tempY ;

var obj=document.getElementById("show");
//obj.innerHTML=str;
}

function show_div(dimage)
{
 
  var obj=document.getElementById("image_div");
   obj.style.visibility="visible";
    obj.style.width="410px";
   obj.style.left=tempX;
   obj.style.top=tempY-40;
   var img_obj=document.getElementById("img");
   img_obj.src="createimage.php?image="+dimage+"&width=400&height=400";
   
   
}

function hide_div()
{
	var obj=document.getElementById("image_div");
   obj.style.visibility="hidden";
}
