
// JavaScript Document

function replaceAll( str, searchTerm, replaceWith, ignoreCase )   {
   var regex = "/"+searchTerm+"/g";
   if( ignoreCase ) regex += "i";
   return str.replace( eval(regex), replaceWith );
}

//AJAX COMMON FUNCTIONS 
var global_eleid = '';
//var webRoot = 'http://pct36:8080/rayv';

function defaultValChg(objnm,defaultval,bool){//bool:{onfocus:true;onblur:false}
	var obj = document.getElementById(objnm);
	if(!obj)return;
	if(bool==true){	if(obj.value==defaultval){obj.value='';obj.style.color='#000000';}	}
	else{if(obj.value==''){obj.value=defaultval;obj.style.color='#BBBBBB';}	}
}
function makexmlHttpObjectCOMM()
	{
		try {  
			// Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();    
		} catch (e){    // Internet Explorer    
			try {      
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			} catch (e) {      
				try {        
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
				} catch (e) {        
					alert("Your browser does not support AJAX!. You may not use all the functionalities provided on this page.");
					return false; 
				}
			}
		} 
		return xmlHttp;
	}

	function runAJAXCOMM(httpObj,method,requestFile,urlstring,responseFunction)
	{
		var URLString = '';
		if (URLString.length){URLString = URLString + "&" + urlstring; }
		else{URLString = urlstring; }
		if (httpObj)
		{
			if (method == "GET")
			{
				var totalurlstring = requestFile ;//+ "?" + URLString;
				httpObj.open(method, totalurlstring, true);
				httpObj.send(null);
			}
			else if (method == "POST")
			{
				httpObj.open(method, requestFile, true);
				try {
					httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					httpObj.setRequestHeader("Content-length", URLString.length);
					httpObj.setRequestHeader("Connection", "close");
				} catch (e) {}
				httpObj.send(URLString);
			}
		httpObj.onreadystatechange = eval(responseFunction);
		}//end if httpObj
	}//end run ajax
	
	function removeElementCOMM(id)   
	{
		if(typeof(id) == 'object'){var Node =id;}
		else{var Node = document.getElementById(id);}
	    Node.parentNode.removeChild(Node);
	}
	function getformVariablesCOMM(formObj,specificVar)
	{
		var urlstring = '';
		if(specificVar)
			var lenArr = specificVar.length; 
		else
			var lenArr = 0;
		var specFlag=1;
		if(lenArr<1)
		{
			specFlag = 0;
			lenArr = formObj.length;
		}
		for(i=0;i<lenArr;i++)
		{ 
				if(specFlag == 0)
				{
					obj = formObj.elements[i];
				}
				else
				{   
					obj = eval('formObj["'+specificVar[i]+'"]');
					if(!obj ||obj==null || obj=='undefined')obj = eval('formObj.'+specificVar[i]);
				}
				//alert(obj.nodeName);
				if(obj && typeof(obj)!='undefined' && (obj.nodeName || obj[0].nodeName) && obj.nodeName!="FIELDSET")
				{
						if(obj.nodeName)
						{
							nodetype = obj.nodeName.toLowerCase();
							name = obj.name;
							type = obj.type.toLowerCase();
							//alert(type);
						}
						else
						{
							nodetype = obj[0].nodeName.toLowerCase();
							name = obj[0].name;
							type = obj[0].type.toLowerCase();						
						}
						if( (nodetype == 'input' && type!='file' && type!='checkbox' && type!='radio') || nodetype == 'textarea' )
						{//hidden text password button ...
							urlstring +='&'+name+"="+encodeURIComponent( obj.value );
						}
						else if(nodetype == 'select')
						{
							if(type == 'select-multiple')
								{
									for(k=0;k<obj.length;k++)
									{
										if(obj.options[k].selected == true)
											urlstring += '&'+name+"="+encodeURIComponent(obj.options[k].value);
									}
								}
							else//type == 'select-one'
								{
									urlstring += '&'+name+"="+obj.options[obj.options.selectedIndex].value;						
								}
						}
						else if(nodetype == 'input' && (type == 'radio') )
						{
							if(obj.length && typeof(obj.length) != "undefined" )
							{
								for(var index=0;index<obj.length;index++)	
								{
									if(obj[index].checked == true)
									{
										urlstring +='&'+name+"="+encodeURIComponent(obj[index].value);
										break;
									}
								}
							}
							else
							{
								if(obj.checked == true)
									urlstring +='&'+name+"="+encodeURIComponent(obj.value);
							}
						}
						else if(nodetype == 'input' && type == 'checkbox')
						{
							if(obj.length && typeof(obj.length) != "undefined" )
							{
								for(var k=0;k<obj.length;k++)
								{
									if(obj[k].checked == true)
									{
										urlstring +='&'+name+"="+encodeURIComponent(obj[k].value);
									}
								}
							}
							else if(obj.checked == true)
							{
								urlstring +='&'+name+"="+encodeURIComponent(obj.value);
							}
						}
						else if(nodetype == 'input' && type == 'file'){	//upload?
						}
						else{ urlstring +='&'+name+"="+encodeURIComponent( obj.value );
						}
				}
				
		}
		strlen = urlstring.length;
		urlstring = urlstring.substring(1,strlen);//alert(urlstring);
		return urlstring;
	}	
	
	function aj_onstatechangeCOMM() 
	{
		if(xmlHttp.readyState==4) {
			var response = xmlHttp.responseText;//alert(response);
			if(response.indexOf("ERROR:")!=-1) {//alert(response.substr(response.indexOf(":")+1));
				alert(response.substr(response.indexOf(":")+1));
			} else {
				document.getElementById(global_eleid).innerHTML =response; 
			}
		}
		else{//nothing
			}
	}
	
	function gotoBizSelReview(biz,review,webroot)
	{
		document.frmhidact.hidact_1.value=review;
		document.frmhidact.action = webroot+'/biz/'+biz;
		document.frmhidact.submit();
		return false;
	}
	function check_chebox_checked(checkbox)
	{
		var count =0;
		if(checkbox){
		if(!checkbox.length || checkbox.length==null || typeof(checkbox.length) == 'undefined')
		{
			if(checkbox.checked==true)
				count = 1;
		}
		else
		{
			for(i=0;i<checkbox.length;i++)
			{
				if(checkbox[i].checked)
				{
					count++;
				}
				
			}
		}
		}
		if(count==0)
			return false;
		else
			return true;
	}
	function check_all_checkboxes(checkbox,option)
	{
		
		if(checkbox!=undefined)
		{
			if(checkbox.length == undefined)
			{
				checkbox.checked=option;
				
			}
			else
			{
				for(i=0;i<checkbox.length;i++)
					checkbox[i].checked = option;
			}
		}
	}
	/* functions of rating*/
	function turnOnStarsOnMouseOver(rating,imggrp) 
	{
		turnOnOffStars(rating,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(rating,imggrp);
	}
	function turnOffStarsOnMouseOut(currentRatingId,imggrp) 
	{
		turnOnOffStars(document.getElementById(currentRatingId).value,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(document.getElementById(currentRatingId).value,imggrp);
	}
	function turnOnOffStars(rating,imggrp) 
	{
		if(!imggrp)imggrp=='D';
		var imgGrpArr = new Array();
		imgGrpArr['D'] = new Array('img_star_object-half.gif','img_star_object-half2.gif','img_star_object_grey-half.gif','img_star_object_grey-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_half1.gif','img_star_half2.gif','img_star_greyhalf1.gif','img_star_greyhalf2.gif');
 		var cimg=0;
 		if(parseInt(rating)<=0)rating=0;
		for(i=10; i>0; i--) 
		{
			cimg =(i%2==0)?(1):(0); 
			cimg = (i>rating)?(cimg+2):cimg;
			document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][cimg];
		}
	}
	function turnOffStars(rating,imggrp) 
	{//'FH'=>'img_star_half1.gif','LH'=>'img_star_half2.gif','FHG'=>'img_star_greyhalf1.gif','LHG'=>'img_star_greyhalf2.gif'
		if(!imggrp)imggrp=='D';
		var imgGrpArr = {};
 		imgGrpArr['D'] = new Array('img_star_object_grey-half.gif','img_star_object_grey-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_greyhalf1.gif','img_star_greyhalf2.gif');
		for(i=rating; i>0; i--) 
		{
			
			if(i%2==0) 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][1];
			}
			else 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][0];
			}
		}
	}

	function turnOnStars(rating,imggrp) 
	{
		if(!imggrp)imggrp=='D';
		var imgGrpArr = {};
		imgGrpArr['D'] = new Array('img_star_object-half.gif','img_star_object-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_half1.gif','img_star_half2.gif');
		for(i=rating; i>0; i--) 
		{
		
			if(i%2==0) 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][1];
			}
			else 
			{
				document.getElementById('star' + i).src =  webRoot+"/images/"+imgGrpArr[imggrp][0];
			}
		}
	}
	function giveRating(rating, destId,imggrp) 
	{
		if(!imggrp || typeof(imggrp)=='undefined' || imggrp==null)imggrp='D';
		document.getElementById(destId).value = rating;
		//alert(document.getElementById(destId).value)
		turnOnOffStars(rating,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(rating,imggrp);
	}
	/* end functions of rating*/
	/*pre load image function*/
	function MM_preloadImages() 
	{ //v3.0
	
	  	var d=document; 
		if(d.images)
	  	{ 
	  		if(!d.MM_p) 
				d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
			webRoot = a[0];
			for(i=1; i<a.length; i++)
				if (a[i].indexOf("#")!=0)
				{ 
					d.MM_p[j]=new Image; 
					d.MM_p[j++].src=webRoot+a[i];
					
				}
		}
	}

	/* function to display popup*/
	function displayPopupMsg(popupDivId, popupMsgDiv, msg, evt, topPos,okDiv,hidenfocusvalue) 
	{
		var popupMsgDiv = document.getElementById(popupMsgDiv);
		document.getElementById("hidden_focus").value = hidenfocusvalue;
		if(popupMsgDiv!=null) 
		{
			popupMsgDiv.innerHTML = msg;
		}
		var popupDiv = document.getElementById(popupDivId);
		
		//alert(popupDiv.style.width);
		height = popupDiv.style.height;
		width = popupDiv.style.width;
		
		if(height.search("px")!=-1)
			height = height.substr(0,height.length-2);
		if(width.search("px")!=-1)
			width = width.substr(0,width.length-2);
		
		
		//alert(height);
			
		
		
		var points = center_of_screen({width:280,height:80});
		//alert(points.x);
		popupDiv.style.top = points.y;
		popupDiv.style.left = points.x;
		popupDiv.style.display = '';
			
		/*if(popupDiv!=null) 
		{
			if (!evt) 
		  		var evt = window.event;
			if (evt.pageX || evt.pageY) 
			{
				posx = evt.pageX;
				posy = evt.pageY;
			}
			else if (evt.clientX || evt.clientY) 
			{
				posx = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;  
				posy = evt.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
			}
			
			posx = screen.width/2;
			var y = screen.height/2;
			//alert(y);
			/*if(evt!=null) 
			{
				x = evt.clientX + 15;
				y = evt.clientY + document.body.scrollTop - 500;
				if(y<0) 
				{
					y = 0;
				}
			}
			*/
			
			//document.getElementById('okbuttonAnchor').focus();
		//}
		if(!okDiv || typeof(okDiv)=='undefined' || okDiv=='')okDiv='okbuttonAnchor';
		if(popupDivId && popupDivId == 'popupMessage'){okDiv = 'okAnc';}
		
		if(document.getElementById(okDiv))
		{
			//alert(okDiv);
			document.getElementById(okDiv).focus();			
		}
	}
	/**/
	
	/*function to use in on off set price*/
	function changePriceCol(selvalue, y, id,typ)
	{
		var doltot='';
		var pricenm='price'+y+'_';
		for(var i=1;i<5;i++)
		{
				doltot +='$';
				if(selvalue==doltot){
					document.getElementById(pricenm+i).style.color = '#f47321';
					if(typ=='set')
					{
						document.getElementById('tempPrice_'+y).value = selvalue;
					}
				}
				else
				{
					document.getElementById(pricenm+i).style.color = '#1B385E';
				}
		}
	}
	/**/
	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;
   
   }
   	/*to get popup message in center of screen */
   	window.size = function()
	{
		var w = 0;
		var h = 0;
	
		//IE
		if(!window.innerWidth)
		{
			//strict mode
			if(!(document.documentElement.clientWidth == 0))
			{
				w = document.documentElement.clientWidth;
				h = document.documentElement.clientHeight;
			}
			//quirks mode
			else
			{
				w = document.body.clientWidth;
				h = document.body.clientHeight;
			}
		}
		//w3c
		else
		{
			w = window.innerWidth;
			h = window.innerHeight;
		}
		return {width:w,height:h};
	}
	
	function center_of_screen()
	{
		var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
	
		var _x = 0;
		var _y = 0;
		var offsetX = 0;
		var offsetY = 0;
	
		//IE
		if(!window.pageYOffset)
		{
			//strict mode
			if(!(document.documentElement.scrollTop == 0))
			{
				offsetY = document.documentElement.scrollTop;
				offsetX = document.documentElement.scrollLeft;
			}
			//quirks mode
			else
			{
				offsetY = document.body.scrollTop;
				offsetX = document.body.scrollLeft;
			}
		}
		//w3c
		else
		{
			offsetX = window.pageXOffset;
			offsetY = window.pageYOffset;
		}
	
		_x = ((this.size().width-hWnd.width)/2)+offsetX;
		_y = ((this.size().height-hWnd.height)/2)+offsetY;
	
		return{x:_x,y:_y};
	}
   /* end */
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1){return "";}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){return "";}
	else{return TRIM_VALUE;}
}

// Right Trim Function
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){return"";}
	var iTemp = v_length -1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){ }
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;}
		iTemp = iTemp-1;
	}
	return strTemp;
}

//Right Trim Function
function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1){return"";}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;
	while(iTemp < v_length)	{
		if(VALUE.charAt(iTemp) == w_space){}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;}
		iTemp = iTemp + 1;
	}
	return strTemp;
}
function IsBlank(obj)
{
	if(Trim(obj.value) == ""){return true;}
	return false;
}   
function toggleAllcontgrab(cb,frm) {
    var val = cb.checked;
	var len = frm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (frm.elements[i].name=='uids[]') {
			frm.elements[i].checked=val;
		}
	}
}