var preVal='';
var EqpText = '';
var start = 1;
var ind=start;
var XX=0;
var YY=0; 
var arr = new Array();
var BillData = new Array();
var JobData = new Array();
var adPath = '';
var currentFld = '';
var NewCategoryOptions='';
var currentDrop='';
var topRows = 1;
var rowcount =0;
var arr = new Array();
var start = 1;
var ind = start;

function addRow(){
  var tbl = document.getElementById('tblGrid');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  if (document.getElementById('tcat')) {
	   var conter = document.getElementById('tcat').value;
	   if (document.getElementById('tcat').value<2) {
		  var cellLeft = row.insertCell(0); 
	      document.getElementById('tcat').value = ++conter;
	   } else {
		     alert("Cannot Assign More then three categories");
			 return;
		   }
	  }else {
     var cellLeft = row.insertCell(0);	  
  }
  var textNode = cellLeft.innerHTML =  showCatDrop(iteration);
  document.getElementById('total').value = iteration;
 }
 
 function addRow_free(){
   var tbl = document.getElementById('tblGrid');
   var lastRow = tbl.rows.length;
   var iteration = lastRow;
   var row = tbl.insertRow(lastRow);
   
   if (document.getElementById('tcat')) {
 	   var conter = document.getElementById('tcat').value;
 	   if (document.getElementById('tcat').value<2) {
 		  var cellLeft = row.insertCell(0); 
 	      document.getElementById('tcat').value = ++conter;
 	   } else {
 		     alert("Cannot Assign More then three categories");
 			 return;
 		   }
 	  }else {
      var cellLeft = row.insertCell(0);	  
   }
   var textNode = cellLeft.innerHTML =  showCatDrop(iteration);
   document.getElementById('total').value = iteration;
  }


function addDiv_cp(div_id,total,cat_list){
	var p_div = document.getElementById(div_id);
	var newdiv = document.createElement('div');
	var o = document.getElementById(div_id).getElementsByTagName("div");
	var iteration = o.length;
	var divIdName = iteration;
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','SubDiv');
	newdiv.style.padding= "5px";
	if((iteration%2)==0)
		newdiv.style.background= "#FFFFFF";
	else
		newdiv.style.background= "#F9F9F9";
	newdiv.innerHTML = showCatDrop_cp(iteration,div_id,cat_list);
	p_div.appendChild(newdiv);
	document.getElementById(total).value = iteration;
}

 function addEmptyRow(){
  var tbl = document.getElementById('tblGrid');
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  if (document.getElementById('tcat')) {
	   var conter = document.getElementById('tcat').value;
	   if (document.getElementById('tcat').value<2) {
		  var cellLeft = row.insertCell(0); 
	      document.getElementById('tcat').value = ++conter;
	   } else {
		     alert("Cannot Assign More then three categories");
			 return;
		   }
	  }else {
     var cellLeft = row.insertCell(0);	  
  }
 }

function removeRow()
{
  var tbl = document.getElementById('tblGrid');
  var lastRow = tbl.rows.length-1;
  if (lastRow>0) {
  tbl.deleteRow(lastRow);
 } 
 return false;
}

function removeDiv_cp(div_id,total)
{
	var count = 0;
	var o = document.getElementById(div_id).getElementsByTagName("div");

	if(o.length >1 )
	{
		var remove_div = (o.length -1)
		document.getElementById(div_id).removeChild(o[remove_div]); 
 		document.getElementById(total).value = (document.getElementById(total).value)-1;
		return true;
	}
	return false
}


function get_val (){
   if (http.readyState==4) {
     var filecont = http.responseText;
	 getVal = filecont.split(/##/);
	 var tbl = document.getElementById('tblGrid');
	 document.getElementById('LOADINGDIV').innerHTML = '';  
	 if (getVal[0]!="") {
	 for(con=parseInt(getVal[2]); con<tbl.tBodies[0].rows[getVal[1]].cells.length; con++) {
		tbl.tBodies[0].rows[getVal[1]].cells[con].innerHTML = "";
	 }
	 if (!tbl.tBodies[0].rows[getVal[1]].cells[getVal[2]]) {
	    tbl.tBodies[0].rows[getVal[1]].insertCell(getVal[2]);
	 } 
	 tbl.tBodies[0].rows[getVal[1]].cells[getVal[2]].innerHTML = getVal[0];
	}
  } else {
	    document.getElementById('LOADINGDIV').innerHTML = '<img src="' + adPath + 'images/loading.gif">'; 
	  }
}

function get_val_free (){
   if (http.readyState==4) 
	 {
		 var filecont = http.responseText;
		 getVal = filecont.split(/##/);
		 var tbl = document.getElementById('tblGrid');
		 var this_cell_num = getVal[2];
		 var next_cell_num = parseInt(getVal[2]) + 1;
		 var this_row = Math.ceil( getVal[2] / 2);
		 var next_row = Math.ceil( (parseInt(getVal[2])+ 1) / 2);		 
		 
		 document.getElementById('LOADINGDIV').innerHTML = '';  
		 //alert ('total rows = ' + tbl.rows.length + '\n' + 'this_cell_num = ' + this_cell_num + '\n'  + 'next_cell_num = ' + next_cell_num + '\n' + 'this_row = ' + this_row + '\n'   + 'next_row = ' + next_row );
		 
		 
		 if (getVal[0]!="" &&  getVal[0]!=" ") 
		 {
		 	//add new row if required
			 if(next_row != this_row && next_row > tbl.rows.length)
			 {			 	
					 addEmptyRow(); 
			 }
		
			//remove extra rows ahead of this column
			 if(next_row < tbl.rows.length)
			 {
				 var i = Math.ceil((getVal[2] + 1) / 2);
				 while  (next_row < tbl.rows.length) {
				 	removeRow();
				 } 
			 }
			 
			 var col = getVal[2] % 2;
			 var rr = Math.floor( getVal[2] / 2 );
			 for(con=parseInt(col); con<tbl.tBodies[0].rows[rr].cells.length; con++) 
			 {
				tbl.tBodies[0].rows[rr].cells[con].innerHTML = "";
			 }
			 if (!tbl.tBodies[0].rows[rr].cells[col]) 
			 {
					tbl.tBodies[0].rows[rr].insertCell(col);
			 } 
			 tbl.tBodies[0].rows[rr].cells[col].innerHTML = getVal[0];
		}
		else if(this_row < tbl.rows.length )
		{
			 while  (this_row < tbl.rows.length) {
				removeRow();
			 } 
		 }
		else if(typeof this_cell_num == "undefined")
		{
			//delete all rows
		 	while  (tbl.rows.length > 1) {
				removeRow();
		 	} 		 	
		 	tbl.tBodies[0].rows[0].cells[1].innerHTML = "";
		 }
				

  } 
	else 
	{
	    document.getElementById('LOADINGDIV').innerHTML = '<img src="' + adPath + 'images/loading.gif">'; 
	}
}

function submitCategory(obj) {
  con_to(obj);
}
function con_to(param) {
	 currentFld = param.id;
	 http.open("GET",adPath + "sitelisting/catlisting.php?param=" + param.id + "&id=" + param.value + "&adPath=" + escape(adPath),true);
   http.onreadystatechange = get_val ;
   http.send(null);
}

function submitCategory_cp(obj,div_id,path) 
{
	if(typeof(path) != 'undefined')
		adPath = path;

	con_to_cp(obj,div_id);
}

function con_to_cp(param,div_id) 
{
	 currentFld = param.id;
	 http.open("GET",adPath + "sitelisting/catlisting_cp.php?param=" + param.id + "&id=" + param.value + "&div_id=" + div_id + "&adPath=" + escape(adPath),true);
	 http.onreadystatechange = function (){
																				if (http.readyState==4) 
																				{
																					 var filecont = http.responseText;
																					 var getVal = filecont.split('##');
																					 var tbl = document.getElementById(div_id);
																					 document.getElementById('LOADINGDIV').innerHTML = '';  
																					 var o = document.getElementById(div_id).getElementsByTagName("div");
																					 if (getVal[0]!="" &&  getVal[0]!=" ") 
																					 {
																						if(o.length >0 )
																						{
																							var total_span = o[getVal[1]].getElementsByTagName("span");
																							if(total_span.length > getVal[2])
																							{
																								tot = parseInt(total_span.length)-1;
																								for(var i=tot;i>=parseInt(getVal[2]);i--)
																								{
																									o[getVal[1]].removeChild(total_span[i]);
																								}
																							}
																							
																							var newSpan = document.createElement('span');
																							newSpan.setAttribute('id','spn_'+[getVal[2]]);
																							newSpan.innerHTML = getVal[0];
																							o[getVal[1]].appendChild(newSpan);
																							return true;
																						}
																					}
																					else
																					{
																						var total_span = o[getVal[1]].getElementsByTagName("span");
																						if(total_span.length > getVal[2])
																						{
																							var tot = parseInt(total_span.length)-1;
																							for(var i=tot;i>=parseInt(getVal[2]);i--)
																							{
																								o[getVal[1]].removeChild(total_span[i]);
																							}
																						}
																					}
																				} 
																				else 
																				{
																						document.getElementById('LOADINGDIV').innerHTML = '<img src="' + adPath + 'images/loading.gif">'; 
																				}
		 																	}
   http.send(null);
}


function submitCategory_free(obj) {
  con_to_free(obj);
}
function con_to_free(param) {
	 currentFld = param.id;
	 http.open("GET",adPath + "sitelisting/catlisting_free.php?param=" + param.id + "&id=" + param.value + "&adPath=" + escape(adPath),true);
   http.onreadystatechange = get_val_free ;
   http.send(null);
}




function article_get_val (){
   if (http.readyState==4) {
     var filecont = http.responseText;
	 getVal = filecont.split(/##/);
	 var tbl = document.getElementById('articletblGrid');
	 document.getElementById('ARTICLELOADINGDIV').innerHTML = '';  
	 if (getVal[0]!="") {
	 for(con=parseInt(getVal[2]); con<tbl.tBodies[0].rows[getVal[1]].cells.length; con++) {
		tbl.tBodies[0].rows[getVal[1]].cells[con].innerHTML = "";
	 }
	 if (!tbl.tBodies[0].rows[getVal[1]].cells[getVal[2]]) {
	    tbl.tBodies[0].rows[getVal[1]].insertCell(getVal[2]);
	 } 
	 tbl.tBodies[0].rows[getVal[1]].cells[getVal[2]].innerHTML = getVal[0];
	}
  } else {
	    document.getElementById('ARTICLELOADINGDIV').innerHTML = '<img src="' + adPath + 'images/loading.gif">'; 
	  }
}
function submitArticleCategory(obj) {
  article_con_to(obj);
}
function article_con_to(param) {
 	currentFld = param.id;
   http.open("GET",adPath + "sitelisting/articlecatlisting.php?param=" + param.id + "&id=" + param.value + "&adPath=" + escape(adPath),true);
   http.onreadystatechange = article_get_val ;
   http.send(null);
}

function start_article_edit() {
	document.getElementById('articlecategoryselect').innerHTML = showArticleCatDrop(0);
	document.getElementById('article_total').value = 1;	
}




function create_http_object(){
  var httpxml=false;
  /*@cc_on 
    @if (@_jscript_version>=5) 
   try {
     httpxml = new ActiveXObject("Msxml12.XMLHTTP");
   } catch(e) {
     try {
    httpxml = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e2) {
    httpxml = false;
  }
   }
   @end @*/ 
   if (!httpxml && typeof XMLHttpRequest != 'undefined') {
    httpxml = new XMLHttpRequest();
   }
return httpxml;
}
http = create_http_object();
function Validate_pass() {
		var frm = document.getElementById('frmNewUser');
		var oldpass = Trim(frm.oldpass.value);
		var newpass = Trim(frm.newpass.value);
		var repass = Trim(frm.repass.value);
		var error_str = '';
		
		if (oldpass.length < 1)
		{
			error_str+="Error : Old Password is required<br>";
		}
		if (newpass.length < 1)
		{
			error_str+="Error : New Password is required<br>";
		}
		if (repass.length < 1)
		{
			error_str+="Error : Re-enter New Password<br>";
		}
		if (newpass != repass)
		{
			error_str+="Error : New Password and Re-entered Password doesnot match<br>";
		}
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		} 
	return true;
}
 function show_login_form_errors() {
	
	var ErrorStr;
	trimForm();
	ErrorStr="";
	if (document.LoginFrm.LoginId.value=="") {
		 ErrorStr +="Error : Please Enter Username<br>";
		  
		}
	if (document.LoginFrm.Pwd.value=="") {
		 ErrorStr +="Error : Please Enter Password<br>";
		  
		}	
	if (ErrorStr!="") {
		ErrorStr += "<br>";	
		document.getElementById("ErrorLable").innerHTML= ErrorStr;
		} else LoginFrm.submit();
	
}
function trimForm()
{
	for(field in document.getElementsByTagName("input"))
	{
		try{
		document.getElementById(field).value=MyTrim(document.getElementById(field).value);
		}catch(e)
		{}
	}
	for(field in document.getElementsByTagName("textarea"))
	{
		try{
		document.getElementById(field).value=MyTrim(document.getElementById(field).value);
		}catch(e)
		{}
	}
}

function Validate_upass() {
		var frm = document.getElementById('frmNewUser');
		
		var newpass = Trim(frm.newpass.value);
		var repass = Trim(frm.repass.value);
		var error_str = '';
		
		if (newpass.length < 1)
		{
			error_str+="Error : New Password is required<br>";
		}
		if (repass.length < 1)
		{
			error_str+="Error : Re-enter New Password<br>";
		}
		if (newpass != repass)
		{
			error_str+="Error : New Password and Re-entered Password doesnot match<br>";
		}
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		} 
	return true;
}
function popup(src,wid,hei){
	    
	    winleft = screen.width/2 - wid/2;
		wintop = screen.height/2 - hei/2;
	    window.open(src,"","toolbar=no,scrollbars=no,resizable, status=yes,width="+wid+",height="+hei+",top="+wintop+",left="+winleft);
	}
function popupScroll(src,wid,hei){
	    winleft = screen.width/2 - wid/2;
		wintop = screen.height/2 - hei/2;
	    window.open(src,"","toolbar=no,scrollbars=yes,resizable, status=yes,width="+wid+",height="+hei+",top="+wintop+",left="+winleft);
	}
	
function Validate()
	{
		var frm = document.getElementById('frmNewUser');
		var usrName = Trim(frm.uname.value);
		var passwrd = Trim(frm.pwd.value);
		var repasswrd = Trim(frm.repwd.value);
		var emailad = Trim(frm.email.value);
		var adcat = Trim(frm.ad_cat.value);
		var error_str = '';
		
		
		if (usrName.length < 1)
		{
			error_str+="Error : User Name is required<br>";
		}
		if (passwrd.length < 1)
		{
			error_str+="Error : Password is required<br>";
		}
		if (passwrd != repasswrd)
		{
			error_str+="Error : Password and Confirm Password doesnot match<br>";
		}
		if (adcat == -1)
		{
			error_str+="Error : Please Choose a Permission Level for this User<br>";
		}
		if (emailad.length<1)
		{
			error_str+="Error : Email Address is required<br>";
		} else if (!isEmail(emailad)) {
			  error_str+="Error : Invalid Email Address<br>";
			} 
		if (error_str) {
			 document.getElementById("ERR_DISP").style.display = "block";
			 document.getElementById("Error_Label").innerHTML = error_str;
			 return false;
		}
		
		return true;
	}
function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
return false;
}

function Message()
	{
		alert("Not implemented yet");
	}
function checkEmail(emailCntrl)
{
	if(emailCntrl.value=="")
	{
		return "Please enter e-mail address.";
	}
	else
	{
		mail=emailCntrl.value
		at_pos=mail.indexOf("@")
		dot_pos=mail.indexOf(".")
		if(at_pos<1 || dot_pos<1)
		{
			return "Please enter valid email address.";
		}
		else
		{
			mail=emailCntrl.value
			condition="yes"
			var at_count=0
			var dot_count=0
			var temp=0
			for(var i=0;i<mail.length;i++)
			{
				if((mail.charCodeAt(i)>0 && mail.charCodeAt(i)<48)||(mail.charCodeAt(i)>57 && mail.charCodeAt(i)<65)||(mail.charCodeAt(i)>91 && mail.charCodeAt(i)<97)||mail.charCodeAt(i)>122)
				{
					if(mail.charAt(i)=="@"||mail.charAt(i)==".")
					{
							if(mail.charAt(i)=="@"){at_count++}else{dot_count++} // counts the no. of times @ and . appears in email
							if(dot_count>=1)
							{
								dot_pos=i
								if((dot_pos>at_pos) && temp==0)
								{
									pos=dot_pos-at_pos
									temp++
								}								
							}
					}
					else
					{
						condition="no"
						i=mail.length
					}
				}
			}
			if(condition=="no")
			{
				alert("Your email contains a blank space or special character.")
				emailCntrl.focus()
				ok=false
			}
			else
			{
				if(at_count>1)
				{
					alert("E-mail contains extra @ ")
					emailCntrl.focus()
					ok=false
				}
				else
				{
					if(pos<2)
					{
						alert("Missing domain name between '@' and '.'")
						emailCntrl.focus()
						ok=false
						i=mail.length
					}
					else
					{	
						count=dot_pos+1
						domain=""
						for(count;count<mail.length;count++)
						{
							domain=domain+mail.charAt(count)		
						}
						dom=new Array("au","com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum")
						error="yes"
						for(var k=0;k<dom.length;k++)
						{
							if(domain==dom[k])
							{
								k=dom.length
								error="no"
							}
						}
						if((error=="yes" && (domain.length>2)) || (domain.length<2))
						{
							alert("Domain name must end with well known domains \n or 2-lettered country name. eg com,edu,in etc.")
							emailCntrl.focus()
							ok=false
						}								
					}
				}
			}
		}
	}
	return ok
}

function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

function isName(value)
{
	for(i=0;i<value.length;i++)
	{			
		ch = value.charAt(i);
		if ( ((ch <= "z") && (ch >= "a")) || ((ch <= "Z") && (ch >= "A")) || (ch == ' ') || (ch == " ") ) {}
		else 
 			return false;
	}
 	return true;
}
function isDigit(value)
{
	var digit = Boolean(true);
    	for(var i=0;i<value.length;i++)
    	{
      	  var ch = value.charAt(i);
      	  if(!(ch == "0" || ch=="1" || ch=="2" || ch=="3" || ch=="4" || ch=="5" || ch=="6" || ch=="7" || ch=="8" || ch=="9"))
   	  	return false;
      	}
	return true;
}
function isFloat(field)
{
	var point=0;
	var i=0;
	var beforePoint=0;
	var afterPoint=0;
	for(var a=0;a<field.length;a++)
	{
    	if(!(field.charAt(a)=="." || field.charAt(a)=="0" || field.charAt(a)=="1" || field.charAt(a)=="2" || field.charAt(a)=="3" || field.charAt(a)=="4" || field.charAt(a)=="5" || field.charAt(a)=="6" || field.charAt(a)=="7" || field.charAt(a)=="8" || field.charAt(a)=="9"))
			return false;
		if(field.charAt(a)==".")
			point++;
	}
	if(point > 1)
		return false;
	if(point == 1)
	{
		while(field.charAt(i)!=".")
		{
			i++;
			beforePoint++;
		}
		afterPoint=field.length-(beforePoint+1);
		if(beforePoint > 3)
			return false;
		if(afterPoint > 4)
			return false;
		if(afterPoint==0 && beforePoint==0)
			return false;
	}
	return true;
}	
function show_hide (obj){
   if (document.getElementById(obj).style.display == "none"){
     document.getElementById(obj).style.display = "block";
   } else {
     document.getElementById(obj).style.display = "none" ;
   }
}

function swap_div(src_div,des_div)
{
	document.getElementById(src_div).style.display = "none";
	document.getElementById(des_div).style.display = "block";
}

function swap_classes(src_div,des_div)
{
	document.getElementById(src_div).className = "selected";
	document.getElementById(des_div).className = "";
}

function get_prepositions()
{
	var prep = new Array("all", "and", "any", "both", "but", "each", "few", "for", "from", "he", "her", "hers", "him", "his", "into", "shall", "were", "had" ,
					  "it", "its", "less", "like", "many", "me", "mine", "my", "none", "off", "one", "onto", "our", "ours","For","at", "is", "has", "have", "not", 
					  "out", "per", "by", "she", "some", "till", "that", "their", "them", "these", "they", "this", "unto", "up", "in","Am", "do", "did", "will" ,
					  "us", "via", "we", "what", "which", "with", "who", "whom", "whose", "you", "your", "yours", "is", "of" ,"a" , "&" ,"are","to");
	return prep;	
}


function changecase(str,word_case)
{
	var prep = get_prepositions();

	if(word_case == "T")
	{
		str_value = document.getElementById(str).value;
		
		newValue = '';
		sentence = str_value.split('. ');
		for(var j = 0; j < sentence.length; j++) 
		{	
			value = sentence[j].split(' ');
			for(var i = 0; i < value.length; i++) 
			{
				if(prep.indexOf(value[i]) >= 0 && i!=0 )
				{
					newValue += value[i].substring(0,1).toLowerCase() +
					value[i].substring(1,value[i].length).toLowerCase() + ' ';
				}
				else
				{
					newValue += value[i].substring(0,1).toUpperCase() +
					value[i].substring(1,value[i].length).toLowerCase() + ' ';
				}
			}	
			if(j < (sentence.length-1))
				newValue = Trim(newValue)+". "
		}
		document.getElementById(str).value = Trim(newValue,' ');
	}
	else
	{
		 val = document.getElementById(str).value;
		 result = new Array();
		 result2 = '';
		 count = 0;
		 endSentence = new Array();
		 for (var i = 1; i < val.length; i++)
		 {
		 	if(val.charAt(i) == '.' || val.charAt(i) == '!' || val.charAt(i) == '?')
		 	{
		   		endSentence[count] = val.charAt(i);
		   		count++
		 	}
		 }
		
		var val2 = val.split(/[.|?|!]/);
		
		if(val2[val2.length-1] == '') 
			val2.length = val2.length-1;
		
		for (var j = 0; j < val2.length; j++)
		{
		 	val3 = val2[j];
			val4 = val2[j-1];
			last_word = "";
			if(typeof(val4) != "undefined")
			{
				temp4 = val4.split(" ");
				last_word = temp4[temp4.length-1];
			}
			if(val3.substring(0,1)!=' ')val2[j]=' '+val2[j];
			
			var temp=val2[j].split(' ');
			var incr=0;
		
			if(temp[0]=='')
			{
		 		incr=1;
			}
			
			temp2=temp[incr].substring(0,1);
			temp3=temp[incr].substring(1,temp[incr].length);
			if(last_word != "no" && last_word != "NO" && last_word != "sq" && last_word != "SQ" && last_word != "ft" && last_word != "FT")
			{
				temp2=temp2.toUpperCase();
			}
			else
			{
				temp2=temp2.toLowerCase();
			}
			temp3=temp3.toLowerCase();
			temp[incr]=temp2+temp3;
		
			for (var i=incr+1;i<temp.length;i++)
			{
		 		temp2=temp[i].substring(0,1);
			 	temp2=temp2.toLowerCase();
				temp3=temp[i].substring(1,temp[i].length);
				temp3=temp3.toLowerCase();
				temp[i]=temp2+temp3;
			}
		
			if(endSentence[j]==undefined)endSentence[j]='';
		 	result2+=temp.join(' ')+endSentence[j];
		}
		
		if(result2.substring(0,1)==' ')result2=result2.substring(1,result2.length);
		 document.getElementById(str).value=result2;

	}	
}
function now(obj)
{
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var sec = currentTime.getSeconds();

	if (hours < 10)
	{
		hours = "0" + hours
	}
	
	if (minutes < 10)
	{
		minutes = "0" + minutes;
	}
	
	if (sec < 10)
	{
		sec = "0" + sec;
	}
	
	if (day < 10)
	{
		day = "0" + day;
	}
	if (month < 10)
	{
		month = "0" + month;
	}
	
	document.getElementById(obj).value = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + sec;
}

version = navigator.userAgent;
findIE6 = version.indexOf("MSIE 6");

function show_breakdown(div_id,element,offsetx,offsety)
{
		div = document.getElementById('backgroundFilter');
		winH = document.getElementById('footer').offsetTop;
		div.style.height = winH + "px";
		div.style.display = 'block'; 
		
		if(typeof(element) == "undefined")
		{
			positionp = typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
			positionp = positionp + 20;
			leftp =  window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
			leftp = leftp/7;
		
		}
		else
		{	
			var leftp = positionp = 0;
			obj = document.getElementById(element);
			if (obj.offsetParent) 
			{
				do 
				{
					leftp += obj.offsetLeft;
					positionp += obj.offsetTop;
				} while (obj = obj.offsetParent);
			}
			if(typeof(offsetx) != "undefined")
				leftp += offsetx;
			if(typeof(offsety) != "undefined")
				positionp += offsety;
		}
			
		//var leftp = 20;
		if(findIE6 != -1)
		{	
			document.getElementById("menu4iframe").style.display = "block";
			document.getElementById("menu4iframe").style.height = "100%";
		}
		
		document.getElementById(div_id).style.display = "block";
		document.getElementById(div_id).style.position= "absolute";
		document.getElementById(div_id).style.top = positionp + "px"; 
		document.getElementById(div_id).style.left = leftp + "px";
		return false;
}

function close_sub(div_id,show_bg_filter)
{
	document.getElementById(div_id).style.display = "none";
	if(show_bg_filter == 0 || typeof(show_bg_filter)=='undefined')
		document.getElementById('backgroundFilter').style.display = "none";
}

function ajaxpostpage(url,containerid,formid,sub_div,action)
{
	var page_request = false;
	var f_value = "";
	try
    {
    // Firefox, Opera 8.0+, Safari
   		 page_request = new XMLHttpRequest();
    }
  	catch (e)
    {
    // Internet Explorer
    	try
      	{
      		page_request = new ActiveXObject("Msxml2.XMLHTTP");
      	}
    	catch (e)
      	{
      		try
        	{
        		page_request = new ActiveXObject("Microsoft.XMLHTTP");
        	}
      		catch (e)
        	{
        		alert("Your browser does not support AJAX!");
        		return false;
        	}
      	}
    }
	if(typeof(formid) != 'undefined')
	{
		var form_var = document.getElementById(formid).elements;
		for(var fl = 0;fl < form_var.length; fl++)
		{
			var radio_sel = true;
			if(form_var[fl].type != "button" )
			{
				c_value = form_var[fl].value;
				c_array = c_value.split("&");
				c_len = c_array.length;
				new_value = "";
				if(c_len > 1)
				{
					for(var i = 0; i < (c_len-1); i++)
						new_value += c_array[i] + "**";
					
					new_value += c_array[i];
				}
				else
				{
					if(form_var[fl].type == "checkbox") 
					{
						if(form_var[fl].checked)
							new_value = form_var[fl].value;
					}
					else if(form_var[fl].type == "radio") 
					{
						radio_sel = false;
						if(form_var[fl].checked)
						{
							new_value = form_var[fl].value;
							radio_sel = true;
						}
					}
					else
						new_value = form_var[fl].value;
				}
				if(radio_sel)
					f_value += form_var[fl].name + "=" + encodeURIComponent(new_value)+"&";
			}
		}
	}
	//document.getElementById(containerid).style.display = "block";
	//document.getElementById(containerid).innerHTML = loadstatustext;
	
	if(typeof(action) != 'undefined')
		f_value += "action="+action+"&";
	
	page_request.onreadystatechange=function()
	{
		loadpage(page_request, containerid)
	}
	if (typeof bustcachevar == 'undefined')
  {
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();	
	}	
	/*if (bustcachevar == undefined) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()*/
	page_request.open('POST', url, true);
	page_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	page_request.setRequestHeader("Content-length",f_value.length);
	page_request.send(f_value);
	
	if(typeof(sub_div) != 'undefined')
		close_sub(sub_div);
}

function setAndExecute(divId, innerData)  
{  
	 var div = document.getElementById(divId);  
   div.innerHTML = innerData;  
   var x = div.getElementsByTagName("script");   
   for(var i=0;i<x.length;i++)  
   {  
       eval(x[i].text);  
   }  
} 

function loadpage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{ 
		res = Trim(page_request.responseText);
		if(res == "get_listed_hide_row")
		{
			document.getElementById('tr_add4').style.display = 'none';
			document.getElementById(containerid).innerHTML = 'No Further Locations.';
		}
		else
		{
			//document.getElementById(containerid).innerHTML=page_request.responseText;
			setAndExecute(containerid, page_request.responseText);
		}
	}
}

function get_locs(lev,val,list_id,weburl)
{
	
	
	if(typeof(weburl)=='undefined')
	{
		var url = '../getlisted/get_country.php?level='+(lev-1)+'&country='+val;
		var loading_html = '<img src="../admin/images/loading.gif">';
	}
	else
	{
		var url = weburl+'getlisted/get_country.php?level='+(lev-1)+'&country='+val;
		var loading_html = '<img src="'+weburl+'admin/images/loading.gif">';
	}
	
	if(typeof(list_id)=='undefined')
	{
		id = '';
	}
	else if(list_id != 'undefined')
	{
		id = "_"+list_id;
		url = url+"&list_id="+list_id;
	}
	else
	{
		id = '';
	}
	
	if(val != '')
	{
		document.getElementById('div_add'+lev+id).innerHTML = loading_html;
		ajaxpostpage(url, 'div_add'+lev+id);	
	}
	
	switch(lev)
	{
		case 2:
			document.getElementById('div_add3'+id).innerHTML = '<select name="address3" id="address3" style="width:225px;" disabled="disabled" onfocus="tbl_bg(\'contact\')" ><option value="">Please Select State or Region First</option></select>';
			document.getElementById('tr_add4').style.display = 'none';
			document.getElementById('div_add4'+id).innerHTML = '';			
			if(val == '')
			{
				document.getElementById('div_add2'+id).innerHTML = '<select name="address2" id="address2" style="width:225px;" disabled="disabled" onfocus="tbl_bg(\'contact\')" ><option value="">Please Select Country First</option></select>';
			}
			break;
		
		case 3:
			if(val == '')
			{
				document.getElementById('div_add3'+id).innerHTML = '<select name="address3" id="address3" style="width:225px;" disabled="disabled" onfocus="tbl_bg(\'contact\')" ><option value="">Please Select State or Region First</option></select>';
			}
			document.getElementById('tr_add4').style.display = 'none';
			document.getElementById('div_add4'+id).innerHTML = '';						
			break;
	
		case 4:
			if(val == '')
			{
				document.getElementById('tr_add4').style.display = 'none';
				document.getElementById('div_add4'+id).innerHTML = '';							
			}
			else
			{
				document.getElementById('tr_add4').style.display = '';
			}
			break;
	}
}


function load_cats(list_id,site_id)
{
	var path = '../getlisted/';
	if(typeof(list_id) == 'undefined')  // From Get Listed Page
	{
		tbl_bg('profile');
		var search_fld = 'alt_cat';
		var url = path+'load_search_cats.php';	
	}
	else 
	{
		var search_fld = 'alt_cat_'+list_id;
		document.getElementById('bg_filter').value == 1;
		var url = path+'load_search_cats.php?id='+list_id+'&site_id='+site_id;
	}

	if(document.getElementById(search_fld).value == '')
	{
		alert("Please Enter Search Category.");
		return false;
	}

	show_breakdown('cat_data');
	document.getElementById('cat_name').value = document.getElementById(search_fld).value;
	ajaxpostpage(url,'cat_data','search_cat');
}

function load_areas(list_id)
{
	var path = '../getlisted/';
	if(typeof(list_id) == 'undefined')  // From Get Listed Page
	{
		tbl_bg('contact');
		var search_fld = 'srch_area';
		var url = path+'load_search_areas.php';	
	}
	else 
	{
		var search_fld = 'srch_area_'+list_id;
		document.getElementById('bg_filter').value == 1;
		var url = path+'load_search_areas.php?id='+list_id;
	}

	if(document.getElementById(search_fld).value == '')
	{
		alert("Please Enter Search Location.");
		return false;
	}

	show_breakdown('cat_data');
	document.getElementById('search_name').value = document.getElementById(search_fld).value;
	ajaxpostpage(url,'cat_data','search_area');
}

function load_parents(chk_selected_cat,show_bg_filter,id,site_id)
{
	input_array = document.getElementsByTagName("input");
	input_length = input_array.length;
	cat = '';
	for(i = 0; i < input_length; i++)
	{
		  if(input_array[i].getAttribute("type") == "radio" && input_array[i].checked && input_array[i].value != 'new' && input_array[i].value != 'member' )
			{
				if(id>0)
				{
					if(input_array[i].name == ('selected_cat_'+id))
						cat = input_array[i].value;
				}
				else
					cat = input_array[i].value;
			}
	}

	if(cat == '')
	{
		alert('Please click the radio button to select category. or press Cancel ');
		return false;
	}
	
	var url = 'load_parent_cats.php?selected='+cat;
	var url = '../getlisted/load_parent_cats.php';
	if(id>0)
	{
		var div_id = "Div_Cat_"+id;
		url = url+'?selected='+cat+'&id='+id+'&site_id='+site_id;
	}
	else
	{
		var div_id = "Div_Cat";
		var url = url+'?selected='+cat;
	}
	ajaxpostpage(url,div_id);
	
	if(show_bg_filter == 0 || typeof(show_bg_filter)=='undefined')
		close_sub('cat_data',0);
	else
		close_sub('cat_data',1);
	
}

function load_locations(show_bg_filter,id)
{
	input_array = document.getElementsByTagName("input");
	input_length = input_array.length;
	area = '';
	for(i = 0; i < input_length; i++)
	{
		  if(input_array[i].getAttribute("type") == "radio" && input_array[i].checked)
			{
				if(id>0)
				{
					if(input_array[i].name == ('selected_area_'+id))
						area = input_array[i].value;
				}
				else
					area = input_array[i].value;
			}
	}

	if(area == '')
	{
		alert('Please click the radio button to select location. or press Cancel');
		return false;
	}

	var area_array = area.split(':');

	//selecting Country
	var i;
	url = '../getlisted/';
	if(id>0)
	{
		slt_name = 'address1_'+id;
		div_ext = '_'+id;
		qry_str = "&list_id="+id;
	}
	else
	{
		slt_name = 'country';
		div_ext = '';
		qry_str = '';
	}
	
	for(i=0;i<document.getElementById(slt_name).length;i++)
	{
		lst_value = document.getElementById(slt_name).options[i].value;
		if(area_array[0] == lst_value)
		{
		 	document.getElementById(slt_name).options[i].selected = true;
			if(id>0)
				get_locs(2,document.getElementById(slt_name).options[i].value,id);
			else
				get_locs(2,document.getElementById(slt_name).options[i].value);
			break;
		}
	}
	
	if(area_array[0] != '')
		ajaxpostpage(url+'get_country.php?level=1&country='+area_array[0]+'&sel='+area_array[1]+qry_str, 'div_add2'+div_ext);
	
	if(area_array[1] != '')
		ajaxpostpage(url+'get_country.php?level=2&country='+area_array[1]+'&sel='+area_array[2]+qry_str, 'div_add3'+div_ext);

	if(area_array[2] != '')
	{
		ajaxpostpage(url+'get_country.php?level=3&country='+area_array[2]+'&sel='+area_array[3]+qry_str, 'div_add4'+div_ext);
		if(document.getElementById('tr_add4'))
			document.getElementById('tr_add4').style.display='';
		
		if(!(id>0))
			document.getElementById('tr_add4'+div_ext).style.display='';
	}

	if(show_bg_filter == 0 || typeof(show_bg_filter)=='undefined')
		close_sub('cat_data',0);
	else
		close_sub('cat_data',1);
}


function checkEnter(type,e,list_id,site_id)
{ 
	//e is event object passed from function invocation
	if(e && e.which)
	{ 
		//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		//e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		if(typeof(list_id) == 'undefined')
		{	
			//submit the form
			if(type == 'cats')
				load_cats();
			else
				load_areas(); 
			
		}
		else
		{
			//submit the formload_cats();
			if(type == 'cats')
				load_cats(list_id,site_id); 
			else
				load_areas(list_id,site_id); 
			
		}
		return false;
	}
	else
	{
		return true;
	}
}

function uncheck(chk)
{
	document.getElementById(chk).checked = false;
}

function empty(txt,msg)
{
	if(typeof(msg) == "undefined")
	{
		if(txt.value == 'Search Area')
		{
			txt.value = '';
			txt.style.color = '#000'
		}
	}
	else
	{
		if(txt.value == msg)
		{
			txt.value = '';
			txt.style.color = '#000'
		}
	}
}

function fill(txt,msg)
{
	if(txt.value == '')
	{
		if(typeof(msg) == "undefined")
			txt.value = 'Search Area';
		else
			txt.value = msg;
		
		txt.style.color = '#CECECE'
	}
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function check_user(path)
{
	tbl_bg('signup');
	var search_fld = 'username';
	if(typeof(path) == 'undefined')
		path = '';
	
	var url = path+'check_user.php';	
	username = document.getElementById(search_fld).value;
	if( trim(username) == '')
	{
		alert("Please Enter Username.");
		return false;
	}

	show_breakdown('user_availablity','ref_chk_avl');
	document.getElementById('hdn_username').value = username;
	ajaxpostpage(url,'user_availablity','check_username');
}


function remove_specail_char(obj)
{
	var textEntered = obj.value;
	var filterStr = textEntered.replace(/[^a-zA-Z0-9_]+/g,'');
	obj.value = filterStr;
	return true;	
}

function checkAll(checkname, exby) 
{
	if (typeof(checkname.length) == "undefined")
	{
		checkname.checked = exby.checked? true:false
	}
	else
	{
		for (i = 0; i < checkname.length; i++)
			checkname[i].checked = exby.checked? true:false
	}
}


function CreateList(mode_value)
{
	var list, from, to;
	var buffer = "";
	var counter = 0;
	list = document.getElementsByTagName("input");
	for (i=0; i<list.length; i++)
	{
		if(list[i].type == "checkbox")
		{
			if(list[i].checked == true)
			{
				buffer += list[i].value + ",";
				counter++;
			}	
		}
	}
	
	
	if (document.getElementById("all").checked == true)
	{
		counter--;
	}
	if (counter >= 1)
	{
		var allowToPass = true;
		
		if (mode_value == "ban") 
		{
			if (confirm('Are you sure you want to ban selected keywords?'))
				allowToPass = true;
			else
				allowToPass = false;	
		}
		if (allowToPass)
		{
			if(mode_value == 'att')
			{
				to = 0;
				from = buffer.length - 1;
				buffer = buffer.substring(to, from);
				buffer = buffer.substring(2, buffer.length);
				if (document.getElementById("all").checked == true)
				{
					buffer = buffer.substring(0, (buffer.length - 3));
				}
			}
			else
			{
				to = 0;
				from = buffer.length - 1;
				buffer = buffer.substring(to, from);
				if (document.getElementById("all").checked == true)
				{
					buffer = buffer.substring(3, buffer.length);
				}
			}
			document.getElementById("kw").value = buffer;
			document.form121.submit();
		}
	}
	else
	{
		alert('No Listing Seleted');
	}	
} 

function update_loc_on_enter(type,e)
{ 
	if(e && e.which)
	{ 
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		if(document.getElementById('loc_update'))	
			document.getElementById('loc_update').value = 1;
		return false;
	}
	return false;
}


function submit_search_frm(obj_frm,webpath)
{
	selIndex = obj_frm.search_in.selectedIndex;
	selVal = obj_frm.search_in.options[selIndex].value
	if(	selVal == 'directory')	
	{
		if(obj_frm.pkey)
		{
			obj_frm.pkey.id = 'pkey';
			obj_frm.pkey.name = 'pkey';
			obj_frm.method = 'get';
		}
		return submit_frm(obj_frm);
	}
	else if(selVal == 'classified')
	{
		if(obj_frm.keywords)
		{
			obj_frm.keywords.id = 'pkey';
			obj_frm.keywords.name = 'pkey';
			obj_frm.method = 'post';
		}
		return set(obj_frm,webpath);
	}
	return false;
}

<!-- --------------- submit.tpl.php price functions---------------- -->

function showPriceText(event, newprice)
{
    var inps=document.getElementsByTagName("input");
    var pricetag;
	var pri_display = " ";
	
	if(newprice == 2)
		pri_display = "Salary";
	else if(newprice == 3)
		pri_display = "Fee";	
	else
		pri_display = "Price";
		
    if(event)
    {
    pricetag = event;
    }else{
        for(k=0;k<inps.length;k++)
        {
            if(inps[k].getAttribute("name")=="price")
                pricetag=inps[k];
        }
    }
    if (isNaN(pricetag.value))
    {
        showprice = "<font color=\"red\">"+pri_display+" must contain numbers only</font>";
    }
    else 
    {
        showprice = getPriceText(pricetag.value, pri_display);
    }
    if(document.getElementById("stext_facebox") != null && document.getElementById("stext_facebox").style.display == "none")
			document.getElementById("stext_facebox").style.display = "block";
	document.getElementById("stext").innerHTML = showprice;
}//End Of Function              

function getPriceText(price, pri_display)
{    
    retText="";
    price = price + "";
	price_array = price.split(",");
    price_length = price_array.length;
    price = "";
    for(i = 0;i < price_length; i++)
    {
        price += price_array[i];
    }
    price = number_format(price,0,"","");
	lprice = price.length;

    if(price == 0)
    {
        retText += ""+pri_display+" should be greater than '0'";
    }
    else
    {
        if(lprice>=12)
        {
                retText+=""+pri_display+" is too big. Please contact us";
        }
        else if(lprice==11)
        {
            retText+=price.substr(0,2);
                retText+=" Billion ";    
            if(price.substr(2,1)!="0")
                retText+=price.substr(2,3)+" Million ";
            if(price.substr(2,1)=="0"  && price.substr(3,1)!="0")
                retText+=price.substr(3,2)+" Million ";
            if(price.substr(2,1)=="0"  && price.substr(3,1)=="0" && price.substr(4,1)!="0")
                retText+=price.substr(4,1)+" Million ";
		}
        else if(lprice==10)
        {
            retText+=price.substr(0,1);
                retText+=" Billion ";    
            if(price.substr(1,1)!="0")
                retText+=price.substr(1,3)+" Million ";
            if(price.substr(1,1)=="0"  && price.substr(2,1)!="0")
                retText+=price.substr(2,2)+" Million ";
            if(price.substr(1,1)=="0"  && price.substr(2,1)=="0" && price.substr(3,1)!="0")
                retText+=price.substr(3,1)+" Million ";
        }
        else if(lprice==9)
        {
            retText+=price.substr(0,3)+" Million ";
            
            if(price.substr(3,1)!="0")
                retText+=price.substr(3,3)+" Thousand";
                
            if(price.substr(3,1)=="0"  && price.substr(4,1)!="0")    
                retText+=price.substr(4,2)+" Thousand";
                
            if(price.substr(3,1)=="0"  && price.substr(4,1)=="0" && price.substr(5,1)!="0")    
                retText+=price.substr(5,1)+" Thousand";
        }
        else if(lprice==8)
        {
            retText+=price.substr(0,2);
            if(price.substr(2,3)=="00")
                retText+=" Million ";
            
            if(price.substr(2,3)!="00")
                retText+=" Million ";
                      
            if(price.substr(2,2)!="00" && price.substr(2,1)=="0")
                retText+=price.substr(3,2)+" Thousand";
                
            if(price.substr(2,2)!="00" && price.substr(2,1)!="0")
                retText+=price.substr(2,3)+" Thousand";
        }
        else if(lprice==7)
        {
            retText+=price.substr(0,1);
                retText += " Million ";
            if(price.substr(1,1)!="0")
                retText += price.substr(1,3)+" Thousand";
            if(price.substr(1,1)=="0" && price.substr(2,1)!="0")
                retText += price.substr(2,2)+" Thousand";    
            if(price.substr(1,1)=="0" && price.substr(2,1)=="0" && price.substr(3,1)!="0" )
                retText += price.substr(3,1)+" Thousand";    
        }    
        else if(lprice==6)
        {
            retText+=price.substr(0,1)+" Hundred";
            if(price.substr(1,2)=="00")
                retText+=" Thousand";
            if(price.substr(1,2)!="00" && price.substr(1,1)!="0")
                retText+=" "+price.substr(1,2)+" Thousand";
            if(price.substr(1,2)!="00" && price.substr(1,1)=="0")
                retText+=" "+price.substr(2,1)+" Thousand";
        }
        else if(lprice==5)
        {
            if(price.substr(0,2)!="00" && price.substr(0,1)!="0")
                retText+=price.substr(0,2)+" Thousand";
            if(price.substr(0,1)=="0" && price.substr(1,1)!="0") 
                retText+=price.substr(1,1)+" Thousand";
        }
        else if(lprice==4)
        {
            if(price.substr(0,1)!="0" && price.substr(0,2)!="00")
                retText+=price.substr(0,1)+" Thousand";
        }
        else if(lprice<=3)
        {
            retText+=price;
        }
        if(lprice<12)
            retText+="";
    }
    return retText;
    
}//End of Function

function number_format(number, decimals, comma, formatSeparator) 
{
	number = Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals);
	e = number + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < decimals){
		g = f[1];
		for(i = f[1].length + 1; i <= decimals; i++) 
		{
			g += '0';
		}
		f[1] = g;
	}
	if(formatSeparator != '' && f[0].length > 3) 
	{
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) 
		{
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = formatSeparator + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	comma = (decimals <= 0) ? '': comma;
	return f[0] + comma + f[1];
}
function hide_price()
{
	document.getElementById("stext").style.display = 'none';
  if(document.getElementById("stext_facebox") != null && document.getElementById("stext_facebox").style.display == "block")
		document.getElementById("stext_facebox").style.display = "none";

	<!--$("#stext").css({"display":"none"});-->
}

function show_price()
{
	document.getElementById("stext").style.display = '';
  if(document.getElementById("stext_facebox") != null && document.getElementById("stext_facebox").style.display == "none")
		document.getElementById("stext_facebox").style.display = "block";

	
	<!--$("#stext").css({"display":""});-->
}

