var DHTML = (document.getElementById || document.all || document.layers);
var num = 0;

function chkclientSignUpform(obj){
		if(obj.user_name.value=="")
		{
		alert("Please enter Username.");
		obj.user_name.focus();
		return false;
		}
		
		if(obj.user_pass.value=="")
		{
		alert("Please enter Password.");
		obj.user_pass.focus();
		return false;
		}
		
		if(obj.confirm_pass.value=="")
		{
		alert("Please enter Confirm Password.");
		obj.confirm_pass.focus();
		return false;
		}	
		
		if(obj.user_pass.value != obj.confirm_pass.value)
		{
		alert("Confirm Password not matching with Password.");
		obj.confirm_pass.focus();
		return false;		
		}	

		val=document.getElementById("user_email").value;
		
		if(val=="")
		{
		alert("Please enter Email.");
		return false;
		}
		val=document.getElementById("user_email").value;
		val1=document.getElementById("user_email");
		if ((val==null)||(val=="")){
			alert("Please enter Email.")
			val1.focus()
			return false;
		}
		val=document.getElementById("user_email").value;
		val1=document.getElementById("user_email");
		if (echeck(val)==false){
			val1.value=""
			val1.focus()
			return false;
		}

		if(obj.user_account_type.value=="")
		{
		alert("Please choose a Account Type.");
		obj.user_account_type.focus();
		return false;
		}	

		if(obj.user_company_name.value=="")
		{
		alert("Please enter Company Name.");
		obj.user_company_name.focus();
		return false;
		}

		if(obj.contact_name.value=="")
		{
		alert("Please enter Name.");
		obj.contact_name.focus();
		return false;
		}
		
		if(obj.contact_address_street1.value=="")
		{
		alert("Please enter Address Street 1.");
		obj.contact_address_street1.focus();
		return false;
		}		

		if(obj.contact_city.value=="")
		{
		alert("Please enter City.");
		obj.contact_city.focus();
		return false;
		}

		if(obj.contact_postal_code.value=="")
		{
		alert("Please enter Zip.");
		obj.contact_postal_code.focus();
		return false;
		}

		if(obj.contact_phone.value=="")
		{
		alert("Please enter Phone.");
		obj.contact_phone.focus();
		return false;
		}

}

function jm_phonemask(t)
			{
			var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
			var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
			var str = t.value;
			var result;
			if (!str.match(patt2))
			{result = str.match(patt1);
			if (result!= null)
			{t.value = t.value.replace(/[^\d]/gi,'');
			//str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
			str = result[1] + '-' + result[2] + '-' + result[3];
			t.value = str;
			}else{
			if (t.value.match(/[^\d]/gi))
			t.value = t.value.replace(/[^\d]/gi,'');
			}}}
			
function intOnly(i)
{
		if(i.value.length>0)
		{
			i.value = i.value.replace(/[^\d]+/g, ''); 
		}
}	

function _ (myvar) {
	return encodeURIComponent(myvar);	
}

function linkTo(url, div) {

	if(!objExist(div)) {	
		alert('Unable to link to ('+div+').');
		return false;
	}
	divDsp(div,'inline');
	var ajax = new hollerBack('GET','/ajax.php'+url, '', div);
	return ajax;
}

function removeEntity(url, div, msg) {

	if(!objExist(div)) {	
		alert('Unable to remove ('+div+').');
		return false;
	}
	
	var doThis = confirm(msg);
	
	if(doThis) {
		var ajax = new holler('POST','/ajax.php', url,  Effect.DropOut(div) );
	}
	
	return doThis;
}

function linkToToggle(url, div) {

	if(!objExist(div)) {	
		alert('Unable to link to ('+div+').');
		return false;
	}
	divDsp(div);
	var ajax = new hollerBack('GET','/ajax.php'+url, '', div);
}

function submitTo(formObj, action, div, url, _onload) {
	if(!objExist(div)) {	
		alert('Unable to submit this form '+div);
		return false;
	}
	var ajax = new hollerAtMe('POST', formObj, '/ajax.php?action='+action+'&'+url, div, _onload);
	return ajax;
}
//submitTo_2(this,'secure_form','appraisal_view','secure.php', function(){ linkTo('?module=client.current_view','current_view'); linkTo('?module=client.dashboard_current_view','dashboard_current_view');} );
function submitTo_2(formObj, action, div, url, _onload) {
	if(!objExist(div)) {	
		alert('Unable to submit this form '+div);
		return false;
	}
	var ajax = new hollerAtMe('POST', formObj, url, div, _onload);
	return ajax;
}
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) IsNumber = false;
   }
   
   return IsNumber;
}

function redirect(url){
	window.location.href = url;
}

function concatenateNames()
{
//alert('debug');
var val;
val=document.getElementById('fee_select').value;
	if(val=="")
	{
	alert("Please select job type !");
	return false;
	}
	else
	{
//alert(document.getElementById('borrower').value);
//alert(document.getElementById('borrower_middle').value);
//alert(document.getElementById('borrower_last').value);

document.getElementById('borrower').value=document.getElementById('borrower_last').value+', '+document.getElementById('borrower').value+' '+document.getElementById('borrower_middle').value;
//alert(document.getElementById('borrower').value);

//alert(document.getElementById('coborrower').value);
//alert(document.getElementById('coborrower_middle').value);
//alert(document.getElementById('coborrower_last').value);
document.getElementById('coborrower').value=document.getElementById('coborrower_last').value+', '+document.getElementById('coborrower').value+' '+document.getElementById('coborrower_middle').value;
//alert(document.getElementById('coborrower').value);


//alert(document.getElementById('owner').value);
//alert(document.getElementById('owner_middle').value);
//alert(document.getElementById('owner_last').value);
document.getElementById('owner').value=document.getElementById('owner_last').value+', '+document.getElementById('owner').value+' '+document.getElementById('owner_middle').value;
//alert(document.getElementById('owner').value);


//alert(document.getElementById('other').value);
//alert(document.getElementById('other_middle').value);
//alert(document.getElementById('other_last').value);
document.getElementById('other').value=document.getElementById('other_last').value+', '+document.getElementById('other').value+' '+document.getElementById('other_middle').value;
//alert(document.getElementById('other').value);
return true;
	}
}
function ValidateAmount(obj,eveglob)
{
var key = eveglob.which ? eveglob.which : eveglob.keyCode;
//alert(key);
var n=obj.id;
//alert(n);
var p=document.getElementById(n).value;
var q=(p.length);
//var s=Math.round(q/3);
//alert(s);
//alert(q);
if(key!=8 && key!=46 && key!=44)
	{
	if(p.length==3)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==7)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==11)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==15)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==19)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==23)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==27)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==31)
		{
		document.getElementById(n).value=p+',';
		}
	else if(p.length==35)
		{
		document.getElementById(n).value=p+',';
		}
	}
}

function ValidatePhone(obj,eveglob)
{
var key = eveglob.which ? eveglob.which : eveglob.keyCode;
//alert(key);
var n=obj.id;
//alert(n);
var p=document.getElementById(n).value;
if(key!=8 && key!=46 && key!=45)
	{
	if(p.length==3)
		{
		document.getElementById(n).value=p+'-';
		}
	else if(p.length==7)
		{
		document.getElementById(n).value=p+'-';
		}
	}
}

function funShowOwner()
{
//document.getElementById("test").style.display='';
if((document.getElementById( "showOwner").style.display=='none') || (document.getElementById("showOwnerHome").style.display=='none') || (document.getElementById("showOther").style.display=='none') || (document.getElementById("showOtherHome").style.display=='none'))
	{
//	alert("show");
	document.getElementById("showOwner").style.display='';
	document.getElementById("showOwnerHome").style.display='';
	document.getElementById("showOther").style.display='';
	document.getElementById("showOtherHome").style.display='';
	}
	else
	{
//	alert("hide");
	document.getElementById("showOwner").style.display='none';
	document.getElementById("showOwnerHome").style.display='none';
	document.getElementById("showOther").style.display='none';
	document.getElementById("showOtherHome").style.display='none';
	}
}


function funShowOwner_AC()
{
//document.getElementById("test").style.display='';
if((document.getElementById("showOwner").style.display=='none') || (document.getElementById("showOwnerHome").style.display=='none') || (document.getElementById("showOther").style.display=='none') || (document.getElementById("showOtherHome").style.display=='none'))
	{
//	alert("show");
	document.getElementById("showOwner").style.display='';
	document.getElementById("showOwnerHome").style.display='';
	document.getElementById("showOther").style.display='';
	document.getElementById("showOtherHome").style.display='';
	}
	else
	{
//	alert("hide");
	document.getElementById("showOwner").style.display='none';
	document.getElementById("showOwnerHome").style.display='none';
	document.getElementById("showOther").style.display='none';
	document.getElementById("showOtherHome").style.display='none';
	}
}
/*
function validateJobType()
{
var client_id=document.getElementById('client_id').value;
var fee_select=document.getElementById('fee_select').value;

if(client_id=="")
	{
	alert('Please select the Client..!');
	return false;
	}
else if(fee_select=="")
	{
	alert('Please select the Job type!');
	return false;
	}
	else
	{
	return true;
	}
}
*/
function getObj(name) {
	if( typeof(name) == 'object' ) {
		this.obj = name;
	} else {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		} else if (document.all)  {
			this.obj = document.all[name];
		} else if (document.layers)  {
			this.obj = document.layers[name];
		}
	}
	return this.obj;
}

function objExist(name) {

	if( typeof(name) == 'object' ) {
		return true;
	} else {
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		} else if (document.all)  {
			this.obj = document.all[name];
		} else if (document.layers)  {
			this.obj = document.layers[name];
		}
		if(this.obj) {
			return true;
		} else {
			return false;
		}		
	}

}

// Object check added - 11/15/2006
function divDsp(el, dspState)
{
	if (!DHTML) return;
	
	if( typeof(el) == 'object' ) {
		x = el;
	} else {
		var x = new getObj(el);
	}
	x.style.display = (dspState)? (dspState=='inline'?'':dspState) : (x.style.display=='inline'||x.style.display=='') ? 'none' : '';
}

function popup(href,width,height,win_name) {
	    if (!win_name) win_name = 'none';
	    var window_features = "height="+height+",width="+width+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,dependent=1,top=100,left=100";
		win = window.open(href,win_name,window_features);
		if(win) {win.focus();}
		return false;
}

function selectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = true;
	}
	return;
}

function unSelectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = false;
	}
	return;
}

function selectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = true;
	}
	return;
}

function unSelectAllChecked(selectBox){
	for(var i=0;i<selectBox.length;i++){
		selectBox[i].checked = false;
	}
	return;
}

function numOnly(el) {
	var tmp 	= el.value.replace(/[^0-9.]/g,'');
	var argv 	= numOnly.arguments;
	if (argv.length==2) {
		if(tmp.length >= argv[1]) {
			el.form[(getIndex(el)+1) % el.form.length].focus();
		}
	}
	return el.value=tmp;
}

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;
}


function checkAll(checkBox){
	for(var i=0;i<checkBox.length;i++){
		checkBox[i].checked = true;
	}
	return;
}

function unCheckAll(checkBox){
	for(var i=0;i<checkBox.length;i++){
		checkBox[i].checked = false;
	}
	return;
}



checked_toggle_check = 0;

function checkToggle(checkBox){
	if(checked_toggle_check==0){
		checkAll(checkBox);
		checked_toggle_check = 1;
	} else {
		unCheckAll(checkBox);
		checked_toggle_check = 0;
	}
	return;
}


// AJAX Functionality
function holler(method,url,parameters,callback) {
	var method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	        var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		//alert(url);
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
    xmlhttp.onreadystatechange = function () {
	  		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {
				if (xmlhttp.status == 200) {
					if (typeof callback == 'function') {
						callback(xmlhttp);
					} else { 
						eval(callback);
					}
				} else{
					alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
					return;
				}
		    }
		};
}

/******************************************************************************************
hollerBack:
executes an ajax call and places the result into the specified html container object

method: 		'get' or 'post'
url: 			url to request
parameters: 	query string to send
thisObj:		id of or reference to an html container object, where the result is placed
LoadingTxt:		loading... indicator, if not specified defaults to an animated loading image

returns:		no return value

Example:
new hollerBack("post", "/?var1=abcd", "&var2=" + var2), "div_id");
new hollerBack("post", 
	"/?action=appraiser&node=search_close_appraisers", 
	"&appraisal_id=" + appraisal_id + "&distance=" + _($('distance').value), 
	"appraiser_search_list");
********************************************************************************************/
function hollerBack(method,url,parameters,thisObj,LoadingTxt) {
	 var xmlhttp 	= null;
	 var method 	= method.toUpperCase();
     var self = this;
	 try{
	 
	    if (window.XMLHttpRequest) {
	        var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-length", parameters.length);
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }


 	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
	} else if (typeof thisObj != "string") {
		var x = thisObj;
	}
 
 	if(LoadingTxt){
		x.innerHTML = '<div>'+LoadingTxt+'</div>';
	} else {
		//if(x.clientHeight && x.clientHeight < 220) {
			x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="" width="16" height="16" border="0" /></div>';
		//} else {
		//	x.innerHTML = '<div><img src="/img/loading.gif" alt="" width="220" height="19" border="0" /></div>';
		//}
	}
	 
    xmlhttp.onreadystatechange = function () {
			
		

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {

			try {
				x.innerHTML = xmlhttp.responseText;
				if (self && (typeof self.onload == 'function')) {
					self.onload(xmlhttp);
				}
			} catch (e) {
				alert('An error occurred while trying to return your request. \nError '+e.description);
			}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
			if(LoadingTxt){
				x.innerHTML = '<div>'+LoadingTxt+'</div>';
			} else {
				x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="" width="16" height="16" border="0" /></div>';
			}
			return;
			//x.innerHTML = '<b>Loading...</b>';
		}
	};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}

function hollerBackNow(method, url, parameters, thisObj, LoadingTxt) {

	 var xmlhttp = null;
	 var method = method.toUpperCase();
	 try{
	    if (window.XMLHttpRequest) {
	       var xmlhttp = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        //var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			try {
				var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
	    }
		
		if(method=="POST"){
			xmlhttp.open(method, url, true);
			xmlhttp.setRequestHeader("Content-type", "text/xml");//application/x-www-form-urlencoded
			xmlhttp.setRequestHeader("Content-length", parameters.length);//parameters.length
			xmlhttp.setRequestHeader("Connection", "close");
			xmlhttp.send(parameters);
		} else{
			xmlhttp.open(method, url+'&'+parameters, true);
			//xmlhttp.setRequestHeader("Content-type", "text/xml");
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.send(null);
		}
		
     } catch(e){
	 	alert('Error occurred while trying to process your request');
	 	return;
	 }
	
	
    xmlhttp.onreadystatechange = function () {
			
		if (objExist(thisObj)) { 
			var x = new getObj(thisObj);
		}

		if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete') {

			try {
				//x.innerHTML = xmlhttp.responseXML;
				var response = xmlhttp.responseXML;
				alert(response.Length);
			} catch (e) {
				alert('An error occurred while trying to return your request. \nError '+e.description);
			}
			
			if (xmlhttp.status != 200) {
				alert('An error occurred while trying to return your request. \nError '+xmlhttp.status+': '+xmlhttp.statusText);
				return;
			}
	    } else{
			
			/*if(LoadingTxt){
				x.innerHTML = '<div>'+LoadingTxt+'</div>';
			} else {
				x.innerHTML = '<div><img src="/img.admin/loading.gif" alt="" width="220" height="19" border="0" /></div>';
			}
			return;
			//x.innerHTML = '<b>Loading...</b>';*/
		}
	};
	//xmlhttp.setRequestHeader("Content-Length", "66");
}
//hollerAtMe('POST', formObj, '/ajax.php?action='+action+'&'+url, div, _onload);
function hollerAtMe(method,formObj,url,thisObj, _onload) 
{
	
	this.uniqueId = new Date().getTime();
	this.frameName = 'frame_'+this.uniqueId;
	
	try{
		// Create New hidden iframe
		var divElm = document.createElement('DIV');
		
		divElm._onload = _onload;
		
		divElm.style.display = 'none';
		document.body.appendChild(divElm);
		divElm.innerHTML = '<iframe name=\"'+this.frameName+'\" id=\"'+this.frameName+'\" src=\"about:blank\" onload=\"loadFrame(this,\''+thisObj+'\')\"></iframe>';
	} catch(e){
	 	alert('Error occurred while trying to create frame');
	 	return;
	 }
	
	try{
		
		//alert(formObj.action+"="+url);
		h_action = formObj.action;
		h_method = formObj.method;
		h_target = formObj.target;
		
		// Set target of ajax call to frame
		formObj.action 	= url;
		formObj.method 	= method;
		formObj.target = this.frameName;
		formObj.submit();
		
		formObj.action	= h_action;
		formObj.method 	= h_method;
		formObj.target 	= h_target;
		
	} catch(e){
	 	alert('Error occurred while trying to submit form: ' + e);
	 	return;
	 }

	// the source div to swap out
	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
		x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="" width="16" height="16" border="0" /></div>';
	}
}


function hollerBacki(method, url, thisObj) 
{
	this.uniqueId = new Date().getTime();
	this.frameName = 'frame_'+this.uniqueId;
	
	try{
		// Create New hidden iframe
		var divElm = document.createElement('DIV');
		divElm.style.display = 'none';
		document.body.appendChild(divElm);
		divElm.innerHTML = '<iframe name=\"'+this.frameName+'\" id=\"'+this.frameName+'\" src=\"about:blank\" onload=\"loadFrame(this,\''+thisObj+'\')\"></iframe>';
		var x = new getObj(this.frameName);
		x.src = url;
	} catch(e){
	 	alert('Error occurred while trying to create frame');
	 	return;
	 }
	
	try{
		
	} catch(e){
	 	alert('Error occurred while trying to submit form');
	 	return;
	 }

	// the source div to swap out
	if (objExist(thisObj)) { 
		var x = new getObj(thisObj);
		x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="" width="16" height="16" border="0" /></div>';
	}
	

}


function loadFrame(iframeObj, thisObj) {
	try{
		frameName = iframeObj.id;
		var x = new getObj(thisObj);
		x.innerHTML = '<div><img src="/img/icon.indicator.gif" alt="" width="16" height="16" border="0" /></div>';
		x.innerHTML = window.frames[frameName].document.body.innerHTML;
		//alert(window.frames[frameName]);
		
		if(typeof iframeObj.parentNode._onload=='function'){
			iframeObj.parentNode._onload();
		}
		
		
		return window.frames[frameName];
	} catch(e){
	 	alert('Error occurred while trying to load data from frame');
	 	return;
	}
}


function getFormValues(fobj,valFunc) {    
	var str         = "";
	var valueArr     = null;
	var val         = "";
	var cmd         = "";

	for(var i = 0;i < fobj.elements.length;i++) {        
		switch(fobj.elements[i].type) {            
			case "hidden":
			case "text":
			case "textarea":
			case "password":
				if(valFunc) {
					//use single quotes for argument so that the value of
					//fobj.elements[i].value is treated as a string not a literal
					cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
					val = eval(cmd)
				}
				str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;            
			case "select-one":
				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
			case "select-multiple":                
				for(var z=0;z<fobj.elements[i].options.length;z++){
					if(fobj.elements[i].options[z].selected==true)
						str += fobj.elements[i].name + "=" + fobj.elements[i].options[z].value + "&";
				}
			break;
			case "checkbox":
				if(fobj.elements[i].checked==true)
					str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			break;
		}
	}
	str = str.substr(0,(str.length - 1)); 
	return str;
} 

function maxlength(obj, len)
{
	if(obj.value.length>=len) { obj.value = obj.value.substr(0,len) }
}

function print_r(obj) {
	big_list = "";
	for (property in obj) {
    	big_list +=property+"="+obj[property]+"\n";
	  }
	alert(big_list);
	return;
}

function URLEncode(plaintext) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";


	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function URLDecode(encoded) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 

   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function toQueryString(params) {
	var str = '';
	for (var i in params) { 
		if(i=='toJSONString'){ continue; }
		str += '&' + i + '='+params[i]; 
	}
	return str;
}

/*

	Added because IE does not support Object.toSource()

*/


/*
    json.js
    2006-12-06

    This file adds these methods to JavaScript:

        array.toJSONString()
        boolean.toJSONString()
        date.toJSONString()
        number.toJSONString()
        object.toJSONString()
        string.toJSONString()
            These method produces a JSON text from a JavaScript value.
            It must not contain any cyclical references. Illegal values
            will be excluded.

            The default conversion for dates is to an ISO string. You can
            add a toJSONString method to any date object to get a different
            representation.

        string.parseJSON(hook)
            This method parses a JSON text to produce an object or
            array. It can throw a SyntaxError exception.

            The optional hook parameter is a function which can filter and
            transform the results. It receives each of the values, and its
            return value is used instead. If it returns what it received, then
            structure is not modified.

            Example:

            // Parse the text. If it contains any "NaN" strings, replace them
            // with the NaN value. All other values are left alone.

            myData = text.parseJSON(function (value) {
                if (typeof value === 'string') {
                    if (value === 'NaN') {
                        return NaN;
                    }
                }
                return value;
            });

    It is expected that these methods will formally become part of the
    JavaScript Programming Language in the Fourth Edition of the
    ECMAScript standard in 2007.
*/

Array.prototype.toJSONString = function () {
    var a = ['['], b, i, l = this.length, v;

    function p(s) {
        if (b) {
            a.push(',');
        }
        a.push(s);
        b = true;
    }

    for (i = 0; i < l; i += 1) {
        v = this[i];
        switch (typeof v) {
        case 'undefined':
        case 'function':
        case 'unknown':
            break;
        case 'object':
            if (v) {
                if (typeof v.toJSONString === 'function') {
                    p(v.toJSONString());
                }
            } else {
                p("null");
            }
            break;
        default:
            p(v.toJSONString());
        }
    }
    a.push(']');
    return a.join('');
};

Boolean.prototype.toJSONString = function () {
    return String(this);
};

Date.prototype.toJSONString = function () {

    function f(n) {
        return n < 10 ? '0' + n : n;
    }

    return '"' + this.getFullYear() + '-' +
            f(this.getMonth() + 1) + '-' +
            f(this.getDate()) + 'T' +
            f(this.getHours()) + ':' +
            f(this.getMinutes()) + ':' +
            f(this.getSeconds()) + '"';
};

Number.prototype.toJSONString = function () {
    return isFinite(this) ? String(this) : "null";
};

Object.prototype.toJSONString = function () {
    var a = ['{'], b, i, v;

    function p(s) {
        if (b) {
            a.push(',');
        }
        a.push(i.toJSONString(), ':', s);
        b = true;
    }

    for (i in this) {
        if (this.hasOwnProperty(i)) {
            v = this[i];
            switch (typeof v) {
            case 'undefined':
            case 'function':
            case 'unknown':
                break;
            case 'object':
                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        p(v.toJSONString());
                    }
                } else {
                    p("null");
                }
                break;
            default:
                p(v.toJSONString());
            }
        }
    }
    a.push('}');
    return a.join('');
};


(function (s) {
    var m = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"' : '\\"',
        '\\': '\\\\'
    };

    s.parseJSON = function (hook) {
        try {
            if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                    test(this)) {
                var j = eval('(' + this + ')');
                if (typeof hook === 'function') {
                    function walk(v) {
                        if (v && typeof v === 'object') {
                            for (var i in v) {
                                if (v.hasOwnProperty(i)) {
                                    v[i] = walk(v[i]);
                                }
                            }
                        }
                        return hook(v);
                    }
                    return walk(j);
                }
                return j;
            }
        } catch (e) {
        }
        throw new SyntaxError("parseJSON");
    };

    s.toJSONString = function () {
        if (/["\\\x00-\x1f]/.test(this)) {
            return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                var c = m[b];
                if (c) {
                    return c;
                }
                c = b.charCodeAt();
                return '\\u00' +
                    Math.floor(c / 16).toString(16) +
                    (c % 16).toString(16);
            }) + '"';
        }
        return '"' + this + '"';
    };
})(String.prototype);


/**
* Multi update from object
*/
function multiUpdate (obj) {
        for (var i in obj) {
                //properties starting with _ will not be considered
                if (!(i.match(/^_/)) && getObj(i)) {
                        getObj(i).innerHTML = obj[i];
                }       
        }       
}

function ShowMenu(myval){
		//starting at one, loop through until the number chosen by the user
		if(myval == "FHA"){
			 document.getElementById('fha_label').style.display = 'block';
			 document.getElementById('fha_box').style.display = 'block';
		} else {
			document.getElementById('fha_label').style.display = 'none';
			document.getElementById('fha_box').style.display = 'none';
		}
                
}

function ShowFee(myval){
		//starting at one, loop through until the number chosen by the user
		
	document.getElementById('fee_label').style.display = 'block';
	document.getElementById('fee_box').style.display = 'block';

	document.getElementById('fee_label_2').style.display = 'block';
	document.getElementById('fee_box_2').style.display = 'block';
	
	var myVar = myval.split("|")
	document.getElementById('fee_box').value = myVar[1];
	document.getElementById('fee_box_2').value = myVar[2];
	
	if(myVar[1] == undefined){
		document.getElementById('fee_box').value = "";
	}
	
	if(myVar[2] == undefined){
		document.getElementById('fee_box_2').value = "";
	}
		
                
}
function ShowFee2(myval){
		//starting at one, loop through until the number chosen by the user
		
	document.getElementById('fee_label').style.display = 'block';
var fb2 = typeof document.frmData.fee_box_2;
if(fb2=='object')
	{
	document.getElementById('fee_box_2').style.display = 'block';
	}

//	document.getElementById('fee_label_2').style.display = 'block';
//	document.getElementById('fee_box_2').style.display = 'block';
	
	var myVar = myval.split("|")
//document.getElementById('fee_box').value = myVar[1];
//	document.getElementById('fee_box_2').value = myVar[2];
	
	if(myVar[1] == undefined){
		if(fb2=='object') {
		document.getElementById('fee_box_2').value = "";
		}
	}
	
	if(myVar[2] == undefined){
//		document.getElementById('fee_box_2').value = "";
	}
		
                
}
function ajaxUpdater(id,url) {  
  new Ajax.Updater(id,url,{asynchronous:true});  
}  

var myxmlHttp
function showClientFee(fileName,id,jobType)
{
//alert(id);
if (fileName.length==0)
  { 
  document.getElementById("fee_box").innerHTML="";
  return;
  }
myxmlHttp=GetXmlHttpObject()
if (myxmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url;
var sel=document.getElementById("fee_select").value;
var arr=sel.split("|");
url=fileName+"?id="+id;
url=url+"&jobType="+arr[0];
url=url+"&sid="+Math.random();
//alert(url);
myxmlHttp.onreadystatechange=stateChanged;

myxmlHttp.open("GET",url,true);
myxmlHttp.send(null);
}
//============================================================================================================
//============================================================================================================
//============================================================================================================
function showClientFeeForRequestAdmin(fileName,client_id,jobType,frmData)
{
var client_id_exist = typeof document.frmData.client_id;

if (fileName.length==0)
  { 
  document.getElementById("fee_box_2").innerHTML="";
  return;
  }
if(client_id_exist=='object')
	{
		if ((document.getElementById("client_id").value)=='')
		  { 
			alert('Please select the client !');
			return;
		  }
	}
myxmlHttp=GetXmlHttpObject()
if (myxmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url;
if(client_id_exist=='object')
	{
	var id=document.getElementById("client_id").value;
	}
else
{
var id=client_id;
}
var sel=document.getElementById("fee_select").value;
var arr=sel.split("|");
//alert(arr[0]+" "+arr[1]+" "+arr[2]);
url=fileName+"?id="+id;
url=url+"&jobType="+arr[0];
//url=url+"&sel="+sel;
url=url+"&sid="+Math.random();
//alert(url);
myxmlHttp.onreadystatechange=stateChangedAdmin;

myxmlHttp.open("GET",url,true);
myxmlHttp.send(null);
}
//============================================================================================================
//====================================	   E		N	   D		==========================================
//============================================================================================================
function stateChanged() 
{ 
if (myxmlHttp.readyState==4)
{
ShowFee2(document.getElementById("fee_select").value);
if(myxmlHttp.responseText)
{
document.getElementById("fee_box").value=myxmlHttp.responseText;
}
//alert(myxmlHttp.responseText);
}
}

function GetXmlHttpObject()
{
var myxmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  myxmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    myxmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    myxmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return myxmlHttp;
}

function GetXmlHttpObjectApp()
{
var myxmlHttpApp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  myxmlHttpApp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
	myxmlHttpApp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
	myxmlHttpApp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return myxmlHttpApp;
}

function stateChangedApp() 
{ 
if (myxmlHttpApp.readyState==4)
{
ShowFee2(document.getElementById("fee_select").value);
if(myxmlHttpApp.responseText)
{
document.getElementById("fee_box_2").value=myxmlHttpApp.responseText;
}
//alert(myxmlHttpApp.responseText);
}
}

function stateChangedAdmin() 
{ 
if (myxmlHttp.readyState==4)
{
ShowFee2(document.getElementById("fee_select").value);
if(myxmlHttp.responseText)
{
document.getElementById("fee_box_2").value=myxmlHttp.responseText;
}
//alert(myxmlHttp.responseText);
}
}


//===================================== Appraiser fee
var myxmlHttpApp
function showAppraiserFee(fileName,id,jobType)
{
//alert(id);
if (fileName.length==0)
  {
var fb2 = typeof document.frmData.fee_box_2;
if(fb2=='object') {
  document.getElementById("fee_box_2").innerHTML="";
}
  return;
  }
myxmlHttpApp=GetXmlHttpObjectApp()
if (myxmlHttpApp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url;
var sel=document.getElementById("fee_select").value;
var arr=sel.split("|");
url=fileName+"?id="+id;
url=url+"&jobType="+arr[0];
url=url+"&sid="+Math.random();
//alert(url);
myxmlHttpApp.onreadystatechange=stateChangedApp;

myxmlHttpApp.open("GET",url,true);
myxmlHttpApp.send(null);
}
function hideCommentsAppraiser(tagId)
{
alert(tagId);
document.getElementById(tagId).style.display = 'block';
}

function changeLable()
{
	var selectedOption=document.getElementById("status").value;
	if(selectedOption=="Comment")
	{
	//alert("comment..");
	document.getElementById("showlabel").innerHTML="Comment :";
	}
	else
	{
	//alert("date..");
	document.getElementById("showlabel").innerHTML="Status Date: ";
	}
}
function checkBlankUploadDocument()
{
	if((document.getElementById("documentId").value)=='')
	{
	alert("Please select the document !");
	return false;
	}
	else
	{
	return true;
	}
}




//===========================================================
function checknull()
{
var val;
val=document.getElementById('user_name').value;
	if(val=="")
	{
	alert("Please select User Name !");
	return false;login_paypal_frmif(!checknull())
	return false;	
	}
	else
	{
	var result=(login_paypal_frm.mailf.value);
	if(result) {
	checkBalnkOther();
	return false;
	}
	else
	{
	return false;
	}
	}



}
//FUNCTION WITH NO NAME ,I PUT A NAME THERE
function checkDomain(nname) {
if(nname	==	"") {
	alert("Please fill in the domain name !");
	return false;
}	
var mai = nname;
var val = true;

var dot = mai.lastIndexOf("");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
	
if(dot>2 && dot< 57)
{
	
		for(var j=0; j< dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 94 && hh<123) || hh==45 )
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your Domain name should not have special characters");
			 return false;
		  }
		}
	
}
else
{
 alert("Your Domain name is too short/long");
 return false;
}	
return true;
}


function checkBalnkOther()
{

	val=document.getElementById('uname').value;
	if(val=="")
	{
	alert("Please enter First Name.");
	return false;
	}
	val=document.getElementById('u_name').value;
	if(val=="")
	{
	alert("Please enter User Name.");
	return false;
	}
	val=document.getElementById('app_pwd').value;
	if(val=="")
	{
	alert("Please enter Password.");
	return false;
	}
	val=document.getElementById('user_email').value;
	
	if(val=="")
	{
	alert("Please enter Email.");
	return false;
	}
	val=document.getElementById('user_email').value;
	val1=document.getElementById('user_email');
	if ((val==null)||(val=="")){
		alert("Please Enter your Email ID")
		val1.focus()
		return false;
	}
	val=document.getElementById('user_email').value;
	val1=document.getElementById('user_email');
	if (echeck(val)==false){
		val1.value=""
		val1.focus()
		return false;
	}

val=document.getElementById('user_company_name').value;
	if(val=="")
	{
	alert("Please enter Company Name.");
	return false;
	}


val=document.getElementById('contact_address_street1').value;
	if(val=="")
	{
	alert("Please enter Address Street 1.");
	return false;
	}
val = document.getElementById('postal_code').value;
	if(val=="")
	{
		alert("Please enter Zip Code.");
		return false;
	}
	val=document.getElementById('contact_city').value;
	if(val=="")
	{
	alert("Please enter City.");
	return false;
	}
	val=document.getElementById('contact_state').value;
	if(val=="")
	{
	alert("Please select State.");
	return false;
	}
	/*val=document.getElementById('country').value;
	if(val=="")
	{
	alert("Please enter Country !");
	return false;
	}*/
	val=document.getElementById('user_phone').value;
	if(val=="")
	{
	alert("Please enter Phone Number.");
	return false;
	}
	val=document.getElementById('user_fax').value;
	if(val=="")
	{
	alert("Please enter Fax Number.");
	return false;
	}

	val=document.getElementById('appraiser_license').value;
	if(val=="")
	{
	alert("Please enter License #.");
	return false;
	}

	val=document.getElementById('appraiser_years_licensed').value;
	if(val=="")
	{
	alert("Please enter Years licensed.");
	return false;
	}
	val=document.getElementById('appraiser_experience').value;
	if(val=="")
	{
	alert("Please enter License Expiration Date.");
	return false;
	}
	
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function chk_username_mahak()
{
	
var fileName='chk_username.php';
var userName=document.getElementById("u_name").value;
if(userName != "") {

myxmlHttpMahak=GetXmlHttpObject()
if (myxmlHttpMahak==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url;



url=fileName+"?user_name="+userName;
url=url+"&sid="+Math.random();

myxmlHttpMahak.onreadystatechange=stateChangedMahak;

myxmlHttpMahak.open("GET",url,true);
myxmlHttpMahak.send(null);
}
else {
	document.getElementById('divAlert').style.display	=	'';
	document.getElementById('td_alert').innerHTML		=	'Please fill in the username!';	
	}
	
}

function stateChangedMahak() { 
	if (myxmlHttpMahak.readyState==4) {
		if(myxmlHttpMahak.responseText) {
			document.getElementById('divAlert').style.display	=	"";
				
				if(myxmlHttpMahak.responseText	==	1) 
					document.getElementById('td_alert').innerHTML		=	"Sorry , this username is already in use !";	
				else
				 	document.getElementById('td_alert').innerHTML		=	"Congratulations, this username is available!";	
		}
			
	}
}

 

function chk_email() {
var fileName='chk_email.php';
var email=document.getElementById("user_email").value;
var emailObj = document.getElementById("user_email");
if(email != "") {

/*if(!valid_email(emailObj)) {
//alert("Invalid Email address !");
//emailObj.focus();
document.getElementById('td_alert_email').innerHTML		=	'Invalid address !';	
//return false;
}*/

	
myxmlHttpMahak_email=GetXmlHttpObject()
if (myxmlHttpMahak_email==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url;



url=fileName+"?email="+email;
url=url+"&sid="+Math.random();

myxmlHttpMahak_email.onreadystatechange=stateChangedMahak_email;

myxmlHttpMahak_email.open("GET",url,true);
myxmlHttpMahak_email.send(null);
}
else {
	document.getElementById('divAlertEmail').style.display	=	'';
	document.getElementById('td_alert_email').innerHTML		=	'Please fill in the email!';	
	}
	
}

function stateChangedMahak_email() { 
	if (myxmlHttpMahak_email.readyState==4) {
		if(myxmlHttpMahak_email.responseText) {
			document.getElementById('divAlertEmail').style.display	=	"";
				//alert(myxmlHttpMahak.responseText);
				if(myxmlHttpMahak_email.responseText	==	1) 
					document.getElementById('td_alert_email').innerHTML		=	"Sorry , this email is already in use !";	
				else
				 	document.getElementById('td_alert_email').innerHTML		=	"Congratulations, this email is available!";	
		}
			
	}
}
function valid_email(emailObj) {
  var emailstr = emailObj.value;
  if(emailObj.value.length >= 1)
	{
	 var emailPat = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})$/;
	 var matchArray = emailstr.match(emailPat);
	 if (matchArray == null)  {
		 	document.getElementById('divAlertEmail').style.display = '';
			document.getElementById('td_alert_email').innerHTML="Your e-mail address is Invalid.";
			emailObj.focus();
			return false;
	  }
	}
}


function showAssignOption(){
	
document.getElementById("showassignoption_id").style.display='';

}

function showAutoassign()
{
document.getElementById("assign_row").style.display='none';


}
