/*
 * EstateVue Widgets
 * JavaScript Common Library v.2.0
 * author Sigit N <info[at]antibiasa[dot]net>
 * August 2010
 * 
 * Copyright EstateVue 2010. All right reserved.
 */

var pullit,drawit,e,ajax;
var state = 'hide';
//var site_url = 'http://localhost/estatevue_new2/';
var widget_site_url = 'http://v2.estatevue.com/';
function togglecb(el){
	e = getElement(el);
	if(state == 'hide'){
		e.style.opacity = 0;
		e.style.display = 'block';
		pullit = setInterval("pullIn()",75);
		state = 'show';
	} else {
		e.style.opacity = .99;
		drawit = setInterval("pullOut()",75);
		state = 'hide';
	}
}

function pullIn(){
	var opacity = parseFloat(e.style.opacity) + .5;
	if(opacity > .99) opacity = .99;
	if(opacity >= .99) clearInterval(pullit);
	e.style.opacity = opacity;
	e.style.MozOpacity = opacity;
	e.style.filter = 'alpha(opacity=' + (opacity*100) + ')';
}

function pullOut(){
	var opacity = parseFloat(e.style.opacity) - .5;
	if(opacity < 0) opacity = 0;
	if(opacity <= 0){ 
		clearInterval(drawit);
		e.style.display = 'none';
	}
	e.style.opacity = opacity;
	e.style.MozOpacity = opacity;
	e.style.filter = 'alpha(opacity=' + (opacity*100) + ')';
}

function cancelPull(e){
	e.style.opacity = .99;
}

function clearTextField(e,text){
	var value = e.value;
	if(value == text) e.value = '';
}

function fillTextField(e,text){
	var value = e.value;
	if(value == '') e.value = text;
}

function getElement(id){
	return document.getElementById(id);
}

function loadScript(url,callback){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = url;
	
	//calling a function after the js is loaded (IE)  
    var loadFunction = function(){  
    	if (this.readyState == 'complete' || this.readyState == 'loaded') {
    		callback();   
    	}  
    };  
    script.onreadystatechange = loadFunction;  
    //calling a function after the js is loaded (Firefox)  
    script.onload = callback; 
    document.getElementsByTagName('head')[0].appendChild(script);
}

function evLoadEvent(func){
	if (window.attachEvent) {
		window.attachEvent("onload", func);
	} else {
		window.addEventListener("load", func, false);
	}
}

function ucwords(str){
	return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
        return $1.toUpperCase();
    });
}
