/*
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
# Copywrite: Ezone Solutions
# Created By: Prosenjit Debnath
# Creation Date: 2006-09-12
# Modified Date: 2006-09-20
# Description: Here we have written all general javascript functions.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
*/

function open_popup(url, parameters) {
	//window.open( "http://www.google.com/", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" )
	window.open(url, "myWindow", parameters)
}

function populate_sale_property(){
	var current_address     = frm_fsbo_registration.elements['current_address'].value;
	var current_unit        = frm_fsbo_registration.elements['current_unit'].value;
	var current_city        = frm_fsbo_registration.elements['current_city'].value;
	var current_state       = frm_fsbo_registration.elements['current_state'].value;
	var current_postal_code = frm_fsbo_registration.elements['current_postal_code'].value;

	if(!frm_fsbo_registration.elements['chk_same_address'].checked){
		var current_address     = "";
		var current_unit        = "";
		var current_city        = "";
		var current_state       = 0;
		var current_postal_code = "";
	}
	
	frm_fsbo_registration.elements['sale_property_address'].value    = current_address;
	frm_fsbo_registration.elements['sale_property_unit'].value       = current_unit;
	frm_fsbo_registration.elements['sale_property_city'].value       = current_city;
	frm_fsbo_registration.elements['sale_property_state'].value      = current_state;
	frm_fsbo_registration.elements['sale_property_postal_code'].value= current_postal_code;
}

function char_counter(){
	var max_chars = parseInt(frm_fsbo_registration.elements['home_features_add_desc_chars'].value);
	max_chars--;
	frm_fsbo_registration.elements['home_features_add_desc_chars'].value = max_chars;
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.replace(/[\n\r\n]/g,'  ').length > maxlimit){
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit-(field.value.replace(/[\n\r\n]/g,'  ').length-field.value.length));
	}// otherwise, update 'characters left' counter
	else{
		cntfield.value = maxlimit - field.value.replace(/[\n\r\n]/g,'  ').length;
	}	
}

function check_test_map(){
	current_address     = document.getElementById("pro_add_st_address").value;
	current_city        = document.getElementById("pro_add_city").value;
	current_state       = document.getElementById("pro_add_state").value;
	current_postal_code = document.getElementById("pro_add_postal_code").value;
	map_address = current_address + ','  + current_city  + ',' + current_state + ',' + current_postal_code;
	//self.location = 'http://maps.google.com/maps?q='+ map_address +'&hl=en';
	open_popup('http://maps.google.com/maps?q='+ map_address +'&hl=en', 'status = 1, height = 500, width = 600, resizable = 1');
}

// INTEGER CHECKING FUNCTIONS STARTS
function getkey(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}
function goodchars(e, goods)
{
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	// else return false
	return false;
}
// INTEGER CHECKING FUNCTIONS ENDS

function show_hide(show_hide_id, show_hide_text_id, show_text, hide_text){
	if( document.getElementById(show_hide_id).style.display=='none' ){
		document.getElementById(show_hide_id).style.display = 'block';
		document.getElementById(show_hide_text_id).innerHTML= hide_text;
	}else{
		document.getElementById(show_hide_id).style.display = 'none';
		document.getElementById(show_hide_text_id).innerHTML= show_text;
	}
	//alert('ok');
}

// FOR ATTO TAB
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)
			index = i;
		else 
			i++;
		return index;
	}
return true;
}

//############################################//
//######  Function for Numaric Value  ########// added by hetal
//############################################//
function numbersonly(evnt)
{
var unicode=evnt.charCode? evnt.charCode : evnt.keyCode
	if (unicode<46||unicode>57 || unicode==47){
		if(unicode == 43 || unicode == 32 || unicode == 8 || unicode == 9)
			return true;
		else
			return false;
	}
}
