/**
'********************************************************************************************
'Modules Name		:	Common JavaScript Functions
'Client Name		:	South Florida Fair & Palm Beach County Expositions, Inc. USA.
'Design By			:	
'********************************************************************************************
'Form Name			:	COMMON.JS
'Description		:	Common JavaScript Functions
'Developed By		:	Raj Shah
'Creation Date		:	08/13/2003
'Modified By		:	Raj Shah
'Modification Date	:	08/20/2003
'No of Modification	:	6
'********************************************************************************************
*/

// Validation for EMAIL
function isEmail(objObject) {
	var regEmail, strValue;	
	regEmail =/^([A-Za-z0-9]{1})([A-Za-z0-9_.\-]*)([A-Za-z0-9]{1})(@)([A-Za-z0-9]{1})([A-Za-z0-9_.\-]*)([A-Za-z0-9]{1})(\.)([A-Za-z]{1})([A-Za-z]*)$/
	strValue = objObject.value;
	if (objObject.value == "") return true;
	if(! regEmail.test(strValue)) {
		objObject.focus();
		return false;
	}
	return true;
}
//Validation for IP Address
function isIPValidate(objObject){	
	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var strValue = objObject.value
	errorString = "";
	var ipArray = strValue.match(ipPattern);	
	if (strValue == "0.0.0.0" || strValue == "255.255.255.255"){
		errorString = 'You can not use special IP address\ni.e 0.0.0.0 and 255.255.255.255';
	}
	if (ipArray == null){
		errorString = 'Please enter valid IP address.';
	}else {
		for (i = 0; i < 4; i++){
			thisSegment = ipArray[i];
			if (thisSegment > 255){
				errorString = 'Please enter a valid IP address.';
				i = 4;
			}
			if ((i == 0) && (thisSegment > 255)){
				errorString = 'You can not use special IP address\ni.e 0.0.0.0 and 255.255.255.255';
				i = 4;
			}
		}
	}
	extensionLength = 3;
	if (errorString == ""){
		return true;
	}else{
		alert (errorString);
		return false;
	}
}
// Trim Function
function Trim(strVal) {
    var strMatch = strVal.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    result = (strMatch == null) ? "" : strMatch[1];
    return result;
}
//New Window Open Function
function NewWindow(url,ht,wd,name){
	param = "height="+ht+",width="+wd+",location=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=20,left=100";
	oc_infowin=window.open(url,name,param);
	if (oc_infowin != null){
		oc_infowin.opener = self;
	}
	oc_infowin.focus();
}
//Window Resize and Move Function
function Resize(ht,wd,lt,tp){	
	self.resizeTo(ht,wd);
	self.moveTo(lt,tp);	
	return true;
}
// KeyCheck Function
function keyCheck(objEvent,objObject, strType, strCase, strSpecialChars) {	
	var intKeycode, intLen;
	intKeycode=objEvent.keyCode;
	var strObjvalue=objObject.value;
	if (!strSpecialChars) 
		strSpecialChars="";
	if (!strCase)
		strCase="";
	if (!strType)
		strType="";

	intLen = strSpecialChars.length;
	if (intKeycode==34 && strSpecialChars.indexOf('D') != -1) // for the quotes.
			return true;
	if (intKeycode==39 && strSpecialChars.indexOf('S') != -1) // from the apostrophe.
			return true;

	if (strType == "AN") {
		if (!( (intKeycode>=65 && intKeycode<=90)  ||
		       (intKeycode>=97 && intKeycode<=122) ||
		       (intKeycode>=48 && intKeycode<=57)  ||
		       (intKeycode==32) )) { 
		       	
			if(intLen != 0) 
				for(i=0; i<intLen; i++)
					if(strSpecialChars.charAt(i) == String.fromCharCode(intKeycode)) 
						return true;
			event.returnValue=false;
			objObject.value = strObjvalue;
			return false; 
		}
	}
	if (strType == "AL") {
		if (!( (intKeycode>=65 && intKeycode<=90)  ||
		       (intKeycode>=97 && intKeycode<=122) ||
		       (intKeycode==32) ) ) {
		       	
			if(intLen != 0) 
			for(i=0; i<intLen; i++)
				if(strSpecialChars.charAt(i) == String.fromCharCode(intKeycode)) 
					return true;

			event.returnValue=false;
			objObject.value = strObjvalue;
			return false;
		}
	}
	if (strType == "NM") {
		if (!( (intKeycode>=48 && intKeycode<=57)  ||
		       (intKeycode==32) )) { 
		       	
			if(intLen != 0) 
			for(i=0; i<intLen; i++)
				if(strSpecialChars.charAt(i) == String.fromCharCode(intKeycode)) 
					return true;
					
			event.returnValue=false;
			objObject.value = strObjvalue;
			return false; 
		}
	}
	if (strType == "BL") {
		if (!(intKeycode==110 || intKeycode==121 || intKeycode==78 || intKeycode==89)) {
				event.returnValue=false;
				objObject.value = strObjvalue;
				return false;
		}
	}
	if (strType == "") {
		if (!( (intKeycode>=65 || intKeycode<=90)  &&
		       (intKeycode>=97 || intKeycode<=122) &&
		       (intKeycode>=48 || intKeycode<=57)  &&
		       (intKeycode==32) )) { 
				
			if(intLen != 0) 
				for(i=0; i<intLen; i++)
					if(strSpecialChars.charAt(i) == String.fromCharCode(intKeycode)) 
					return true;
				event.returnValue=false;
				objObject.value = strObjvalue;
				return false; 
		}
	}
	if(strCase == 'U')
		changeCase("U");
	else if(strCase == 'L')
		changeCase("L");
	
	return true;
}
// Change Character Case Function
function changeCase(strCase) {
	if (event.keyCode>=97 && event.keyCode<=122) {
		if (strCase=='U')
			event.keyCode = event.keyCode-32;
	}
	else if (event.keyCode>=65 && event.keyCode<=90) {
		if (strCase=='L')
			event.keyCode = event.keyCode+32;
	}
	else if (event.keyCode==34) {
		event.keyCode = 0;
		event.returnValue = false;
	}	
	event.returnValue = true;
}
//Common Functions for Image and Windows
function MM_swapImgRestore(){
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages(){
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage(){
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_reloadPage(init){
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_findObj(n, d){ 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

MM_reloadPage(true);
//Keywoard Search OnFocus Function
function getblank(this1){
	if (this1.value = "Enter keyword here") {
		this1.value = "";
	}
    return true;
}
// Function to disable form
function disableForm(theform){
	if (document.all || document.getElementById){
		for (i = 0; i < theform.length; i++){
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "button" || tempobj.type.toLowerCase() == "image")
			tempobj.disabled = true;
		}
		return true;
	}else{
		alert("The form has been submitted.But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
		return false;
	}
}
//Function for Check All and Clear All Checkboxes
function ToggleAll(e,x){
	var theForm = document.forms[x];
	if (e.checked){
	    CheckAll(x);
	}else{
	    ClearAll(x);
	}	
}
function Toggle(e,x){
	var theForm = document.forms[x];
	if (e.checked){
		Highlight(e);
	    theForm.toggleAll.checked = AllChecked(x);
	}else{
		Unhighlight(e);
	    theForm.toggleAll.checked = false;
	}	
}
function Check(e){
	e.checked = true;
	Highlight(e);
}
function Clear(e){
	e.checked = false;
	Unhighlight(e);
}
function CheckAll(x){	
	var theForm = document.forms[x];
	var len = theForm.elements.length;
	for (var i = 0; i < len; i++){
	    var e = theForm.elements[i];
	    if (e.name == "check"){
			Check(e);
	    }
	}
	theForm.toggleAll.checked = true;
}
function ClearAll(x){
	var theForm = document.forms[x];
	var len = theForm.elements.length;
	for (var i = 0; i < len; i++){
	    var e = theForm.elements[i];
	    if (e.name == "check"){
			Clear(e);
	    }
	}
	theForm.toggleAll.checked = false;	
}
function AllChecked(x){
	var theForm = document.forms[x];
	len = theForm.elements.length;
	for(var i = 0 ; i < len ; i++){
	    if (theForm.elements[i].name == "check" && !theForm.elements[i].checked){
			return false;
	    }
	}
	return true;
}
function Highlight(e){	
	var r = null;
	if (e.parentNode && e.parentNode.parentNode){
	    r = e.parentNode.parentNode;
	}
	else if (e.parentElement && e.parentElement.parentElement){
	    r = e.parentElement.parentElement;
	}
	if (r){
	    if (r.className == "tdunhighlighted"){
			r.className = "tdhighlighted";
	    }
	}
}
function Unhighlight(e){
	var r = null;
	if (e.parentNode && e.parentNode.parentNode){
	    r = e.parentNode.parentNode;
	}else if (e.parentElement && e.parentElement.parentElement){
	    r = e.parentElement.parentElement;
	}
	if (r){
	    if (r.className == "tdhighlighted"){
			r.className = "tdunhighlighted";
	    }
	}
}
// Cookies Management
function getCookie(name){ 
	var pos
	var token = name + "=";
	var tnlen = token.length;
	var cklen = document.cookie.length;
	var i = 0;
	var j;
	while (i < cklen){ 
	j = i + tnlen;
	if (document.cookie.substring(i, j) == token){ 
		pos = document.cookie.indexOf (";", j);
		if (pos == -1)
			pos = document.cookie.length;
		return unescape(document.cookie.substring(j, pos));
	}
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
  }
  return null;
}
function setCookie(name, value){ 
	document.cookie = name + "=" + escape(value)
}
function deleteCookie(name){ 
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//Validation for Add/Update New Articles
function checkdate(objName) {
	var datefield = objName;	
	if ((datefield.value).length>0){
		if (chkdate(objName) == false) {
			datefield.select();
			alert("That date is invalid.  Please try again.");
			datefield.focus();
			return false;
		}else{
			return true;
		}
	}
}
function chkdate(objName) {
	var strDatestyle = "US"; 
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;	
	if (strDate.length >=1 && strDate.length <6){
		return false;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++){
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1){
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3){
				err = 1;
				return false;
			}else{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}
	if (booFound == false){
			if (strDate.length>5){
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
	   }
	}
	if (strYear.length == 2){
		strYear = '20' + strYear;
	}
	if (strDatestyle == "US"){
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)){
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)){
		for (i = 0;i<12;i++){
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()){
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
	  		}
		}
		if (isNaN(intMonth)){
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)){
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1){
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)){
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)){
		err = 7;
		return false;
	}
	if (intMonth == 2){
		if (intday < 1){
			err = 8;
			return false;
		}
	if (LeapYear(intYear) == true){
		if (intday > 29) {
			err = 9;
			return false;
		}
	}else{
		if (intday > 28){
			err = 10;
			return false;
		}
	}
	}
	if (strDatestyle == "US"){
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}else{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	return true;
}
function LeapYear(intYear){
	if (intYear % 100 == 0){
		if (intYear % 400 == 0){ 
			return true; 
		}
	}else{
		if ((intYear % 4) == 0){ 
			return true; 
		}
	}
	return false;
}
//Function for Next and Previous
function MoveRecord(pg,x){	
	var theForm = document.forms[x];	
	theForm.hidintPage.value=pg;
	theForm.submit();
}
function MovePage(pg,x){	
	var theForm = document.frmARTICLEDISPLAY;	
	theForm.hidintPage.value=pg;
	theForm.action='default.asp';
	theForm.submit();
}