/* Code by PHPPat @ www.php-tools.net & W-agora @ www.w-agora.com*/
function getTip(txt)
{
document.getElementById('tip').innerHTML=txt
}
function resetTip()
{
document.getElementById('tip').innerHTML="&nbsp;"
}

var displaystates = new Array();
function toggleMenu( nr )
{
  var d  = document.getElementById( "details"+nr );
   if( displaystates[nr] == "open" )
  {
    d.style.display  = "none";
    displaystates[nr] = "closed";
  }
  else if( displaystates[nr] == "closed" )
  {
    d.style.display  = "block";
    displaystates[nr] = "open";
  }
  else
  {
    d.style.display  = "block";
    displaystates[nr] = "open";
  }
window.focus(); 
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

var newWindow = null;
    function OpenWindow (Url,Title,Width,Height) {
    var win_opt= 'toolbar=0,location=0,directories=0,status=0,menubar=0,';
    win_opt += 'scrollbars=1,resizable=1,copyhistory=0,';
    win_opt += 'width=' + Width + ',height=' + Height;
    var windowX = (screen.width/2)-(Width/2);
    var windowY = (screen.height/2)-(Height/2); 
    window.name = 'MainWindow';    
    newWindow = window.open('',Title,win_opt);
     if (newWindow != null) {
     if (newWindow.opener == null)
     newWindow.opener = self;
     newWindow.location.href = Url;
     newWindow.moveTo(windowX,windowY);     
     if (newWindow.focus) newWindow.focus();
  }
}

function trimLeft(s) {
	var whitespaces = " \t\n\r";
	for(n = 0; n < s.length; n++) { 
		if (whitespaces.indexOf(s.charAt(n)) == -1) 
			return (n > 0) ? s.substring(n, s.length) : s; 
	}
	return("");
}
function trimRight(s){
	var whitespaces = " \t\n\r";
	for(n = s.length - 1; n  > -1; n--) { 
		if (whitespaces.indexOf(s.charAt(n)) == -1) 
			return (n < (s.length - 1)) ? s.substring(0, n+1) : s; 
	}
	return("");
}
function trim(s) {
	return ((s == null) ? "" : trimRight(trimLeft(s))); 
}
function isBlank(field, ErrorMsg) {
	var strTrimmed = trim(field.value);
	if (strTrimmed.length > 0) return false;
	alert(ErrorMsg);
	field.focus();
	return true;
}
function isBlankRadio(field, ErrorMsg) {
	if (returnSelection(field) == null) {
		alert(ErrorMsg);
		return true;
	} else {
		return false;
	}
}
function isBadURL(field, ErrorMsg) {
	var strTrimmed = trim(field.value);
	if (strTrimmed.length == 0 || 
		strTrimmed.substring(0,7) == 'http://' || 
		strTrimmed.substring(0,6) == 'ftp://' || 
		strTrimmed.substring(0,7) == 'mailto:' || 
		strTrimmed.substring(0,8) == 'https://') return false;
	alert(ErrorMsg);
	field.focus();
	return true;
}

function isPhone(field, ErrorMsg) {
	var strVal = trim(field.value);
	phoneReg = "^(?:[\(][0-9]{3}[\). ]|[0-9]{3})[-. ]?[0-9]{3}[-. ]?[0-9]{4}$";
	var regex = new RegExp(phoneReg);
	if (regex.test(field.value)) {
		return true;
		}
	else {
		alert(ErrorMsg);
		field.focus();
		return false;
		}
	return true;
	}

function isEmail(field, ErrorMsg) {
	var strMsg = ""; 
	var chAt  = '@'; 
	var chDot = '.'; 
	var strEmailAddr = trim(field.value);
	   if (strEmailAddr.length == 0) return true;
	   if (strEmailAddr.indexOf(" ") == -1)
	   {
	       var iFirstAtPos = strEmailAddr.indexOf(chAt);
	       var iLastAtPos = strEmailAddr.lastIndexOf(chAt);
	       if (iFirstAtPos > 0 && iFirstAtPos < (strEmailAddr.length - 1) &&iFirstAtPos == iLastAtPos) {
		   // look for '.' there must be at least one char between '@' and '.'
		   var iDotPos = strEmailAddr.indexOf(chDot, iFirstAtPos + 1);
		   if (iDotPos > (iFirstAtPos + 1) && iDotPos < (strEmailAddr.length -1)) return true;
	       }
	   }
	   alert(ErrorMsg);
	   field.focus();
	   return false;
}

function isFirstOption(field, ErrorMsg) {
	if (field[0].selected) {
		alert(ErrorMsg);
		return true;
	} else {
		return false;
	}
}

function returnSelection(radioButton) {
	var selection=null;
	for(var i=0; i<radioButton.length; i++) {
		if(radioButton[i].checked) {
			selection=radioButton[i].value;
			return selection;
		}
	}
	return selection; 
}

var counter=0; 

function isReady() {
	var _ret=false;
	if (validate_form())
	  _ret=true;
	else
	  _ret=false;
	if(_ret)
	  if(counter++)
	  {
	    _ret=false;
	    alert('The Form Is Already Being Submitted'); 
	  }
	  else
	    _ret=true;
	alert(_ret);
	return _ret; 
} 
