
// for confirmation

	function verifyLogout () {
		if (confirm ("Are you sure you want to logout ?") ==  true) {
			window.location.href = 'j_spring_security_logout';
		}
	}

	function verifyDeZilebi (link) {
		if (confirm ("Are you sure you want to remove your account from Zeringo Network ?") ==  true) {
			link.href = 'dezilebi.htm';
		}
	}
	function Set_Cookie( name, value, expires, path, domain, secure ) 
		{
			var today = new Date();
			today.setTime( today.getTime() );
			if ( expires )
				expires = expires * 1000;
			var expires_date = new Date( today.getTime() + (expires) );		
			document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
			( ( path ) ? ";path=" + path : "" ) + 
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
		}		
	function Delete_Cookie( name, path, domain ) {
			if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
		
	function Get_Cookie( check_name ) {
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false;	
		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			a_temp_cookie = a_all_cookies[i].split( '=' );				
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');	
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;			
				if ( a_temp_cookie.length > 1 )
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
			return null;
	}	
	
	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 setActiveStyleSheet(title) {	
	document.getElementById('small1').innerHTML='A';
	document.getElementById('normal1').innerHTML='A';
	document.getElementById('large1').innerHTML='A';
	document.getElementById(title+1).innerHTML='<u>A</u>';
	  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 removeLast(valmonth,valyear,optmonth,optdate,lpyr){
		 var leapyear=valyear.value;
		 var ind=optdate.selectedIndex;	
		
		 if(((optmonth.selectedIndex==0 && ind!=0 )||(ind==0 && optmonth.selectedIndex!=0))||(lpyr.selectedIndex!=0 && optmonth.selectedIndex==0 && ind==0)){
				//document.getElementById("doberror").style.display="block";
		 }else 
			//document.getElementById("doberror").style.display="none";
		if (valmonth.value=="2")
		{
			if(leapyear%4!=0)
			{
				optdate[31] = null;
				optdate[30] = null;
				optdate[29] = null;
			}
			if(leapyear%4==0 || valyear.value=="-1")
			{
				optdate[31] = null;
				optdate[30] = null;
				optdate[29]=new Option (29,29);
			}
		}
		if (valmonth.value=="4"||valmonth.value=="6"||valmonth.value=="9"||valmonth.value == "11")
		    { 
			for( var i=29;i<=30;i++)
			{	
				optdate[i]=new Option (i,i);
		 	} 
		   	optdate[31] = null;
		   	}
	    if (valmonth.value=="1"||valmonth.value=="3"||valmonth.value=="5"||valmonth.value=="7"||valmonth.value=="8"||valmonth.value=="10"||valmonth.value=="12")
	    {
	       for( var i=29;i<=31;i++)
			 {	
				optdate[i]=new Option (i,i);
		  	 } 
	    }      
		optdate.selectedIndex=ind;
		}

	function checkLeapYear(valyear,valmonth,valdate)
		{ 
			if(valyear.options.selectedIndex!=0 ){
			if( valmonth.options.selectedIndex==0 || valdate.options.selectedIndex==0){
				//document.getElementById("doberror").style.display="block";
			 }
			}else if( valmonth.options.selectedIndex==0 && valdate.options.selectedIndex==0)
			//	document.getElementById("doberror").style.display="none";
			
			var vyear=valyear.value;
			var lpyr=vyear%4;
			if(lpyr!=0 && valmonth.value==2 && valdate.length>=30)
			{
				if(lpyr!=0 && valmonth.value==2 && valdate.value>=29)
				{
					valdate[31]=null;
					valdate[30]=null;
					valdate[29]=null;
					valdate[0].selected=true;
				}				
				else
				{					
					valdate[31]=null;
					valdate[30]=null;
					valdate[29]=null;
				}
		  	}
	  		else if(lpyr==0 && valmonth.value==2)
	  		{	  	  		 	
	  		  	valdate[31]=null;
				valdate[30]=null;
	  		  	valdate[29]=new Option (29,29);				
	  		 }
	  	}
	  	
	function validateEmail(str) {
		var iChars = "!@#$%^&*()+=-[]\';./{}|\":<>?";
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 	return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		  	return false
		}
		if (str.indexOf(at,(lat+1))!=-1){		
		    return false
		 }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		if((str.substring((ldot+1),(ldot+2))).length==0)
		{
		    return false
		 }
		if (str.indexOf(" ")!=-1){

		    return false
		 }
		if (iChars.indexOf(str.charAt(str.length-1)) != -1) {
		    return false
		 }
 		 return true					
	}
	
	function trim1(s) {
		  while (s.substring(0,1) == ' ') {
		    s = s.substring(1,s.length);
		  }
		  while (s.substring(s.length-1,s.length) == ' ') {
		    s = s.substring(0,s.length-1);
		  }
		  return s;
	}

	function CheckBoxGroup() {
		this.controlBox=null;
		this.controlBoxChecked=null;
		this.maxAllowed=null;
		this.maxAllowedMessage=null;
		this.masterBehavior=null;
		this.formRef=null;
		this.checkboxWildcardNames=new Array();
		this.checkboxNames=new Array();
		this.totalBoxes=0;
		this.totalSelected=0;
		// Public methods
		this.setControlBox=CBG_setControlBox;
		this.setMaxAllowed=CBG_setMaxAllowed;
		this.setMasterBehavior=CBG_setMasterBehavior;	// all, some
		this.addToGroup=CBG_addToGroup;
		// Private methods
		this.expandWildcards=CBG_expandWildcards;
		this.addWildcardCheckboxes=CBG_addWildcardCheckboxes;
		this.addArrayCheckboxes=CBG_addArrayCheckboxes;
		this.addSingleCheckbox=CBG_addSingleCheckbox;
		this.check=CBG_check;
	}
	
	function CBG_expandWildcards() {
		if (this.formRef==null) {return false; }
		for (var i=0; i<this.checkboxWildcardNames.length;i++) {
			var n = this.checkboxWildcardNames[i];
			var el = this.formRef[n];
			if (n.indexOf("*")!=-1) { this.addWildcardCheckboxes(n); }
			else if(CBG_nameIsArray(el)) { this.addArrayCheckboxes(n); }
			else { this.addSingleCheckbox(el); }
			}
		}
	
	function CBG_setMaxAllowed(num,msg) {
		this.maxAllowed=num;
		if (msg!=null&&msg!="") { this.maxAllowedMessage=msg; }
	}
		
	function CBG_addWildcardCheckboxes(name) {
		var i=name.indexOf("*");
		if ((i==0) || (i==name.length-1)) {
			searchString= (i)?name.substring(0,name.length-1):name.substring(1,name.length);
			for (var j=0;j<this.formRef.length;j++) {
				currentElement = this.formRef.elements[j];
				currentElementName=currentElement.name;
				var partialName = (i)?currentElementName.substring(0,searchString.length) : currentElementName.substring(currentElementName.length-searchString.length,currentElementName.length);
				if (partialName==searchString) {
					if(CBG_nameIsArray(currentElement)) this.addArrayCheckboxes(currentElement);
					else this.addSingleCheckbox(currentElement);
					}
				}
			}
		}

	// Add checkboxes to the group which all have the same name
	function CBG_addArrayCheckboxes(name) {
		if((CBG_nameIsArray(this.formRef[name])) && (this.formRef[name].length>0)) {
			for (var i=0; i<this.formRef[name].length; i++) { this.addSingleCheckbox(this.formRef[name][i]); }
			}
		}
	
	function CBG_addSingleCheckbox(obj) {
		if (obj != this.formRef[this.controlBox]) {
			this.checkboxNames[this.checkboxNames.length]=obj;
			this.totalBoxes++;
			if (obj.checked) {
				this.totalSelected++;
				}
			}
		}
		
	function CBG_nameIsArray(obj) {
		return ((typeof obj.type!="string")&&(obj.length>0)&&(obj[0]!=null)&&(obj[0].type=="checkbox"));
	}
		
	function CBG_setMasterBehavior(b) { this.masterBehavior = b.toLowerCase(); }
	
	function CBG_setControlBox(name) { this.controlBox=name; }
	
	function CBG_addToGroup() {
		if (arguments.length>0) {
			for (var i=0;i<arguments.length;i++) {
				this.checkboxWildcardNames[this.checkboxWildcardNames.length]=arguments[i];
				}
			}
		}
		
	function CBG_check(obj) {
		var checked=obj.checked;
		if (this.formRef==null) {
			this.formRef=obj.form;
			this.expandWildcards();
			if (this.controlBox==null || obj.name!=this.controlBox) {
				this.totalSelected += (checked)?-1:1;
				}
			}
		if (this.controlBox!=null&&obj.name==this.controlBox) {
			if (this.masterBehavior=="all") {
				for (i=0;i<this.checkboxNames.length;i++) { this.checkboxNames[i].checked=checked; }
				this.totalSelected=(checked)?this.checkboxNames.length:0;
				}
			else {
				if (!checked) {
					obj.checked = (this.totalSelected>0)?true:false;
					obj.blur();
					}
				}
			}
		else {
			if (this.masterBehavior=="all") {
				if (!checked) {
					this.formRef[this.controlBox].checked=false;
					this.totalSelected--;
					}
				else { this.totalSelected++; }
				if (this.controlBox!=null) {
					this.formRef[this.controlBox].checked=(this.totalSelected==this.totalBoxes)?true:false;
					}
				}
			else {
				if (!obj.checked) { this.totalSelected--; }	
				else { this.totalSelected++; }
				if (this.controlBox!=null) {
					this.formRef[this.controlBox].checked=(this.totalSelected>0)?true:false;
					}
				if (this.maxAllowed!=null) {
					if (this.totalSelected>this.maxAllowed) {
						obj.checked=false;
						this.totalSelected--;
						if (this.maxAllowedMessage!=null) { }
						return false;
						}
					}
				}
			}
		}
	
	Array.prototype.contains = function(obj) {
	  var i = this.length;
	  while (i--) {
	    if (this[i] === obj) {
	      return true;
	    }
	  }
	  return false;
	}
	
	Array.prototype.remove=function(s){
		for(i=0;i<this.length;i++){
			if(s==this[i]) 
			this.splice(i, 1);
		}
	}	
