﻿/***********************************************
* Dynamic Ajax Content- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}



      //----------

      function addEvent(obj ,evt, fnc)
      {
        if (obj.addEventListener)
          obj.addEventListener(evt,fnc,false);
        else if (obj.attachEvent)
          obj.attachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      function removeEvent(obj ,evt, fnc)
      {
        if (obj.removeEventListener)
          obj.removeEventListener(evt,fnc,false);
        else if (obj.detachEvent)
          obj.detachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      //----------

      function appendElement(node,tag,id,htm)
      {
        var ne = document.createElement(tag);
        if(id) ne.id = id;
        if(htm) ne.innerHTML = htm;
        node.appendChild(ne);
      }

      //----------

      function showPopup(p, divname, filename)
      {
		var xp, yp, op

		var scrolledX, scrolledY;
		if( self.pageYoffset ) {
		scrolledX = self.pageXoffset;
		scrolledY = self.pageYoffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		scrolledX = document.documentElement.scrollLeft;
		scrolledY = document.documentElement.scrollTop;
		} else if( document.body ) {
		scrolledX = document.body.scrollLeft;
		scrolledY = document.body.scrollTop;
		}
		
		// Next, determine the coordinates of the center of browser's window
		
		var centerX, centerY;
		if( self.innerHeight ) {
		centerX = self.innerWidth;
		centerY = self.innerHeight;
		} else if( document.documentElement && document.documentElement.clientHeight ) {
		centerX = document.documentElement.clientWidth;
		centerY = document.documentElement.clientHeight;
		} else if( document.body ) {
		centerX = document.body.clientWidth;
		centerY = document.body.clientHeight;
		}

		// Xwidth is the width of the div, Yheight is the height of the
		// div passed as arguments to the function:
		var xp = scrolledX + (centerX - 900) / 2;
		var yp = scrolledY + (centerY - 400) / 2; 
		
        greyout(true);
		ajaxpage(filename, 'popupbody');
		loadobjs('formvalidation.js')
        document.getElementById(p).style.display = 'block';
		document.getElementById(p).style.top = yp+'px';
		document.getElementById(p).style.left = xp+'px';
		//var IfrRef = document.getElementById('Someiframe');	
		var DivRef = document.getElementById(p);
		//IfrRef.style.width = DivRef.offsetWidth;
		//if (DivRef.offsetHeight > 23)
		//{
		//IfrRef.style.height = DivRef.offsetHeight;
		//}
		//IfrRef.style.top = yp+'px';
		//IfrRef.style.left = xp+'px';
		//IfrRef.style.zIndex = DivRef.style.zIndex +1;
		//IfrRef.style.display = "block"; 
      }

      function hidePopup(p)
      {
		if (needToConfirm== true && disp_confirm("Changes will be lost if you don't click on the 'Save'-button.  Click OK to stay on this page, click Cancel to continue without saving.")==true)
			 {
			 }
		else
		{
				needToConfirm=false;
				greyout(false);
				ajaxpage('blank.htm', 'popupbody'); //clear the contant in the container
				document.getElementById(p).style.display = 'none';
				//document.getElementById('Someiframe').style.display = 'none';
		}
      }

      //----------

      function greyout(d,z)
      {
        var obj = document.getElementById('greyout');
        if(!obj)
        {
          appendElement(document.body,'div','greyout');
          obj = document.getElementById('greyout');
          obj.style.position = 'absolute';
          obj.style.top = '0px';
          obj.style.left = '0px';
          obj.style.background = '#333';
          obj.style.opacity = '.5';
          obj.style.filter = 'alpha(opacity=50)';
        }
        if(d)
        {
          if(!z){ z - 50 }
          //obj.style.zIndex = z;
          obj.style.height = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)+'px';
          obj.style.width  = Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth)+'px';
          obj.style.display = 'block';
          addEvent(window,'resize',greyoutResize);
        }
        else
        {
          obj.style.display = 'none';   
          removeEvent(window,'resize',greyoutResize);
        }
      }
     
      function greyoutResize()
      {
        var obj = document.getElementById('greyout');
        obj.style.height = document.body.clientHeight+'px';
        obj.style.width  = document.body.clientWidth+'px';
        obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
        obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
      }
function disp_confirm(txt)
{
	var name=confirm(txt)
	if (name==true)
	{
		return (true)
	}
	else
	{
		return (false)
	}
}
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}
function trim12 (str) {
	
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}


      //----------
