﻿var validate = true;

function closeWindow() {
	window.close();
}
function print() {
    window.print();
}
function back() {
    history.go(-1);
    return false;    
}
function deleteObject(objectName) {    
    if ( confirm('Are you sure you want to delete this ' + objectName + '?\nNote: There is no Undo.') ) {
        return true;
    } else {
        return false;
    }
}
function alertAndFocus(element, alertText) {
	//
	//modifyClassName('add',element,'error');
	//alert(element.focus());		
	
	hideShow(1, ("error_" + element.id)) ;		
	element.focus();			
}

function alertAndShow(element, error_elementID) {
	//
	//modifyClassName('add',element,'error');
	//alert(element.focus());		
	hideShow(1, (error_elementID)) ;	
	//hideShow(1, ("validationError"));	

	fncScrollTo("#"+error_elementID);	

	element.focus();			
}

function hide(elementID) {
    hideShow(0, elementID);
}
function show(elementID) {
    hideShow(1, elementID);
}

function hideShow(action, elementID) {
    //alert(elementID);
    if (document.getElementById(elementID) ) {
    
        if (action == 1 ){
            document.getElementById(elementID).style.display="block";
        }else {
            document.getElementById(elementID).style.display="none";
        }
    }    
}
function setFocus(elementID) {
    
    if (document.getElementById(elementID)) {    
        document.getElementById(elementID).focus();
    }
}

function resetErrorElement(element) {	
	
	hideShow(0, ("error_" + element.id)) ;
	
	//modifyClassName('remove', element, 'error');
	//element.style.backgroundColor="";	
}

function isEmpty(element, defaultValue, errorAlert) { 
	if ( (element.value == "" ) || (element.value == defaultValue ) ){ 
		
		//hideShow(1, ("error_" + element.id)) ;
		alertAndFocus(element,errorAlert); 
		return true;  
	} else {
		//hideShow(0, ("error_" + element.id)) ;
		resetErrorElement(element);
		
		return false;  
	}
}
function isEmptyAndShow(element, defaultValue, errorElementID) { 
	if ( (element.value == "" ) || (element.value == defaultValue ) ){ 				
		alertAndShow(element,errorElementID); 
		return true;  
	} else {		
		resetErrorElement(element);		
		return false;  
	}
}
function isBothEmptyAndShow(element, element2, defaultValue, errorElementID) { 
	if ( ( (element.value == "" ) || (element.value == defaultValue )) && (element2.value == "") ){ 				
		alertAndShow(element,errorElementID); 
		return true;  
	} else {		
		resetErrorElement(element);		
		return false;  
	}
}


function isSelectedIndex(element, errorAlert, indexValue) {     
	if (element.selectedIndex == indexValue) {  
					
		alertAndFocus(element, errorAlert)		
		//alert(errorAlert);
		//element.focus();
		return false;        
	}  
	return true;
}
function isChecked(eName)  {	
	//alert(eName);
	formElement = document.getElementsByName(eName);		
	for ( i=0 ; i < formElement.length; i++ ) {		
		if (formElement[i].checked == true ) {			
			return true;			
		}		
	}
	return false;
}

function isNumerical(stringInput, allowedChars) {  
	var decPoints = 0;
	var decCheck = false;    
	
	if (allowedChars.indexOf(".") != -1) {     
		decCheck = true;
	}                 
	for (i = 0;  i < stringInput.length;  i++)  {
		ch = stringInput.charAt(i);            
		if (allowedChars.indexOf(ch) == -1) {    
			return false;
		}             
		if ( (decCheck == true) && (ch == ".") ) {
			decPoints++;
			if (decPoints > 1) {
				return false;
			}
		}         
	}
	return true;
}

function validateEmail(email, defaultText) {	
	if ((email == "") || (email == defaultText)) {
		return false;
	} else {
		eLength = email.length;
		eAt = email.indexOf("@"); 
		eDot = email.lastIndexOf(".");	
		eSpace = email.indexOf(" ");
		
		// if no @ sign, @ is at start or end of email
		if ( (eAt == -1) || (eAt == 0) || (eAt == eLength-1) ) {
			return false;
		} else {
			// if no dot, dot is at start end or next to or less than @
			if ( (eDot == -1) || (eDot == 0) || (eDot == eLength-1) || (eDot <= eAt+1)  )  {
				return false;
			}		
		}
		if (eSpace != -1) {
			return false;	
		}
	}
	return true;
}
function clearInput(defaultText, elementName) {	
	element = document.getElementById(elementName);			
	//alert(element.value)
	if (element.value == defaultText) {
		element.value= "";
	}	
}
// dreamweaver functions---------------------------
function MM_preloadImages() { //v3.0
  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_swapImgRestore() { //v3.0
  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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  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];}
}
// eof dreamweaver functions----------------------


function valSignIn() {
	//frmUsername
	//frmPassword
	if ( isEmpty(document.getElementById("frmUsername"), "username", "Please enter your username.")) {
		return false;
	}
	if ( isEmpty(document.getElementById("frmPassword"), "password", "Please enter your password.")) {
		return false;
	}

	return true;
}
function swapImage(strImage,strElement) {
	if ( (strImage != "") && (strElement != "") ) {
		//strImageL = strImage + "&t=l";
		//strImageXL = strImage + "&t=xl";
		//alert(strImageL);
		document.getElementById(strElement).src = strImage;
		//document.getElementById("mainImageLink").href = strImageXL;
	}
	return false;
}

function modifyClassName(a,o,c1,c2) {
/*
http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
a   -   defines the action you want the function to perform.
o   -   the object in question.
c1  -   the name of the first class
c2  -   the name of the second class 

actions:
swap    -   replaces class c1 with class c2 in object o.
add     -   adds class c1 to the object o.
remove  -   removes class c1 from the object o.
check   -   test if class c1 is already applied to object o and returns true or false. 
*/

  switch (a){
    case 'swap':
      o.className=!modifyClassName('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
    break;
    case 'add':
      if(!modifyClassName('check',o,c1)){o.className+=o.className?' '+c1:c1;}
    break;
    case 'remove':
      var rep=o.className.match(' '+c1)?' '+c1:c1;
      o.className=o.className.replace(rep,'');
    break;
    case 'check':
      return new RegExp('\\b'+c1+'\\b').test(o.className)
    break;
  }
}

function rulerOnOff(elementID, state){
    
    alert(elementID);
    element = document.getElementById("elementID");
    if (state == 1) {
        modifyClassName('add', element, 'rulerOn');        
    } else {
        modifyClassName('remove', element, 'rulerOn');
    }
}

/*----------- style switcher --------------------*/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
/*----------- end of style switcher --------------------*/



function getRecordIDFromID(id) {									
	var indexOfLastUnderscore = id.lastIndexOf("_");
	var recordId = id.substring(indexOfLastUnderscore+1,id.length);		
	return recordId;	
}

function fncScrollTo(valTarget) {
	$.scrollTo(valTarget, 'none', {axis:'y'} );	
}

function fncHighlight(elementId) {
     fncHighlightMaster(elementId, "#FFFF66", "#ffffff", 1000);
}

function fncHighlightMaster(elementId, startColour, endColour, speed) {
        
	//$("#database_container_<%=wpc.General.Request("id", "0") %>").addClass("highlight");
    //$("#database_container_<%=wpc.General.Request("id", "0") %>").css("backgroundColor", "#FFFF66");
    //$("#database_container_<%=wpc.General.Request("id", "0") %>").animate({ backgroundColor: "#F0F5E6" }, 1000);         
    	    
    //$("#" + elementId).addClass(highlightClass);
    $("#" + elementId).css("backgroundColor", startColour);
    $("#" + elementId).animate({ backgroundColor: endColour }, speed);
	    	        
    /*
    var originalColour = $("#" + elementId).css("background-color");
    alert(originalColour);
    $("#" + elementId).addClass(highlightClass);
    $("#" + elementId).animate({ backgroundColor: originalColour }, speed);
    */
                	    
}
// global jquery functions
$(document).ready(function() {						   
	
	/*
	$(".scrollTo").click(function() {		
		
		target = $(this).attr("href");				

		fncScrollTo(target);		
		
		return false;
   	});
   	*/
});



/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/9/2009
 * @author Ariel Flesler
 * @version 1.4.1
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function($){var m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);
/* eof jQuery.ScrollTo Extension */


/* htmlEditor (WYMeditor */
function fncAddHtmlEditor(identifier, type, size, stylesheet) {

    type = 'standard'
        
    if (stylesheet == "") {
        stylesheet = 'css/wym-styles.css'
    }
    //stylesheet="";

    jQuery(function() {
                        
        jQuery(identifier).wymeditor({        
                  stylesheet: stylesheet
                , skin: type 
                , logoHtml : '' 
                
                , toolsItems: [
                    {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                    {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                    //{'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                    //{'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                    {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                    {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                    //{'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                    //{'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                    //{'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                    //{'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                    {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                    {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
                    //{'name': 'InsertImage', 'title': 'Image', 'css': 'wym_tools_image'},
                    {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                    //{'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                    {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'}
                    //,{'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'}
                ]
                                                                                                                                                                                     
        });
              
    });          
    
}

function fncImgError(element, image){
    element.onerror = "";
	element.src = image;
    return true;
}
