
//**************************** CWX Javascript Functions *****************************//
var Development=1;
var xCookie=document.cookie;

if (document.layers)
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN | Event.MOUSEUP)
	document.onmouseover=hidestatus
	document.onmouseout=hidestatus


function hidestatus(){
	window.status=''
	return true
}

function Logout(theForm){
var agree=confirm("Are you sure you wish log out?");
if (agree){
	theForm.HLogin.value='';
	return true ;
	}
else{
	return false ;
	}
}

function ConfirmDelete()
{
var dagree=confirm("Are you sure you wish to delete this record(s)?");
if (dagree){
	return true ;
	}
else{
	return false ;
	}
}

function ConfirmEmail()
{
var eagree=confirm("Are you sure you wish to mail this record(s)?");
if (eagree){
	return true ;
	}
else{
	return false ;
	}
}

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4){ 
	window.print();
   }else{
   alert("Your browser does not support this fuctionality");
   }
}

function ConfirmUserEdit(theForm){
}

function select_deselectAll(theForm,chkVal,idVal,idType) { 
	for (i=0; i<theForm.length; i++) {
		if ((theForm.elements[i].name.indexOf('CheckAll#'+idType)!=-1)||(theForm.elements[i].name.indexOf('DeleteAll#'+idType)!=-1)) {
			theForm.elements[i].checked = chkVal;
		}
	}
}

function GetallSelected(theForm,type,command){
var DeleteItems= "";
var DeleteNumber=0;
var Num=1;
var DeleteBoxName='';
  for(i=0;i< theForm.length;i++)
  {
    e=theForm.elements[i];
    
    if ( e.type=='checkbox' && e.name.indexOf("DeleteAll#"+command) != -1 )
    {
		if (e.checked){
			Mysplit=e.name.split(":");
			DeleteItems+=","+Mysplit[Mysplit.length-1];
			DeleteNumber++;
		}
    }
    if ( e.name.indexOf("Variable"+command) != -1 )
    {
		DeleteBoxName=e.id;
    }
  }
	if((DeleteNumber>0)&&(DeleteBoxName!='')){
	var DV=eval('theForm.'+DeleteBoxName);
	DV.value=DeleteItems.substring(1,DeleteItems.length);
		var agree=confirm('Are you sure you want to '+type+' the selected file(s)?')
		if (agree){
			return true;
		}else{
			return false;
		}
	}else{
		alert("No files where selected");
		return false;
	}
}

function ProcessInputBox(xMaxChars){
	var ThisObject=event.srcElement
	var InputName=ThisObject.name
	var ThisInput=ThisObject.value
	var TextLength=ThisInput.length
	var ThisclassName="textbox"
	if (xMaxChars!=0) {
		if (TextLength > xMaxChars) {
				var ThisNewText = ThisInput.substring(0, xMaxChars-3);
				event.srcElement.value=ThisNewText+"...";
				ThisObject.className="xTextBoxAlert";
				alert("The maximum amount of characters is "+xMaxChars+", your input has been shortened to reflect the maximun number of characters")
			}else{
				ThisObject.className=ThisclassName;
			}
		//INameChar.innerHTML=xMaxChars-TextLength
			}
		}
				var FileN = 0;
				var FileI = 0;
				var FileL = 0;
				
				function ExpandFiles(Parent,SFiles,Files,Values,Type){
				var Target="_blank,_self";
				var TargetArray=Target.split(",");
				var TargetName="New window,Same window";
				var TargetNameArray=TargetName.split(",");
				var NumberOfTargets=TargetArray.length;
				var SFile_Rrray=SFiles.split(",");
				var File_Rrray=Files.split(",");
				var Value_Rrray=Values.split(",");
				var NumberOfFiles=File_Rrray.length;
				var NumberOfSFiles=SFile_Rrray.length;
				var FileNC=0;
				var FCount=0;
				if (Parent=="Documents"){
					FileN++
					FCount=FileN;
				}else if(Parent=="Images"){
					FileI++
					FCount=FileI;
				}else if(Parent=="Links"){
					
					FileL++
					FCount=FileL;
				}
				FileNC=(NumberOfSFiles)+FCount;
				var JFileSelector="<select id='"+Type+FileNC+"' name='"+Type+FileNC+"' class='textbox' runat='server'>";
				if(Parent=="Links"){
					JFileSelector="<select id='Link_Target"+FileNC+"' name='Link_Target"+FileNC+"' class='textbox' runat='server'>";
					for (n=0;n<TargetArray.length;n++){
						JFileSelector+="<option value='"+TargetArray[n]+"'>"+TargetNameArray[n]+"</option>";
					}
				}else{
					for (i=0;i<NumberOfFiles;i++){
						JFileSelector+="<option value='"+Value_Rrray[i]+"'>"+File_Rrray[i]+"</option>";
					}
				}

				JFileSelector+="</select>";
				var AddFiles=Type+" "+FileNC+" : "+JFileSelector+"<br><br>"
				if (Parent=="Documents"){
					if (FileNC<50){
						DFiles.insertAdjacentHTML('BeforeEnd',AddFiles);
					}else{
						alert("You can only add up to 50 documents");
					}
				}else if(Parent=="Images"){
					if (FileNC<6){
					IFiles.insertAdjacentHTML('BeforeEnd',AddFiles);
					}else{
					alert("You can only select 6 images when using templates");
					}
				}else if(Parent=="Links"){
					if (FileNC<50){
						AddFiles="<table width='100%'cellpadding='3'><tr><td width='37%'>"+Type+" "+FileNC+" : <input id='Link"+FileNC+"' name='"+Type+FileNC+"' runat='server' class='textbox' size='27' maxlength='150' value=''></td><td width='37%'>&nbsp;Path : <input id='Link_Path"+FileNC+"' name='Link_Path"+FileNC+"' class='textbox' size='27' maxlength='150' value=''></td><td width='16%'>&nbsp;Target :"+JFileSelector+"</td><tr></table>";
						LFiles.insertAdjacentHTML('BeforeEnd',AddFiles);
					}else{
						alert("You can only add up to 50 links per page");
					}
				}
				return false;
				}
function ValidatexCompanyNews()
{
var x=getHTML();
	if(x){
		return(true);
	}else{
		return false;
	}
}
function ValidateFEmailer(theForm){
return true;
var String = EmailDisplay;
theForm.MailMessage.value=PageHtmlEncoder(String.innerHTML);
return true;
}
function PageHtmlEncoder(encodedHtml){
	encodedHtml = encodedHtml.replace(/</g,'&lt;');
	encodedHtml = encodedHtml.replace(/>/g,'&gt;');
	encodedHtml = encodedHtml.replace(/&/g,'&amp;');
	return encodedHtml;
}

function PageHtmlDecoder(decodedHtml){
	decodedHtml = decodedHtml.replace(/&lt;/g,'<');
	decodedHtml = decodedHtml.replace(/&gt;/g,'>');
	decodedHtml = decodedHtml.replace(/&amp;/g,'&');
	return decodedHtml;
}

//**************************** Javascript Functions *****************************//

function HLLink(x,w){

}

//**************************** Calendar Functions *****************************//
function xCalendar(strField,Root)
{
		var URLStr=Root+'xIncludes/xCalendar.aspx';
				var theForm=document.forms[0];
				var thisform=document.forms[0].id;
				for(i=0;i< theForm.length;i++)
					{
						e=theForm.elements[i];
						if ( e.name.indexOf(strField) != -1 )
						{
							DeleteBoxName=e.id;
						}
					}
					var w=190;
					var h=190;
					l = (screen.availWidth-10 - w) / 2;
					t = (screen.availHeight-20 - h) / 2;

		strField=thisform+'.'+DeleteBoxName;
		window.open(URLStr+'?F='+strField,'calendarPopup','width='+w+',height='+h+',left='+l+',top='+t+',resizable=no');
}

function xCalendarClear(strField,thexForm)
{
var theForm=document.forms[0];
	for(i=0;i< theForm.length;i++)
		{
			e=theForm.elements[i];
			if ( e.name.indexOf(strField) != -1 )
			{
				DeleteBoxName=e.id;
			}
		}
		eval("theForm."+DeleteBoxName+".value=''")
}



//**************************** Admin Functions *****************************//

function GetRootPath(QUERY){
	var RootPath= "";
	var PathArray=QUERY.split('/');
	var RootPathCount=PathArray.length
	if ((QUERY.indexOf('devserver')!=-1)||(QUERY.indexOf('localhost')!=-1)||(Development=1)){
		RootPathCount=RootPathCount-5
	}else{
		RootPathCount=RootPathCount-4
	}
	for(var i=0;i<RootPathCount;i++){
		RootPath+="../";
	}
	return RootPath;
}

function SetCookie(name, value) {
	return false;
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function GetCookie(name){
	var index = xCookie.indexOf(name+"=");
	if (index == -1) return null;
	index = xCookie.indexOf("=", index) + 1;
	var endstr = xCookie.indexOf(";", index);
	if (endstr == -1) endstr = xCookie.length;
	return xCookie.substring(index, endstr)
}

function right(e) {

	var count=0;
	var QUERY=document.location.toString();
	var ComponentString='xComponents';
	var RootPath=GetRootPath(QUERY);

	if (QUERY.indexOf(ComponentString)==-1){
		count=QUERY.indexOf('default.aspx');
	}else{
		count=QUERY.indexOf(ComponentString)
	}
	var xHost=QUERY.substring(0,count);
	QUERY=QUERY.substring(count,QUERY.length);

		if (navigator.appName == 'Microsoft Internet Explorer') 
		{
		var xButtonEvent=event.button
		if (xButtonEvent>1){
			if(GetCookie("Links")!=null){
			var thisCookieArray = GetCookie("Links").split('#');
				if(thisCookieArray.length>0){
					if(thisCookieArray[0]=="{Links}"){
						var x=window.confirm("Are you sure you want to create a link to this page?");
						if (x){
							var xCPath=thisCookieArray[2]
							window.location.replace(xHost+"xComponents/" + xCPath + "/" + thisCookieArray[3] + "&S=1&Se=0&ID="+thisCookieArray[1]+"&PID=" + RootPath + QUERY.replace(/\?/g,'Qm').replace(/\&/g,'An').replace('CWXQ','{CWXQ}'));
						}else{
							return false;
						}
					}
				}
			}
		}
	}else{
	//alert('This Functionality is only available for Internet explorer');
	return false;
	}
}


//**************************** Load Page *****************************//
document.onmousedown=right;
document.onmouseup=right;
	
function loadpage() { 

} 


//**************************** Collapse Boxes *****************************//


 function FindTagId( itemid, tag ) {

        var divCollection = document.getElementsByTagName(tag);
        
        for (var i=0; i < divCollection.length; i++) {
			if( IE5 ){
				if( divCollection[i].getAttribute("id").indexOf( itemid ) != -1 ) {
					return divCollection[i].getAttribute("id");
				}
			}else{
				if( divCollection[i].hasAttribute("id") ){
					if( divCollection[i].getAttribute("id").indexOf( itemid ) != -1 ) {
						return divCollection[i].getAttribute("id");
					}
				} 
            }
        }
     return null;
  }
  
  function expanderbox(id)
{
	var _id = FindTagId( id, "div" );
	
	if( _id != null ){
		if (document.getElementById(_id).style.display == 'none')
		{
			document.getElementById(_id).style.display = 'block';
		}else{
			document.getElementById(_id).style.display = 'none';
		}
    }
}
function expander( item,over )
{
	if( over ){
		//".src = "images/blue.jpg";
		doCursor( item,'hand');
	}else{
		doCursor( item,'arrow');
	}
}
function doCursor( item,cursor ){
	item.style.cursor = cursor;
}


  //**************************** Find Functions *****************************//

function FindFormElement( id )
{
	var theForm = document.forms[0];
	var idstring = "";
	for(i=0;i< theForm.length;i++)
		{
			e = theForm.elements[i];
			if ( e.name.indexOf( id ) != -1 )
			{
				idstring = e.id;
			}
		}
	return idstring;
}

  //**************************** browser Functions *****************************//
  
IE4 = (document.all && !document.getElementById) ? true : false;
NS4 = (document.layers) ? true : false;
IE5 = (document.all && document.getElementById) ? true : false;
NS6 = (!document.all && document.getElementById) ? true : false;
  
var ua = navigator.userAgent.toLowerCase();
var os,browser,version,data;

if (detect('konqueror')) {browser = "konqueror"; os = "linux";}
else if (detect('safari')) browser = "safari";
else if (detect('omniweb')) browser = "omniweb";
else if (detect('gecko')) browser = "gecko";
else if (detect('firefox')) browser = "firefox";
else if (detect('opera')) browser = "opera";
else if (detect('webtv')) browser = "webtv";
else if (detect('icab')) browser = "icab";
else if (detect('msie')) browser = "msie";
else if (!detect('compatible')) {browser = "netscape"; version = ua.charAt(8);}
else browser = "unknown";

if (!version) version = ua.charAt(stringposition + data.length);

if (!os) {
   if (detect('linux')) os = "linux";
   else if (detect('x11')) os = "unix";
   else if (detect('mac')) os = "mac";
   else if (detect('win')) os = "win";
   else os = "unknown";
}

function detect(text) {
   stringposition = ua.indexOf(text) + 1;
   data = text;
   return stringposition;
}

function outputValues() {
   document.write('&lt;p&gt;Your browser is: ' + browser + '&lt;/p&gt;');
   document.write('&lt;p&gt;Your browser version is: ' + version + '&lt;/p&gt;');
   document.write('&lt;p&gt;Your operating system is: ' + os + '&lt;/p&gt;');
   document.write('&lt;p&gt;Your user agent string (in lowercase) is: ' + ua + '&lt;/p&gt;');
}
function Nonvalidation(){

}

  //**************************** browser Functions *****************************//
  
function ValidOnSubmit() {
    if (Page_ValidationActive) {
		if( !Page_IsValid ){
			placeFocus();
			alert( "Please check the fields indicated. All fields marked with an (*) are required." );
		}		    
       return ValidatorCommonOnSubmit();
    }else{
    alert("ggg");
    }
    return true;
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
			break;
			}
		}
   }
}

