//------------Rating section -----------------
var imagePath		 = "http://172.24.0.9:7003/Storage/rating/";
//var imagePath		 = "http://smartdatainc.co.in:8066/Images/rating/";
//var imagePath = document.getElementById("imagePath").value ;

var largeStarLeftOn  = imagePath+"star_v_on_l.gif";
var largeStarLeftOff = imagePath+"star_v_off_l.gif";
var largeStarMidOn   = imagePath+"star_v_on_m.gif";
var largeStarMidOff  = imagePath+"star_v_off_m.gif";
var largeStarRightOn = imagePath+"star_v_on_r.gif";
var largeStarRightOff= imagePath+"star_v_off_r.gif";
UserRating	= 0;

/*
function isAddress(s){
	//var s=trim(s);
	var bag = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-, ";
	var flag = false; 
	
	for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1){
			flag = true;
		}
    }
    return flag;
}
*/

function checkBadWords(fieldName,badArr,replaceArr){
	var tempStr = new String();
	tempStr=getObject(fieldName).value;
	var i = 0;
	for(i in badArr){
		tempStr = tempStr.replace(eval("/"+badArr[i]+"/g"),replaceArr[i]);
	}
	getObject(fieldName).value = tempStr;
}





function OnMouseClickStars(ratingId){
    
	if(UserRating!=0){
		UserRating=0;
	}else {
		UserRating = ratingId; 	
		getObject("txtRating").value	= ratingId;
	}
}

function OnMouseOverStars(ratingId, img){

  if ((ratingId < 1)||(ratingId > 5)||(UserRating > 0))
    return;

  img.style.cursor = "pointer";
  
  if (ratingId >= 1)
    getObject("rating_star_1").src = largeStarLeftOn;
  else  
    getObject("rating_star_1").src = largeStarLeftOff;
        
  if (ratingId >= 2)        
    getObject("rating_star_2").src = largeStarMidOn;
  else  
    getObject("rating_star_2").src = largeStarMidOff;    
    
  if (ratingId >= 3)            
    getObject("rating_star_3").src = largeStarMidOn;
  else  
    getObject("rating_star_3").src = largeStarMidOff;    
    
  if (ratingId >= 4)                
    getObject("rating_star_4").src = largeStarMidOn;
  else  
    getObject("rating_star_4").src = largeStarMidOff;    
    
  if (ratingId >= 5)                    
    getObject("rating_star_5").src = largeStarRightOn;
  else  
    getObject("rating_star_5").src = largeStarRightOff;
}

function OnMouseOutRating(a, img){

  img.style.cursor = "default";

  if (UserRating == 0){
    getObject("rating_star_1").src = largeStarLeftOff;
    getObject("rating_star_2").src = largeStarMidOff;
    getObject("rating_star_3").src = largeStarMidOff;
    getObject("rating_star_4").src = largeStarMidOff;
    getObject("rating_star_5").src = largeStarRightOff;
 	getObject("txtRating").value	= 0;
  }  
}

function chkBoxes(FormName,FieldName)
{
	var chk=0;
	if(!document.forms[FormName])
		return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];

	if(!objCheckBoxes)
		return;
		var countCheckBoxes = objCheckBoxes.length;
	if(countCheckBoxes){
		for(var i = 0; i < countCheckBoxes; i++){
			if(objCheckBoxes[i].checked==true) {
				chk=1;
				break;
			} else {
				chk=0;	
			}
		}
	} else {
		if(objCheckBoxes.checked==true){
			chk=1;
		}else {
			chk=0;
		}	
	}
	if(chk==0)
		{
			alert('Please select one check box to perform the desired action');
			return false;
		}
		else
		{
			return true;
		}
}

function SetAllCheckBoxe(FormName,FieldName)
{
	
	var isChecked=document.getElementById('idSelectAll').checked;
	
	if(isChecked==true){
		var	CheckValue='true';
	}
	else{
		var	CheckValue='';
	}
	if(!document.forms[FormName])
		return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];

	if(!objCheckBoxes)
		return;
		var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
		{
				objCheckBoxes[i].checked = CheckValue;
		}
}

function setSort(frmName,FieldName,srtBy) {
	document.forms[frmName].hidSortValue.value='sort';
	
	if(document.forms[frmName].hidSortValue.value=='sort')
	{
		if(srtBy=='')
		{
			document.forms[frmName].hidSortAction.value="ASC";	
		}
		else
		{
			document.forms[frmName].hidSortAction.value=srtBy;
		}
	}
	document.forms[frmName].hidSortField.value=FieldName;
	document.forms[frmName].submit();

}

function showBetweenDate(frmobj){
		document.getElementById('betweenData').style.display="";
		document.getElementById('betweenText').style.display="";
	}
	function hideBetweenDate(frmobj){
		document.getElementById('betweenData').style.display="none";
		document.getElementById('betweenText').style.display="none";
		document.getElementById('dateFrom').value="";
		document.getElementById('dateto').value="";
	}


function setView(frmObj,FieldName)
{
	if(document.forms[frmObj.name].show_name_photo.checked==true)
	{	
		document.getElementById(FieldName).value="thumb";
	}
}


	
	
	//=====================tooltip======================================
		function xstooltip_findPosX(obj) 
		{
		  var curleft = 0;
		  if (obj.offsetParent) 
		  {
			while (obj.offsetParent) 
				{
					curleft += obj.offsetLeft
					obj = obj.offsetParent;
				}
			}
			else if (obj.x)
				curleft += obj.x;
			return curleft;
		}
		
		function xstooltip_findPosY(obj) 
		{
			var curtop = 0;
			if (obj.offsetParent) 
			{
				while (obj.offsetParent) 
				{
					curtop += obj.offsetTop
					obj = obj.offsetParent;
				}
			}
			else if (obj.y)
				curtop += obj.y;
			return curtop;
		}
		function xstooltip_show(tooltipId, parentId, divWidth,displayText,messageType)
		{
			posX	= 0;
			posY	= 0;
			//alert("sdfsdfsd");
			it = getObject(tooltipId);
			
			
			it.style.top	= "";
			it.style.width	= divWidth;
			it.style.left	= "";
			if ((it.style.top == '' || it.style.top == 0) 
				&& (it.style.left == '' || it.style.left == 0))
			{
				// need to fixate default size (MSIE problem)
				it.style.width = it.offsetWidth + 'px';
				it.style.height = it.offsetHeight + 'px';
				
				img = getObject(parentId); 
				
				// if tooltip is too wide, shift left to be within parent 
				if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
				if (posX < 0 ) posX = 0; 
				
				x = xstooltip_findPosX(img) + posX;
				y = xstooltip_findPosY(img) + posY;
				var browser=navigator.appName;
				if(browser=="Microsoft Internet Explorer"){
					it.style.top = y+35 + 'px';
					it.style.left = x+5 + 'px';
				}else {
					it.style.top = y+20 + 'px';
					it.style.left = x-5 + 'px';
				}
			}
			displayTextDivObj	= getObject("errorMessageTD");
			displayTextDivObj.innerHTML	= displayText; 
			if(messageType==1){
				displayTextDivObj.style.color	= "#CC3300";
			}else if(messageType==2){
				displayTextDivObj.style.color	= "#006600";
			}
			it.style.visibility = 'visible'; 
		}
		function xstooltip_hide(id)
		{
			it = getObject(id); 
			it.style.visibility = 'hidden'; 
		}
		
		
		
		function xstooltipImg_show(tooltipId, parentId, divWidth,imgSource)
		{
			posX	= 0;
			posY	= 0;
			//alert("sdfsdfsd");
			it = getObject(tooltipId);
			it.style.top	= "";
			it.style.width	= divWidth;
			it.style.left	= "";
			if ((it.style.top == '' || it.style.top == 0) 
				&& (it.style.left == '' || it.style.left == 0))
			{
				// need to fixate default size (MSIE problem)
				it.style.width = it.offsetWidth + 'px';
				it.style.height = it.offsetHeight + 'px';
				
				img = getObject(parentId); 
			
				// if tooltip is too wide, shift left to be within parent 
				if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
				if (posX < 0 ) posX = 0; 
				
				x = xstooltip_findPosX(img) + posX;
				y = xstooltip_findPosY(img) + posY;
				var browser=navigator.appName;
				if(browser=="Microsoft Internet Explorer"){
					it.style.top = y+35 + 'px';
					it.style.left = x+5 + 'px';
				}else {
					it.style.top = y+20 + 'px';
					it.style.left = x-5 + 'px';
				}
			}
			displayImgDivObj		= getObject("imageforShowFull");
			displayImgDivObj.src	= imgSource;
			it.style.visibility = 'visible'; 
		}
		
	
	//====================================================================

//===============================Create object ============================

function getObject(a){
	  if(document.getElementById && document.getElementById(a)){
		return document.getElementById(a)
	  }else if(document.all&&document.all(a)){
		return document.all(a)
	  }else if(document.layers&&document.layers[a]){
		return document.layers[a]
	  }else{
		return false
	  }
}

//==========================================================================




// ===========================Prelaod images==============================


		function MM_swapImgRestore() { //v3.0
		  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
		}
		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; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}

		function MM_findObj(n, d) { //v4.01
		  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		  if(!x && d.getElementById) x=d.getElementById(n); return x;
		}

		function MM_swapImage() { //v3.0
		  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
		}


// ==========================================================================

function showHideDiv(divName){
	divObj	= getObject(divName);
	if(divObj.style.display=="none"){
		divObj.style.display	= "inline";
	}else {
		divObj.style.display	= "none";
	}
}


function submitFormThroughJS(frmName){
	frmObj	= getObject(frmName);
	frmObj.submit();
}

function submitFormThroughHyperLink(obj){
	var validationFunction	= obj.name +"_validation(obj)";
	var returnStatus = eval(validationFunction);
	if(returnStatus==true){
		obj.submit();
	}
}

function resetFormThroughHyperLink(obj)
{
	obj.reset();
}


//===========================================================
function SetAllCheckBoxes(FormName,FieldName)
	{
	var isChecked=document.getElementById('checkAll').checked;

	if(isChecked==true){
		var	CheckValue='true';
		
	}
	else
	{
		var	CheckValue='';
	}	

	if(!FormName)
		return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];

	if(!objCheckBoxes)
		return;
		var countCheckBoxes = objCheckBoxes.length;

	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
		{
				objCheckBoxes[i].checked = CheckValue;

			
		}
}

function checkMasterCheckBox(checkBoxObj,formName,checkBoxName,masterCheckBoxName){
	allCheckBoxCheckedStatus	= false;
	formObj	= getObject(formName);
	masterCheckBoxObj	= getObject(masterCheckBoxName);
	allCheckBoxCheckedStatus	= isAllcheckBoxSelected(formObj,checkBoxName);
	//alert(allCheckBoxCheckedStatus);
	if(checkBoxObj.checked==true){
		if(allCheckBoxCheckedStatus==true){
			masterCheckBoxObj.checked	= true;
		}
	}else{
		masterCheckBoxObj.checked	= false;
	}
	
}


//=============================================================
//===========================================================
function checkedUnCheckedAllCheckboxes(FormName,masterCheckBoxObj,checkBoxName)
	{
	var isChecked=masterCheckBoxObj.checked;
	
	if(isChecked==true){
		var	CheckValue='true';
		
	}
	else
	{
		var	CheckValue='';
	}	

	if(!FormName)
		return;
		var objCheckBoxes = document.forms[FormName].elements[checkBoxName];

	if(!objCheckBoxes)
		return;
		var countCheckBoxes = objCheckBoxes.length;

	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
		{
				objCheckBoxes[i].checked = CheckValue;

			
		}
}


//=============================================================


function isAllcheckBoxSelected(formObj,checkBoxName){
	var status	= false;
	var countCheckBoxes = 0;
	var objCheckBoxes = formObj.elements[checkBoxName];
	countCheckBoxes = objCheckBoxes.length;
	if(countCheckBoxes!=0){
		for(var i = 0; i <countCheckBoxes; i++){
			if(objCheckBoxes[i].checked==true){
				status	= true;
			}else{
				status	= false;
				break;
			}
		}
	}if(!countCheckBoxes) {
		if(objCheckBoxes.checked==true){
			status	= true;
		}else {
			status	= false;
		}
	}
	return status;
}


//======================= Javacsript function for mouse effect on buttons ===================================

//========== Function for loign button in header =============

function buttonOnMouseOverHeader(buttonObj,buttonEndImageDiv)
{
	buttonObj.className="buttonGrayBackground1";
	document.getElementById(buttonEndImageDiv).className="buttonEndGrayBackground1";
}
function buttonOnMouseOutHeader(buttonObj,buttonEndImageDiv)
{
	buttonObj.className="buttonRedBackground1";
	document.getElementById(buttonEndImageDiv).className="buttonEndRedBackground1";

}

//=============== function for normal button =================
function buttonOnMouseOver(buttonObj,buttonEndImageDiv)
{
	buttonObj.className="buttonGrayBackground";
	document.getElementById(buttonEndImageDiv).className="buttonEndGrayBackground";
}
function buttonOnMouseOut(buttonObj,buttonEndImageDiv)
{
	buttonObj.className="buttonRedBackground";
	document.getElementById(buttonEndImageDiv).className="buttonEndRedBackground";

}


//-------------------- Search box on top bar ====================
function onFocusOnSearchBoxInTop(){
	getObject('srch_data').value	= "";
}

function onFocusOutOnSearchBoxInTop(){
	if(getObject('srch_data').value	== "")
	getObject('srch_data').value	= "Keyword search";
}

//===============================================================



function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function formatNumPrice(input){
	
 var num = input.value.replace(/\,/g,'');
 
 if(isNaN(num.substring(0,1))){
	  	  num = num.substring(1);
	  }
	  
 //string=num;
 //string = string.replace('$','');
 
 //string=string.replace(',','');
 //num=string;
 if(!isNaN(num)){ 
    
	//num=numberFormat(num,"$");
	num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\.]/,'');
     
	  if(isNaN(num.substring(0,1))){
	  	  num = num.substring(1);
	  }
	  
	 num='$'+num;
	   
   input.value = num;
  }

  else{ alert('You may enter only numbers in this field!');
        input.value = input.value.substring(0,input.value.length-1);
  }   
}
function formatNum(input){
	
 var num = input.value.replace(/\,/g,'');
 
	  
 //string=num;
 //string = string.replace('$','');
 
 //string=string.replace(',','');
 //num=string;
 if(!isNaN(num)){ 
    
	//num=numberFormat(num,"$");
	num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\.]/,'');
     
	  if(isNaN(num.substring(0,1))){
	  	  num = num.substring(1);
	  }
	  
	 
	   
   input.value = num;
  }

  else{ alert('You may enter only numbers in this field!');
        input.value = input.value.substring(0,input.value.length-1);
  }   
}
function formatLot(input){
         var num = input.value.replace(/\,/g,'');
        if(String(num).indexOf(".")> -1)
		{
			
	
		if (String(num).indexOf(".") < String(num).length) {
        var num=String(num).length-String(num).indexOf(".");
		
		num=num-1;
		num=num-2;
		//alert("Number can only be 2 decimal places at most.");
          input.value = input.value.substring(0,input.value.length-num);
		} 
 
	}
 
}

function formatDOB2(input){
 var num = input.value.replace(/\-/g,'');
  if(!isNaN(num)){ 
     if(input.value.length<8){
/*	 num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{2})/g,'$1-').split('').reverse().join('').replace(/^[\.]/,'');
	num = num.toString().replace("(^\\d{"+(num.toString().length%3||-1)+"})(?=\\d{3})"),"$1"+"-").replace(/(\d{3})(?=\d)/g,"$1"+"-");*/

      input.value = num;
	 } else {
		alert('Please !');
        input.value = input.value.substring(0,input.value.length-1); 
	 }
  }
  else{ 
  		alert('You may enter only numbers in this field!');
        input.value = input.value.substring(0,input.value.length-1);
  	  }   
  
}


function formatPhone(objFormField){
   if(objFormField.value.length <=14){
   intFieldLength = objFormField.value.length;
    if(intFieldLength == 3){
         objFormField.value =  + objFormField.value + "." ;
         return false;
         }
   	if(intFieldLength >= 9 && intFieldLength <= 10){
       objFormField.value = objFormField.value + ".";
       //return false;
       }
	   } else{
		   objFormField.value = objFormField.value.substring(0,objFormField.value.length-1);
	   }
   
}
function formatNumPhone(input){
	
  var num = input.value.replace(/\./g,'');
if(!isNaN(num)){ 
     if(input.value.length<12){
		num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1.').split('').reverse().join('').replace(/^[\.]/,'');
      	input.value = num;
	} else {
		if(input.value.length>13){
			input.value = input.value.substring(1,input.value.length);
		}
		//alert('Phone numbers should be of 10 numbers!');
		//input.value = input.value.substring(0,input.value.length);
	}
} else{ 
  		alert('You may enter only numbers in this field!');
        input.value = input.value.substring(0,input.value.length-1);
  }   
}

readableNumberLimiter = function (number,limiter){  
//return number.toString().replace(     new RegExp("(^\\d{"+(number.toString().length%3||-1)+"})(?=\\d{3})"),"$1"+limiter).replace(/(\d{3})(?=\d)/g,"$1"+limiter);
}


function formatDOB(input){
 var num = input.value.replace(/\-/g,'');
  if(!isNaN(num)){ 
     if(input.value.length<8){
	 num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{2})/g,'$1-').split('').reverse().join('').replace(/^[\.]/,'');
      input.value = num;
	 } else {
		if(input.value.length>8){
			input.value = input.value.substring(1,input.value.length);
		} 
	 }
  }
  else{ alert('You may enter only numbers in this field!');
        input.value = input.value.substring(0,input.value.length-1);
  }   
  
  
}



function chkdate(input)
{
	
	if(!isValidFormatDate(input.value)){
			alert("Please Enter Valid Date");
			}	
}