// JavaScript Document
function confirmDelete(layerName, useed) {

var okayd=confirm("Are you sure you want to delete " + layerName + "?");
if(okayd) {
 document.location.href="update_layers.php?useed=" + useed + "&layer=" + layerName;
}
else
	return false;
}

function confirmEdit(layerName, useed, theid) {

var okayd=confirm("Are you sure you want to edit " + layerName + "?");
if(okayd) {
 document.getElementById("ctrl_form").useed.value = useed;
 document.getElementById("ctrl_form").mode.value = "edit";
 document.getElementById("ctrl_form").lID.value = theid;
 document.getElementById("ctrl_form").layer.value = layerName;
 //alert(document.getElementById("ctrl_form").useed.value);

  document.getElementById("ctrl_form").submit();
  //alert(document.getElementById("ctrl_form").layer.value);
 //document.location.href="publisher.php?mode=edit&useed=" + useed + "&layer=" + layerName;
}
else
	return false;
}

function changeCursor(cursorThing) {

if(document.all) {
 cursorThing.style.cursor = "hand";
}

else {
 cursorThing.style.cursor = "pointer";
}

}

function previewWindow(gotoUrl)
{

//alert(gotoUrl);

WindowName="GLIN_Preview_Window";

settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width=670,height=430";

MyNewWindow=window.open(gotoUrl,WindowName,settings);
}

function mapIt(a,b,c)
{

//alert(gotoUrl);

gotoUrl = "http://gis.glin.net/mapit3.php?title=" + a + "&style=" + b + "&extent= " + c;

WindowName="GLIN_Preview_Window";

settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width=670,height=430";

//alert(a + " and "  + b + " and " + c);

MyNewWindow=window.open(gotoUrl,WindowName,settings);
}

function getMeta(layerN) {
WindowName="GLIN_Preview_Window";

gotoUrl = "http://gis.glin.net/ogc/metadata/publish/" + layerN + ".xml"

settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width=670,height=430";

MyNewWindow=window.open(gotoUrl,WindowName,settings);
}


function previewMeta(text)
{

WindowName="GLIN_Preview_Window";
//gotoUrl="about:blank";
gotoUrl = "http://gis.glin.net/ogc/metadata/publish/" + text;

settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=no,width=630,height=430";

MyNewWindow=window.open(gotoUrl,WindowName,settings);
MyNewWindow.focus();
//MyNewWindow.document.write(text);
}


function trimString(s)
{
 return s.replace(/^\s*|\s*$/g,"");
}

function checkDataName(theform)
{
 var result = true;
 var n = trimString(theform.dataset.value);
 if(n=="") {
  alert("Please fill the Data set name field!");
  result=false;
 }

 else {
  badchars = /[^a-zA-Z0-9_]/;  // want to match all character but not letters,underscore,single quote,digits
  if(badchars.test(n)){
   alert("Dataset Name can only contain letters,digits and underscores!");
   result=false;
 }

  else {
    if(n[0]=="_") {
     alert("Dataset Name can not start with underscores!");
     result=false;
    }

   else {
    if(n.length<4) {alert("Dataset Name should contain at least 4 characters!");
    result=false;}
   }
  }
 }

 return result;

}

// form validation

function vForm(thisform)
{
 return (checkDataName(thisform));
}

function newImage(arg) {
        if (document.images) {
                rslt = new Image();
                rslt.src = arg;
                return rslt;
        }
}

function changeImages() {
        if (document.images && (preloadFlag == true)) {

               for (var i=0; i<changeImages.arguments.length; i+=2) {
                        document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
                }
        }
}

var preloadFlag = false;
function preloadImages() {
        if (document.images) {
                glakes_in_01_over = newImage("http://www.glin.net/graphics/rollover/glakes_inOver.gif");
                preloadFlag = true;

				econ_in_over = newImage("http://www.glin.net/graphics/rollover/econ_inOver.gif");
                preloadFlag = true;

				teach_in_over = newImage("http://www.glin.net/graphics/rollover/teach_inOver.gif");
                preloadFlag = true;

				gis_in_over = newImage("http://www.glin.net/graphics/rollover/gis_inOver.gif");
                preloadFlag = true;

				tourism_in_over = newImage("http://www.glin.net/graphics/rollover/tourism_inOver.gif");
                preloadFlag = true;
        }
}
function popimage(imagesrc,winwidth,winheight){

		var look='width='+winwidth+',height='+winheight+','

				popwin=window.open("","",look)

				popwin.document.open()

				popwin.document.write('<title>Image Window</title><body><img src="'+imagesrc+'"></body>')

				popwin.document.close()

		}

