var MustResize = true;
// Fixed split
var nativeSplit = nativeSplit || String.prototype.split;
String.prototype.split = function (s /* separator */, limit) {
	// If separator is not a regex, use the native split method
	if (!(s instanceof RegExp))
		return nativeSplit.apply(this, arguments);

	/* Behavior for limit: If it's...
	 - Undefined: No limit
	 - NaN or zero: Return an empty array
	 - A positive number: Use limit after dropping any decimal
	 - A negative number: No limit
	 - Other: Type-convert, then use the above rules */
	if (limit === undefined || +limit < 0) {
		limit = false;
	} else {
		limit = Math.floor(+limit);
		if (!limit)
			return [];
	}

	var	flags = (s.global ? "g" : "") + (s.ignoreCase ? "i" : "") + (s.multiline ? "m" : ""),
		s2 = new RegExp("^" + s.source + "$", flags),
		output = [],
		lastLastIndex = 0,
		i = 0,
		match;

	if (!s.global)
		s = new RegExp(s.source, "g" + flags);

	while ((!limit || i++ <= limit) && (match = s.exec(this))) {
		var zeroLengthMatch = !match[0].length;

		// Fix IE's infinite-loop-resistant but incorrect lastIndex
		if (zeroLengthMatch && s.lastIndex > match.index)
			s.lastIndex = match.index; // The same as s.lastIndex--

		if (s.lastIndex > lastLastIndex) {
			// Fix browsers whose exec methods don't consistently return undefined for non-participating capturing groups
			if (match.length > 1) {
				match[0].replace(s2, function () {
					for (var j = 1; j < arguments.length - 2; j++) {
						if (arguments[j] === undefined)
							match[j] = undefined;
					}
				});
			}

			output = output.concat(this.slice(lastLastIndex, match.index), (match.index === this.length ? [] : match.slice(1)));
			lastLastIndex = s.lastIndex;
		}

		if (zeroLengthMatch)
			s.lastIndex++;
	}

	return (lastLastIndex === this.length) ?
		(s.test("") ? output : output.concat("")) :
		(limit      ? output : output.concat(this.slice(lastLastIndex)));
}

// getByTagName
function getByTagName( o, tN ) {
   return $($(o).select(tN));
}

// Encoding
function utf8_encode( string ) {
    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}

function md5( str ) {
    var RotateLeft = function(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    };
 
    var AddUnsigned = function(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    };
 
    var F = function(x,y,z) { return (x & y) | ((~x) & z); };
    var G = function(x,y,z) { return (x & z) | (y & (~z)); };
    var H = function(x,y,z) { return (x ^ y ^ z); };
    var I = function(x,y,z) { return (y ^ (x | (~z))); };
 
    var FF = function(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };
 
    var GG = function(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };
 
    var HH = function(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };
 
    var II = function(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };
 
    var ConvertToWordArray = function(str) {
        var lWordCount;
        var lMessageLength = str.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };
 
    var WordToHex = function(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };
 
    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;
 
    str = utf8_encode(str);
    x = ConvertToWordArray(str);
    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
    
    xl = x.length;
    for (k=0;k<xl;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }
 
    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
    return temp.toLowerCase();
}

// Select all Checkbox in table
function checkAllTable(table, span) {
   var table = $(table);
   var checked = $(($(span).id).substring(0, ($(span).id).length-2)).checked;
   table.getElementsBySelector('input').each(function(elem) {
                                                              if(elem.type=="checkbox") {
                                                                  elem.checked=checked;
                                                                  ChangeCheckboxClick(elem.id+'_s', elem.id);             
                                                              }                    
                                                             })
}  

// Custom Checkbox Functions
function ChangeCheckboxDown(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).disabled) return false;

   if ($(inputCheckbox).checked) {
      spanCheckbox.style.backgroundPosition = '0px -77px';
   } else {
      spanCheckbox.style.backgroundPosition = '0px -27px';
   }
}

function ChangeCheckboxUp(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).disabled) return false;
   if ($(inputCheckbox).checked) {
      $(inputCheckbox).checked = false;
      $(spanCheckbox).style.backgroundPosition = '0px -2px';
   } else {
      $(inputCheckbox).checked = true;
      $(spanCheckbox).style.backgroundPosition = '0px -52px';
   }
   $(inputCheckbox).focus();
}

function ChangeCheckboxOut(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).disabled) return false;   
   if ($(inputCheckbox).checked) {
      $(spanCheckbox).style.backgroundPosition = '0px -52px';
   } else {
      $(spanCheckbox).style.backgroundPosition = '0px -2px';
   }
}

function ChangeCheckboxClick(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).disabled) return false;
   if ($(inputCheckbox).checked) {
      $(spanCheckbox).style.backgroundPosition = '0px -52px';
   } else {
      $(spanCheckbox).style.backgroundPosition = '0px -2px';
   }
}

// Custom Radio Functions
function ChangeRadioDown(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).checked) {
      $(spanCheckbox).style.backgroundPosition = '0px -77px';
   } else {
      $(spanCheckbox).style.backgroundPosition = '0px -27px';
   }
}
//arrayRadio deprecated
function ChangeRadioUp(spanRadio, inputRadio, arrayRadio) {
   var inputRadioObject = $(inputRadio);
   if (arrayRadio) {
      $A(arrayRadio).each(function(s) {
                                     $(s).checked = false;
                                     $($(s).identify()+'span').style.backgroundPosition = '0px -2px';
                                    });   
   } else {
   $(inputRadioObject.form).getInputs('radio', inputRadioObject.name).each(function(s) {
                                     s.checked = false;
                                     $(s.identify()+'span').style.backgroundPosition = '0px -2px';
                                    });
   }
   inputRadioObject.checked = true;
   $(spanRadio).style.backgroundPosition = '0px -52px';
   inputRadioObject.focus();
}

function ChangeRadioOut(spanCheckbox, inputCheckbox) {
   if ($(inputCheckbox).checked) {
      $(spanCheckbox).style.backgroundPosition = '0px -52px';
   } else {
      $(spanCheckbox).style.backgroundPosition = '0px -2px';
   }
}

// textarea function
function mL(elem) {
   if($F(elem).length>500) {
      $(elem).value=$F(elem).substring(0, 500);   
      return false;
   }
   else return true;
}

// Form validation function
var regexpNumber = /^[\d]*$/;
var regexpNumberWSpace = /^[\d ]*$/;
var regexpICQ = /^[0-9\-\s]*$/;
var regexpICQChar = /^[0-9\-\s]*$/;
var regexpCYTALKid = /^[0-9a-zA-Z\.\-\_]*$/;
var regexpPassword = /^[0-9a-zA-Z\u0020-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E]*$/;
var regexpCaptcha = /^[0-9a-zA-Z\u0020\u0027\u002D\.\,\-\$]*$/;
//var regexpEmailChar = /^[\w\,-@]$/;
var regexpEmailChars = /^[0-9a-zA-Z\.\-\_\@]{1,}$/;
var regexpEmailChar = /^[0-9a-zA-Z\.\-\_\@]$/;
//var regexpEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var regexpEmail = /^[a-zA-Z]{1,}[0-9a-zA-Z\.\-\_]{1,}\@[0-9a-zA-Z\-\_]{2,}\.[a-zA-Z]{2,}$/;
var regexpCompany = /^[0-9a-zA-Z\u0020\u0026-\u0029\u002C-\u002E\u005F\u007B\u007D]*$/;
var regexpName = /^[0-9a-zA-Z\u0020\u0027\u002D]*$/;
var regexpWebpageChar = /^[0-9a-zA-Z\u0020\u0027\u002D\/\:\.\_\+\=\?\-\&]*$/;
var regexpWebpage = /^(http|https)\:\/\/[0-9a-zA-Z]{2,}\.[0-9a-zA-Z\:\_\+\=\?\-\&\.\/]{2,}$/;
var regexpAddress = /^[0-9a-zA-Z\u0020\u0026-\u0029\u002C-\u002E]*$/;
var regexpCity = /^[0-9a-zA-Z\u0020\u0026-\u0029\u002C-\u002E]*$/;
var regexpZip = /^[0-9a-zA-Z\u0020\u002D\u002F]*$/;
var regexpState = /^[0-9a-zA-Z\u0020\u002D\u002F]*$/;
var regexpTwoWords = /^[\w]+[\s][\w]+$/;

function inputKeyboardMasking (event, field, regexpr) {
   var key, keyChar;
   
   if (window.event)
      key = window.event.keyCode;
   else if (event)
      key = event.which;
   else
      return true;
   
   // Check for special characters
   if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
      return true;
   
   // Check if it is a number
   keyChar = String.fromCharCode(key);
   objInput = event.target || event.srcElement;
   
   if (field!='') {
      if (regexpr.test(keyChar)) {
         if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
         else $(field).className = 'custominput1';
         return true;
      } else {
         if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
         else $(field).className = 'custominput2';
         return false;
      }
   } 
   else {
      if (regexpr.test(keyChar)) {
         return true;
      } else {
         return false;
      }
   }
}

function inputPasteValidation (event, field, regexpr) { 
   if (window.clipboardData) {
      var strPasteData = window.clipboardData.getData("Text");
      objInput = event.target || event.srcElement;
      
       if (field!='') {
         if (regexpr.test(strPasteData)) {
            if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
            else $(field).className = 'custominput1';
            return true;
         } else {
            if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
            else $(field).className = 'custominput2';
            return false;
         }
      } 
      else {
         if (regexpr.test(strPasteData)) {
            return true;
         } else {
            return false;
         }
      }
   }
}

function inputChangeValidation (event, field, regexpr) {
   var objInput;

   objInput = event.target || event.srcElement;
  if (objInput.value.length==0) return true;
   if (field!='') {
      if (regexpr.test(objInput.value)) {
         if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
         else $(field).className = 'custominput1';
         return true;
      } else {
         if (objInput.tagName=='TEXTAREA') $(field).className = 'customtextarea2';
         else $(field).className = 'custominput2';
         return false;
      }
   } 
   else {
      if (regexpr.test(objInput.value)) {
         return true;
      } else {
         return false;
      }
   }
   
}

// X-Browser isArray(), including Safari
function isArray(obj) {
    return obj.constructor == Array;
}

function CheckFormFill(form, params, checktr) {
	
		if (!checktr) checktr=true;
		if (!params) params=Form.serializeElements( $(form).getInputs('text'), true );
		var hparams = $H(params);
		var ret=true;
		var patt1=new RegExp(/\[[0-9]{1,}\]/);
		hparams.each(function(pair) {
			 var oldkey=pair.key;	
 			 pair.key=pair.key.replace(/\[|\]/g, '');	  
				if (isArray(pair.value)==false && oldkey==pair.key) {
					if (pair.value=='' && $(pair.key+'_id_r') && $F(pair.key+'_id_r')==1 && $(pair.key+'_id_t').style.display!="none") { 
						if ($(pair.key+'_id_e_f')) $(pair.key+'_id_e_f').show();	
						$(pair.key+'_id_t').className='custominput2';
						ret=false;
					}
				}
				else if(patt1.test(oldkey) && isArray(pair.value)==true) {
				   for(i=0;i<=pair.value.length;i++) {
						j='';
						if ((!pair.value[i] || pair.value[i]=='') && $(pair.key+j+'_id_r') && $F(pair.key+j+'_id_r')==1 && $(pair.key+j+'_id_t').style.display!="none") {
							if ($(pair.key+j+'_id_e_f')) $(pair.key+j+'_id_e_f').show();	
							$(pair.key+j+'_id_t').className='custominput2';
							ret=false;
						}		
					}
				}
				else if(patt1.test(oldkey) && isArray(pair.value)==false) {				
						if ((pair.value=="") && $(pair.key+'_id_r') && $F(pair.key+'_id_r')==1 && $(pair.key+'_id_t').style.display!="none") {
							if ($(pair.key+'_id_e_f')) $(pair.key+'_id_e_f').show();		
							$(pair.key+'_id_t').className='custominput2';
							ret=false;
						}							
				}
				else {
					for(i=0;i<=pair.value.length;i++) {
						j=i+1;
						if ((!pair.value[i] || pair.value[i]=='') && $(pair.key+j+'_id_r') && $F(pair.key+j+'_id_r')==1 && $(pair.key+j+'_id_t').style.display!="none") {
							if ($(pair.key+j+'_id_e_f')) $(pair.key+j+'_id_e_f').show();	
							$(pair.key+j+'_id_t').className='custominput2';
							ret=false;
						}		
					}				  		 
																			  
									
		  		}
		  
		});	
   
		if (checktr==true) {
   		$$('#'+form+' td.errormsg1').find(function(s) {
         if ($(s.parentNode).style.display=='') { 
            //$(s.parentNode).scrollTo();
            ret=false; 
            return true; }
         });
      } 
		   
		return ret;
}

// Ajax functions
var onPressLoginError = false;
function CheckNewLogin(newlogin) {
   var valide='';
   if (onPressLoginError) {
      onPressLoginError = false;
      return;
   }
   $('newlogin_e').hide();
   $('error_newlogin_3').hide();
   $('ok_newlogin').hide();
   if (newlogin.value.length >= 8 && newlogin.value.length <= 20) {
      $('newlogin_e').hide();
      if (newlogin.value.match(regexpCYTALKid)) {
         $('error_newlogin_2').hide();
         
         new Ajax.Request("ajax/test_login.php", {
              method: 'post',
              parameters: "login=" + newlogin.value,
              onSuccess: function(transport) {
                  var response = transport.responseText;
                  if (response == "True") {
                     $('newlogin_t').className = 'custominput1';
                     $('error_newlogin_3').hide();
                     $('ok_newlogin').show();
                     valide = true;
                  } else {
                     $('newlogin_t').className = 'custominput2';
                     $('error_newlogin_3').show();
                     valide = false;
                  }
              }.bind(valide),
              onFailure: function() {
                  $('newlogin_t').className = 'custominput2';
                  $('error_newlogin_3').show();
                  valide = false; 
               
               }.bind(valide)
            });  

      } else {
         $('newlogin_t').className = 'custominput2';
         $('error_newlogin_2').show();
         valide = false;
      }
   } else {
      $('newlogin_t').className = 'custominput2';
      $('newlogin_e').show();
      valide = false;
   }
   
   return valide;  
}

// Input - Keyboard Masking
function isNumberInput(field, event) {
  var key, keyChar;

  if (window.event)
          key = window.event.keyCode;
  else if (event)
          key = event.which;
  else
          return true;

  // Check for special characters
  if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
          return true;

  // Check if it is a number
  keyChar = String.fromCharCode(key);
  if (/\d/.test(keyChar)) {
          window.status = "";
          return true;
  } else {
          window.status = "Field accepts numbers only.";
          return false;
  }
}

function isCountry(field, event) {
  var key, keyChar;

  if (window.event)
          key = window.event.keyCode;
  else if (event)
          key = event.which;
  else
          return true;

  // Check for special characters
  if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
          return true;

// Check if it is a number
   keyChar = String.fromCharCode(key);
   if (/^[a-zA-Z\u0020\u0027\u002D]$/.test(keyChar)) {
      return true;
   } else {
      return false;
   }
   return true;
 
}

/*Show and Hide submenu with mouseover and mouseout events for top menu*/
var submenutimeout = null;
var submenutimeout2 = null;
function showSubMenu(menuId) {
   $$('select').each(function(el){
                                  $(el).blur();
                                    });
   if (submenutimeout) {
      window.clearTimeout(submenutimeout);
      submenutimeout = null;
   }
   
   var i = 1;
   while ($('menu_'+i) != null) {
   	$('menu_'+i).hide();
   	i++;
   }
	$(menuId).show();
}

function hideSubMenu(menuId) {	
	$$('div.menu-hp-sub-sub').invoke('hide');
	$(menuId).hide();
	if (submenutimeout2) window.clearTimeout(submenutimeout2);
}

function hideSubMenuTimer(menuId) {
   if (submenutimeout) window.clearTimeout(submenutimeout);
   if (submenutimeout2) window.clearTimeout(submenutimeout2);
	submenutimeout = setTimeout(function(){hideSubMenu(menuId)}, 200);
}

function showSubMenuTimer(menuId) {
   if (submenutimeout2) window.clearTimeout(submenutimeout2);
	submenutimeout2 = setTimeout(function(){
	                                          $$('div.menu-hp-sub-sub').invoke('hide');
	                                          showSubMenu(menuId);
	                                          $$('div.menu-hp-sub-sub').each(function(elem) {
	                                                subelem = $($($(elem).childElements()[0]).childElements()[0]);
	                                                somewidth = subelem.getWidth();
                                                   elem.style.left = ( -3 - somewidth) +'px';
                                                      });
	                                          
	                                       }, 300);
}

function positionSubMenu(parentids) {
 $A(parentids).each(function (s, index) {
   if (index==0 && $$('td.menu-hp-nonreg-td-first').first()) {
       var offset=($$('td.menu-hp-nonreg-td-first').first().getWidth());
       if ($(s).children)
       	$($(s).children[0]).setStyle({top:0, left:'-'+offset+'px', position: 'absolute', display: 'block'});
   }
   else if ($(s) && $$('td.menu-hp-nonreg-td-separator').toArray().length>0) {
      var offset=($$('td.menu-hp-nonreg-td-separator').toArray()[0].getWidth()/2).round(); 
      if ($(s).children)
      	$($(s).children[0]).setStyle({top:0, left:'-'+offset+'px', position: 'absolute', display: 'block'});
   }     
   })    
}

function buttonState(button_id, state) {
   if ($(button_id)) {
      button = $(button_id);
      if ((state==0 || state==false) && button.className!='graybutton') {
         button.className='graybutton';
         button.style.cursor = 'default';
         //offset = button.viewportOffset();
         elem = new Element('div');
         elem.id=button_id+'_hidediv';
         elem.clonePosition(button).setStyle({top: 0, left:(button.offsetLeft-10)+'px', position: 'relative', height:0, width: 0 });    
         elem2 = new Element('div');
         elem2.setStyle({zIndex: 100000, position: 'absolute', width: button.getWidth()+20+'px',  height: button.getHeight()+'px'}); 
         elem.update(elem2);
         button.insert({before: elem});      
      }
      else if ((state==1 || state==true) && button.className!='bluebutton') {
         button.className='bluebutton';    
         button.style.cursor = 'pointer'; 
         $(button_id+'_hidediv').remove();
      }
   
   }
}

function bubleShow(id, sender, content, type, params) {
   if ($(id)) $(id).show();
   else {
      if (!params) params={};
      if (!params.left) params.left=(10+$(sender).offsetLeft);
      
      if (!type) type=1;
      new Ajax.Request("/ajax/buble.php", {
              method: 'post',
              parameters: 'content='+content+'&id='+id+'&left='+params.left+'&type='+type,
              onComplete: function(transport) {
                  if(!$(id)) $(sender).insert({after: transport.responseText});  
                  $(id).show();
            }.bind(sender).bind(id)
      });   
   }
}

function bigBubleShow(params) {
   if (bubleTimer[params.id]) clearTimeout(bubleTimer[params.id]);
   if ($(params.id)) $(params.id).show();
   else {
      if (!params.left) params.left=(10+$(sender).offsetLeft);
      if (!params.type) params.type=1;
      new Ajax.Request("/ajax/bigbuble.php", {
              method: 'post',
              parameters: params,
              onComplete: function(transport) {
                  if(!$(params.id)) $(params.sender).insert({after: transport.responseText});  
                  $(params.id).show();
            }.bind(params)
      });   
   }
}

var bubleTimer=new Array();
function bubleHide(id) {
   if ($(id)) bubleTimer[id]=setTimeout("$('"+id+"').hide();", 500);
   else bubleTimer[id]=setTimeout("bubleHide('"+id+"');", 500);
}

function ajaxGettext(elem, attr, text) {
   new Ajax.Request("/ajax/get_langvar.php", {
              method: 'post',
              parameters: {langvar: text},
              onComplete: function(transport) {
                  eval('elem.'+attr+'=transport.responseText');
            }.bind(elem).bind(attr)
      }); 
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
   var today = new Date();
   today.setTime( today.getTime() );

   if ( expires ) {
   expires = expires * 1000 * 60 * 60 * 24;
   }
   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 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 ConferenceAddNumber(popupname) { 
   if (!ConferenceValidate('')) return false;
   
   table = $('conferencenumbers');
   newrow = $(table.insertRow(table.rows.length));
   newrow.identify();
   if (table.rows.length%2) newrow.className = 'greyline';   
   else newrow.className = 'whiteline';
   $(newrow.insertCell(0)).update(table.rows.length-1).setStyle({color:'#000000'});
   $(newrow.insertCell(1)).update($F('number_id')).setStyle({color:'#000000'}).className="nopadding";
   $(newrow.insertCell(2)).update($F('name_id')).setStyle({color:'#000000', textAlign:'center'}).className="nopadding";
   $(newrow.insertCell(3)).update($F('email_id')).setStyle({color:'#000000', textAlign:'center'}).className="nopadding";

      
   ajaxGettext($(newrow.insertCell(4)).update(new Element('img', {width:16, height:16, onclick:"ConferenceEditNumber('"+newrow.id+"')", style:'cursor: pointer;', alt:'edit', src:'images/icons/edit.png'})).insert({bottom:'&nbsp;'}).insert({bottom: new Element('a', {href:'#', 'class':'bluelink', onclick:"ConferenceEditNumber('"+newrow.id+"')"})}).setStyle({textAlign:'right', padding:'0px'}).select('a').first(), 'innerHTML', "UI Msg1871");
   
   ajaxGettext($(newrow.insertCell(5)).update(new Element('img', {width:16, height:16, onclick:"ConferenceRemoveNumber('"+newrow.id+"')", style:'cursor: pointer;', alt:'delete', src:'images/phones/member/voicemail/trash.png'})).insert({bottom:'&nbsp;'}).insert({bottom: new Element('a', {href:'#', 'class':'bluelink', onclick:"ConferenceRemoveNumber('"+newrow.id+"')"})}).setStyle({textAlign:'right', padding:'0 10px 0 0'}).select('a').first(), 'innerHTML', "UI Msg1872");
   
   ajaxGettext($('number_id'), 'value', 'UI Msg1873');
   $('name_id').value="";
   $('email_id').value="";
   $('number_id_t').className='custominput1';
   $('name_id_t').className='custominput1';
   $('email_id_t').className='custominput1';
   GetScrollElement(popupname+'_scroll_1').Reload();
   return false;
}

function ConferenceRemoveNumber(row_id) {
   table = $('conferencenumbers');
   $(row_id).remove();
   $A(table.rows).each(function (row, index) {
      if (index<1) return;
      if (index%2) row.className='whiteline';
      else row.className='greyline';
      row.select('td').first().update(index-1) ;
   });
   GetScrollElement('meeting_scroll_1').Reload();
   return false;
}

function ConferenceRemoveSchedule(sender) {
   table = $('sheduleitems');
   $(sender.parentNode.parentNode).remove();
   $A(table.rows).each(function (row, index) {
      if (index%2) row.className='whiteline';
      else row.className='greyline';
      row.select('td').first().update(index+1) ;
   });
   GetScrollElement('meeting_scroll_1').Reload();
   return false;
}
function ConferenceRemoveAllSchedule() {
   table = $('sheduleitems');
   $A(table.rows).invoke('remove');
   GetScrollElement('meeting_scroll_1').Reload();
   return false;
}


function ConferenceEditNumber(row_id) {
   row = $(row_id);
   CreateStylizedInput($(row.cells[1]), {name: 'number'+row_id, value: $(row.cells[1]).innerHTML, style:'width:130px;', required: 1, regexp: 'regexpNumberWSpace', after: '<img width="16" height="16" border="0" alt="" src="../images/phones/directory/directory16.png" >'});
   CreateStylizedInput($(row.cells[2]), {name: 'name'+row_id, value: $(row.cells[2]).innerHTML, style:'width:180px;', required: 1, regexp: 'regexpName', align:'center'});
   CreateStylizedInput($(row.cells[3]), {name: 'email'+row_id, value: $(row.cells[3]).innerHTML, style:'width:180px;', required: 0, regexp: 'regexpEmailChars', align:'center'});
   
   ajaxGettext($(row.cells[4]).update(new Element('img', {width:16, height:16, onclick:"ConferenceSaveNumber('"+row_id+"')", style:'cursor: pointer;', alt:'save', src:'images/phones/member/voicemail/load.png'})).insert({bottom:'&nbsp;'}).insert({bottom: new Element('a', {href:'#', 'class':'bluelink', onclick:"ConferenceSaveNumber('"+row_id+"')"})}).select('a').first(), 'innerHTML', "UI Msg1874");     
}
function ConferenceValidate(row_id) {
      var valid=true;
      valid= valid && ($F('number'+row_id+'_id').length>0) && inputChangeValidation({target: $('number'+row_id+'_id')}, 'number'+row_id+'_id_t', regexpNumberWSpace);
      if ($F('number'+row_id+'_id').length==0) $('number'+row_id+'_id_t').className="custominput2";
      valid= valid && ($F('name'+row_id+'_id').length>0) && inputChangeValidation({target: $('name'+row_id+'_id')}, 'name'+row_id+'_id_t', regexpName);
      if ($F('name'+row_id+'_id').length==0) $('name'+row_id+'_id_t').className="custominput2";
      if ($F('email'+row_id+'_id').length>0) valid= valid && inputChangeValidation({target: $('email'+row_id+'_id')}, 'email'+row_id+'_id_t', regexpEmail);
      return valid;
}

function ConferenceSaveNumber(row_id) {
   if (!ConferenceValidate(row_id)) return false;  
   row = $(row_id);
   ajaxGettext($(row.cells[4]).update(new Element('img', {width:16, height:16, onclick:"ConferenceEditNumber('"+row_id+"')", style:'cursor: pointer;', alt:'edit', src:'images/icons/edit.png'})).insert({bottom:'&nbsp;'}).insert({bottom: new Element('a', {href:'#', 'class':'bluelink', onclick:"ConferenceEditNumber('"+row_id+"')"})}).select('a').first(), 'innerHTML', "UI Msg1871"); 
   $(row.cells[1]).update($(row.cells[1]).select('input').first().value);
   $(row.cells[2]).update($(row.cells[2]).select('input').first().value);
   $(row.cells[3]).update($(row.cells[3]).select('input').first().value);
}

function CreateStylizedInput(place, params) {
   new Ajax.Request("/ajax/get_input.php", {
           method: 'post',
           parameters: params,
           onComplete: function(transport) {
               $(place).update(transport.responseText);
         }.bind(place)
   }); 
};

function ConferencePopupInit() {
   AjaxChangeTab($('tab0'), {popupname: 'meeting', address: 'ajax/meeting0.php'});
}

function ConferenceChangeType(type) {
   if(type==0) {
      $('shedule_controls').hide();
      $('record_controls').show();    
      $('shedule_notify').hide();
      $('shedule_datetime').hide();
   }
   else if (type==1) {
      $('shedule_controls').show();
      $('record_controls').hide(); 
      $('shedule_notify').show(); 
      $('shedule_datetime').show();
   }
}

function AjaxChangeTab(sender, params) {
   $$('table.profiletab_selected').each(function(elem) { elem.className="profiletab"; })
   sender.className="profiletab_selected";
   $(params.popupname+'_load_spinner').show();
   $(params.popupname+'_content').hide();   
   new Ajax.Request(params.address, {
           method: 'post',
           parameters: params,
           onComplete: function(transport) {
               $(params.popupname+'_content').update(transport.responseText);
               $(params.popupname+'_load_spinner').hide();
               $(params.popupname+'_content').show();
               if ($(params.popupname+'_pers1_scroll_table')) TextScrollSimple(params.popupname);
               AddDateTimeCalendar('trigger_shedule_datetime', 'shedule_datetime_value');
         }.bind(params)
   });
}

function AddDateTimeCalendar(id, field) {
    if ($(id)) {
                  new Calendar({
                          inputField: field,
                          dateFormat: "%Y-%m-%d %H:%M",
                          trigger: id,
                          bottomBar: false,
                          showTime :  true,
                          onSelect: function() {
                                  this.hide();
                          }
                  });
               }
}

function StartConference(popupname, params) {
   if ($('filename_id')) {
      if ($F('filename_id').length==0) {
         $('filename_id_t').className="custominput2";
         return false;
      }    
   }
   // someaction
   //on complete
   GetPopupElement(popupname).Remove();
   if (params.popupname) {
      var popup = GetPopupElement(params.popupname);
      if (popup) popup.Remove();
   }
   AjaxChangeTab($('tab1'), { popupname: params.parent_popupname, address: 'ajax/meeting1.php'});
   
}

function ScheduleConference(popupname, params) {
   if ($('filename_id')) {
      if ($F('filename_id').length==0) {
         $('filename_id_t').className="custominput2";
         return false;
      }    
   }
   // someaction
   //on complete
   GetPopupElement(popupname).Remove();
   if (params.popupname) {
      var popup = GetPopupElement(params.popupname);
      if (popup) popup.Remove();
   }
   AjaxChangeTab($('tab3'), { popupname: params.parent_popupname, address: 'ajax/meeting3.php'});
   
}

function ScheduleEditConference(popupname) {
   var params={parent_popupname: popupname, type:1}
   var scheduleeditconference = Popupv2({name:'scheduleeditconference', style:1, title:'UI Msg1897', address:'ajax/meeting0.php', parameters:params, filter_color:'#000000', filter_opacity:65}); scheduleeditconference.EnableHelp('UI Help0301', 'UI Help0302');
   scheduleeditconference.onLoad=function() { AddDateTimeCalendar('trigger_shedule_datetime', 'shedule_datetime_value'); }
   
}
function ScheduleDetailConference(params) {
   var scheduledetailsconference = Popupv2({name:'scheduledetailsconference', style:1, title:'UI Msg1898', address:'ajax/meeting_info.php', parameters:params, filter_color:'#000000', filter_opacity:65}); 
   scheduledetailsconference.EnableHelp('UI Help0305', 'UI Help0306');
   
}

function HistoryDetailConference(params) {
   var historydetailsconference = Popupv2({name:'historydetailsconference', style:1, title:'UI Msg1903', address:'ajax/meeting_info2.php', parameters:params, filter_color:'#000000', filter_opacity:65}); 
   historydetailsconference.EnableHelp('UI Help0307', 'UI Help0308');
   
}

var conferenceManagementUpdater=null;

function setCMUpdater() {
   unsetCMUpdater();
   conferenceManagementUpdater = setTimeout(function() { $('tab1').onclick(); }, 1000*60);
}

function CMUpdate() {
   unsetCMUpdater();
   $('tab1').onclick();  
   setCMUpdater();
}

function unsetCMUpdater() {
   if (conferenceManagementUpdater) clearTimeout(conferenceManagementUpdater);
}

function outLink(link) {
   document.location.href=link;  
}

function CloseSubscribe(){
   $('subscribe_popup').fade({duration:0.3});
   $$('body').first().setStyle({overflow: 'auto', overflowX: 'hidden'});
   $$('html').first().setStyle({overflow: 'auto', overflowX: 'hidden'});
}

function SubmitSubscribe(){
   if (!CheckFormFill('subscribe_form', false, false)) return false;
   new Ajax.Request('/ajax/save_subscribtion.php', {
           method: 'post',
           parameters:$('subscribe_form').serialize(),
           onSuccess: function() {
               Set_Cookie('subscribed', '1', 60*60*24*365, '/', '', '');
               CloseSubscribe()
           }
   });
}

function LoadSubscribe(){ 
   if (Get_Cookie('subscribed')) return true;
   new Ajax.Request('/ajax/subscribe.php', {
           method: 'post',
           onComplete: function(transport) {
               $$('body').first().insert({bottom:transport.responseText});
               var pos = (Prototype.Browser.IE==true)?'absolute':'fixed';
               $('subscribe_popup').setStyle({left:Math.floor(((document.viewport.getWidth()-$('subscribe_popup').getWidth())/2))+'px', 
                                               top:Math.floor(((document.viewport.getHeight()-$('subscribe_popup').getHeight())/2))+'px',
                                               position: pos});
               $('subscribe_popup').appear({duration:0.3});
               $$('body').first().scrollTo();
               $$('body').first().setStyle({overflow: 'hidden'});
               $$('html').first().setStyle({overflow: 'hidden'});
         }
   });
}