
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
var rv = 0

// Browser detect

var browserType = navigator.appName

if (browserType == 'Microsoft Internet Explorer'){
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
}else if(browserType == 'Netscape'){
    var ua = navigator.userAgent;
    var re  = new RegExp("Firefox/([0-9]\.[0-9]{1,2})\.[0-9]{1,4}");
    
    if (re.exec(ua) != null){rv = RegExp.$1;}
	browserType = 'Firefox';
}else{
	browserType = 'none';
	rv = 0
}
 
var browserVersion = rv;


// home pager
var currentHomeAuto = true
var currentHomePage = 1
var maxHomePage = 5
var homeTimer

function homepager(id){
	try{clearTimeout(homeTimer)}catch(err){}
	$('homeaji_' + currentHomePage).fade({duration:0.8})
	$('homeajibutt_' + currentHomePage).removeClassName('active')	
	$('homeaji_' + id).appear({duration:0.8})
	$('homeajibutt_' + id).addClassName('active')
	currentHomePage = id
}

function homepager_next(){
	var myid 
	if(currentHomePage < maxHomePage){
		myid = currentHomePage+1
	}else{
		myid = 1
	}
	homepager(myid)
}

function homepager_prev(){
	var myid 
	if(currentHomePage > 1){
		myid = currentHomePage-1
	}else{
		myid = maxHomePage
	}
	homepager(myid)
}

function homepager_run(){
	clearTimeout(homeTimer)
	homepager_next()
	homeTimer = setTimeout("homepager_run()",5000);
}

function homepager_auto(){
	homeTimer = setTimeout("homepager_run()",5000);
	
}


var inpDefs = new Array() 
var inpTypes = new Array()
var inpDefTypes = new Array()
var initInputs = new Array()
var readAttrbs = new Array('type', 'name', 'id', 'style', 'class', 'onclick')

function initInputfield(inpId, defText, changeType){
	inpTypes[inpId] = changeType
	inpDefTypes[inpId] = $(inpId).readAttribute('type')
	inpDefs[inpId] = defText
	initInputs.push(inpId)
	$(inpId).blur()
	$(inpId).onfocus = autoinputFocus
	$(inpId).onblur = autoinputBlur
	$(inpId).autocomplete = 'off'
	$(inpId).value = defText
	
}

function noSendDefValues(){
	for(var n=0; n<initInputs.length; n++){
		if($(initInputs[n]).value == inpDefs[initInputs[n]]){
			$(initInputs[n]).value = ''
		}
	}
}

function autoinputFocus(){
	if(this.value == inpDefs[this.id]){
		
		this.removeClassName('autoInput')
		this.addClassName('autoInput_selected')
		this.value = ''
		
		
		if(inpTypes[this.id] !== undefined){
			if (browserType == 'Microsoft Internet Explorer'){
				var newObj = htmlObj2String(this)
				newObj = changeIeType(newObj, inpDefTypes[this.id], inpTypes[this.id])
				var thisId = this.id
				
				new Insertion.After(this, newObj)
				this.remove()
				$(thisId).onfocus = autoinputFocus
				$(thisId).onblur = autoinputBlur
				$(thisId).focus()
				
			}else{
				this.writeAttribute('type', inpTypes[this.id])
			}
			
		}
	}
}

function autoinputBlur(){
	if(this.value == ''){
		this.removeClassName('autoInput_selected')
		this.addClassName('autoInput')
		this.value = inpDefs[this.id]
		
		if(inpTypes[this.id] !== undefined){
			if (browserType == 'Microsoft Internet Explorer'){
				var newObj = htmlObj2String(this)
				newObj = changeIeType(newObj, inpTypes[this.id], inpDefTypes[this.id])
				var thisId = this.id
				var retValue = inpDefs[this.id]
				new Insertion.After(this, newObj)
				this.remove()
				$(thisId).onfocus = autoinputFocus
				$(thisId).onblur = autoinputBlur
				$(thisId).value = retValue
				$(thisId).blur()
			}else{
				this.type = inpDefTypes[this.id]
			}
		}
	}
}

function changeIeType(str, oldType, newType){
	var newstr = str.split('type="'+oldType+'"').join('type="'+newType+'"')
	return newstr
}

function htmlObj2String(obj){
	var myAttrbs = new Array()
	for(var n=0; n<readAttrbs.length; n++){
		myAttrbs[n] = obj.readAttribute(readAttrbs[n])
	}
	
	var attrbString = ''
	for(var z=0; z<readAttrbs.length; z++){
		if(myAttrbs[z] !== null){
			attrbString = attrbString + ' ' + readAttrbs[z] + '="' + myAttrbs[z] + '"'
		}
	}
	
	attrbString = '<input '+ attrbString +'/>';
	
	return attrbString
}


function textareaCounter(num, areaid, charid, maxid){
	if($(areaid).value.length < (num+1)){
		$(charid).innerHTML = $(areaid).value.length
	}else{
		$(areaid).value = $(areaid).value.substring(0, num);
	}
}

function insertInArea(target, type, data){
	var selection
	alert(target)
	
	//IE support

		if (document.selection) {

			target.focus();

			selection = document.selection.createRange();

			//sel.text = myValue;

		}
		
		else if (target.selectionStart || target.selectionStart == '0') {

			var startPos = target.selectionStart;

			var endPos = target.selectionEnd;

			//myField.value = myField.value.substring(0, startPos) + myField.value.substring(endPos, myField.value.length);
			selection = target.value.substring(0, startPos) + target.value.substring(endPos, target.value.length);

		} else {

			selection = target.value

		}
		
		alert(selection)
	

}

function insertAtCursor(myField, type, myValue) {
		var tags
		switch(type){
			case 'smile': 
				tags = new Array('', '')
				myValue = myValue; 
				break;
			case 'format': 
				tags = myValue.split('|')
				myValue = '';
			break;
			default: break;
		}

		//IE support

		if (document.selection) {

			myField.focus();

			sel = document.selection.createRange();
			
			//alert(sel.text)
			if(type == 'format'){
				sel.text = tags[0] + sel.text + tags[1];
			}else{
				sel.text = myValue;
			}

		}

		//MOZILLA/NETSCAPE support

		else if (myField.selectionStart || myField.selectionStart == '0') {

			var startPos = myField.selectionStart;

			var endPos = myField.selectionEnd;
			
			
			if(type == 'format'){
				myValue = tags[0] + myField.value.substring(startPos, endPos)+ tags[1]
			}
			
			//alert()

			myField.value = myField.value.substring(0, startPos)

			+ myValue

			+ myField.value.substring(endPos, myField.value.length)
			
			;

		} else {

			myField.value += myValue;

		}

	}
	
	

