var vsIsGridSelected = 'N'
var giPageNo = "1"
var giPageSize = readCookie("PageSize")

function IsAjaxError(poResponse)
{
	if(poResponse.error != null)
	{
		alert(poResponse.error)
		return false
	}
	else if(poResponse.value == null)
	{
		alert(poResponse.value)
		return false
	}
	else if(poResponse.value.substring(0,5) == "ERROR")
	{
		alert(poResponse.value)
		return false
	}
	else if(poResponse.value == "")
	{
	    //alert("System Error")
		return false
	}
	return true
}

function IsAjaxOKError(poResponse,psMessage)
{
	if(poResponse.error != null)
	{
		alert(poResponse.error)
		return false
	}
	else if(poResponse.value != "OK")
	{
		alert(poResponse.value)
		return false
	}
	else if(poResponse.value == null)
	{
		alert(poResponse.value)
		return false
	}
	else
	{
		if(psMessage != "")
		{
			alert(psMessage)
		}
	}
	return true
}


var viMenuCount


//http://www.quirksmode.org/js/cookies.html   
function createCookie_Old(psname,psvalue,psdays) 
{
	if (psdays) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(psdays*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
	{
		var expires = "";
	}
	//document.cookie = "AutoDealers=" + name + "=" + value +  expires + ";";
	document.cookie = "AutoDealers=" + psname + "=" + psvalue + expires + "; path=/";
}

function createCookie(name,value,days) 
{
    if (days) 
    {
	    var date = new Date();
	    date.setTime(date.getTime()+(days*24*60*60*1000));
	    var expires = "; expires="+date.toGMTString();
    }
    else
    { 
        var expires = "";
    }
        document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie123(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
	    var c = ca[i];
	    while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return "";
}

function readCookie_Old(vsCookieName)
{
	var vsCookie = unescape(document.cookie);
	var vsFound = "N";
	if(vsCookie != "")
	{
	    var varrCookie = vsCookie.split(";");
	    for(viCnt=0;viCnt<varrCookie.length;viCnt++)
	    {
		    if(varrCookie[viCnt].indexOf(vsCookieName) != -1)
		    {
			    break
			    vsFound = "Y"    
		    }
	    }
        if(vsFound == "Y")
        {
            var varrrCookie1 = varrCookie[viCnt].split("=");
            return varrrCookie1[2]
        }
        else
        {
            return ""
        }
	}
    else
    {
        return ""
    }
}

function eraseCookie(name) 
{
	createCookie(name,"",-1);
}


function FillSellers_Buyers(psDrpSellerName, psDrpBuyerName, pbIsAll)
{
	LoadMsg(psDrpSellerName);
	LoadMsg(psDrpBuyerName);
	voResponse = clInventoryMethods.GetSellersBuyers(psDrpSellerName, psDrpBuyerName, Sellers_Buyers_CallBack);
}

function Sellers_Buyers_CallBack(voResponse)
{
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll("drpSearchSeller");
			ResetLoadAll("drpSearchBuyer");
		}	
		else
		{
			ResetLoadMsg("drpSearchSeller");
			ResetLoadMsg("drpSearchBuyer");
		}
	}
	else
	{
		ResetLoadMsg("drpSearchSeller");
		ResetLoadMsg("drpSearchBuyer");
	}
}

function FilldealerBuyers(psDrpName, psCompanyId, pbIsAll)
{
	LoadMsg(psDrpName);
	voResponse = clInventoryMethods.GetdealerBuyers(psDrpName, psCompanyId);
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}


function FillCustomers(psDrpName, psIsdealer, pbIsAll)
{
	LoadMsg(psDrpName);
	voResponse = clInventoryMethods.GetCustomers(psDrpName, psIsdealer);  
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}

function FilldealerCustomers(psDrpName, psCompanyId, pbIsAll)
{
	LoadMsg(psDrpName);
	voResponse = clInventoryMethods.GetdealerCustomers(psDrpName, psCompanyId);  
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}

function FillCompanyUsers(psDrpName, pbIsAll)
{
	LoadMsg(psDrpName);
	//psCompanyId = eval("document.Form1." + psDrpdealerName)
	voResponse = clWebMasterDropDown.GetCompanyUser(psDrpName);  
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}

function FilldealerBuyers(psDrpName, psCompanyId, pbIsAll)
{
	LoadMsg(psDrpName);
	voResponse = clInventoryMethods.GetdealerBuyers(psDrpName, psCompanyId);  
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}


function Fillinventorytatus(psDrpName, pbIsAll)
{
	LoadMsg(psDrpName);
	voResponse = clInventoryMethods.Getinventorytatus(psDrpName);  
	if(IsAjaxError(voResponse))
	{
		eval(voResponse.value)
	}
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}


function LoadMsg(drpName)
{
	objDrp = eval("document.Form1." + drpName)
	objDrp.length = 0
	objDrp.length = objDrp.length + 1
	objDrp.options[objDrp.length - 1].text = 'Loading please wait.......'
	objDrp.options[objDrp.length - 1].value = ''
	/*
	objDrp = eval('document.getElementById("' + drpName +  '")')
	alert(objDrp)
	objDrp.length = 0
	objDrp.length = objDrp.length + 1
	objDrp.options[objDrp.length - 1].text = 'Loading please wait.......'
	objDrp.options[objDrp.length - 1].value = ''
	*/
}

function ResetLoadMsg(drpName)
{
	drpObj = eval("document.Form1." + drpName)
	//drpObj= eval('document.getElementById("' + drpName +  '")')
	drpObj.options[0].text = "--Select--";
	drpObj.options[0].value = "";
}

function ResetBlankSelect(drpName)
{
	drpObj = eval("document.Form1." + drpName)
	//drpObj= eval('document.getElementById("' + drpName +  '")')
	drpObj.options[0].text = "";
	drpObj.options[0].value = "";
}


function ResetLoadAll(drpName, psDispName)
{
	drpObj = eval("document.Form1." + drpName)
	//drpObj= eval('document.getElementById("' + drpName +  '")')
	var vsText = "All"
	if(typeof(psDispName) != "undefined")
	{
	    vsText = vsText + " " + psDispName
	}
	drpObj.options[0].text = vsText;
	drpObj.options[0].value = "";
	//drpObj.options[0].value = "ALL";
}


function isReadOnly(poObj,pbValue)
{
	poObj.readOnly = pbValue
	if(pbValue)
	{
		poObj.style.backgroundColor = "#cfcfcf"
	}
	else
	{
		poObj.style.backgroundColor = "#ffffff"
	}
	poObj.style.border = "1px solid #7f9db9"
}


//Image Expand Functionality End
function expandImageCentered(imgId, imgSrc, e, obj) 
{
	var id = imgId + "_container";
	var smImageId = imgId + "_sm_Image";
	var parentid = imgId + "_abs_container";
	var cont = document.getElementById(id);
	var smImg = document.getElementById(smImageId);
	
	cont.style.top = "100px";
	cont.style.left = "100px";
	
	if(cont.style.display == 'none')
	{
		cont.style.display = 'block';
	}
	else
	{
		var divText = "<div class='largeFloatSnp' id='largeFloatImg'></div>";
		var lgImg = new Image();
		lgImg.src = imgSrc;
		var cnt = 0;
		var dynSrc = imgSrc;
		var dynImgID = "dyn_lg_" + imgId;
	    
		var closeUrl = "document.getElementById('" + id + "').style.display='none';";
	    
		var innerHtml= "<table cellpadding='0' style='background-color:#dddddd;margin:0px;padding:0px;border-style=solid;border-width:1px;border-color:#666666;' id='dynLargeTable'>"
			+ "<tr><td style='padding:0px;margin:0px;background-color:#dddddd'><a align='right' href=\"javascript:var x=" + closeUrl + ";\">"
			+ "<img border='0' align='right' src='../images/tipclose.gif'></a></td></tr>"
			+"<tr><td style='padding:0px;margin:0px;background-color:#ffffff'><a href=\"javascript:var x=" + closeUrl + ";\">"
				+"<img id='" + dynImgID + "' border='0' src='" + dynSrc + "'></a></td></tr>"
			+"</table>";
			cont.innerHTML = innerHtml;
			cont.style.position = "absolute";
	        
		var inImage = cont.getElementsByTagName("img")[1];
	        
		if(!inImage.complete)
		{
				var newImage = new Image();
				newImage.src = inImage.src;
				inImage.realImg = newImage;
				inImage.src = smImg.src;
				inImage.width = 200;
				swImg(inImage);
		}
	        
		// Fix the image loading problem
		inImage = cont.getElementsByTagName("img")[0];
	        
		if(!inImage.complete)
		{
				var newImage = new Image();
				newImage.src = inImage.src;
				inImage.realImg = newImage;
				inImage.src = smImg.src;
				swImg(inImage);
		}
	}
}

function swImg(img)
{
	if(img.realImg.complete)
	{
		img.src = img.realImg.src;
		if(img.realImg.width > 100)
		{
			img.width = img.realImg.width;
		}
	}
	else
	{
		setTimeout ( function() { swImg(img); }, 10 );
	}
}

function GetJavaDate(piDays)
{
	var vsDate = ""
	var vsMonth = ""
	var vsYear = ""
	var vsData = ""
	var voTodayDate = new Date()
	
	voTodayDate.setDate(voTodayDate.getDate() + piDays)
	
	vsDate = String(voTodayDate.getDate())
	if(vsDate.length < 2)
	{
		vsDate = "0" + vsDate
	}
	vsMonth = String(voTodayDate.getMonth() + 1)
	if(vsMonth.length < 2)
	{
		vsMonth = "0" + vsMonth
	}
	vsYear = String(voTodayDate.getFullYear())
	
	vsData = vsDate + "/" + vsMonth + "/" + vsYear
	return vsData
}

function GoToPage(nOpt)
{
	var vsFileName = ""
	if(nOpt==1)
	{
		vsFileName = "dealer_Signup.aspx"
	}
	if(nOpt==2)
	{
		vsFileName = "User_Signup.aspx"
	}
	if(nOpt==3)
	{
		vsFileName = "Default_Home.aspx"
	}
	if(nOpt==4)
	{
		vsFileName = "Live_Bidding_General.aspx"
	}
	if(nOpt==5)
	{
		vsFileName = "Used_Cars.aspx"
	}
	if(nOpt==6)
	{
		vsFileName = "Training.aspx"
	}
	window.location.href=vsFileName
}


function FillAlphaMonths(psDrpName, pbIsAll)
{
	objDrp = eval("document.Form1." + psDrpName)
	var months=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	LoadMsg(psDrpName);
	
	for(viCnt=0; viCnt < months.length; viCnt ++)
	{
		objDrp.length = objDrp.length + 1;
		objDrp.options[objDrp.length - 1].text = months[viCnt]
		objDrp.options[objDrp.length - 1].value = viCnt + 1
	}	
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}

function FillCardYears(psDrpName, pbIsAll)
{
	objDrp = eval("document.Form1." + psDrpName)
	var vdCurrDate = new Date();
	var viCurrYear = vdCurrDate.getFullYear();

	LoadMsg(psDrpName);
	for(viCnt=viCurrYear; viCnt < 2020; viCnt ++)
	{
		objDrp.length = objDrp.length + 1;
		objDrp.options[objDrp.length - 1].text = viCnt
		objDrp.options[objDrp.length - 1].value = viCnt
	}	
	if(typeof(pbIsAll) != "undefined")
	{
		if(pbIsAll)
		{
			ResetLoadAll(psDrpName);
		}	
		else
		{
			ResetLoadMsg(psDrpName);
		}
	}
	else
	{
		ResetLoadMsg(psDrpName);
	}
}


function EnlargeVehiclePhoto(psVehiclePhoto)
{
	document.Form1.img1.src = psVehiclePhoto
	//window.open("inventory_Photo_Enlarge.aspx")
}



function FillCommonMonth(psDrpName)
{
	var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	
	var voCommonMonth = eval("document.Form1." + psDrpName)
	voCommonMonth.length = voCommonMonth.length + 1
	voCommonMonth.options[voCommonMonth.length - 1].text = "--";
	voCommonMonth.options[voCommonMonth.length - 1].value = ""
	for(viCnt=0; viCnt < MONTH_NAMES.length; viCnt++)
	{
		voCommonMonth.length = voCommonMonth.length + 1
		voCommonMonth.options[voCommonMonth.length - 1].text = MONTH_NAMES[viCnt];
		voCommonMonth.options[voCommonMonth.length - 1].value = voCommonMonth.length
	}
}

function FillCommonDay(psDrpName)
{
	var voCommonMonth = eval("document.Form1." + psDrpName)
	voCommonMonth.length = voCommonMonth.length + 1
	voCommonMonth.options[voCommonMonth.length - 1].text = "--";
	voCommonMonth.options[voCommonMonth.length - 1].value = ""
	for(viCnt=0; viCnt < 31; viCnt++)
	{
		voCommonMonth.length = voCommonMonth.length + 1
		voCommonMonth.options[voCommonMonth.length - 1].text = viCnt;
		voCommonMonth.options[voCommonMonth.length - 1].value = viCnt
	}
}

function FillCommonYear(psDrpName)
{
	var voCommonMonth = eval("document.Form1." + psDrpName)
	voCommonMonth.length = voCommonMonth.length + 1
	voCommonMonth.options[voCommonMonth.length - 1].text = "--";
	voCommonMonth.options[voCommonMonth.length - 1].value = ""
	var vsTempDate = new Date()
	for(viCnt=1920; viCnt <= (vsTempDate.getFullYear()-18); viCnt++)
	{
		voCommonMonth.length = voCommonMonth.length + 1
		voCommonMonth.options[voCommonMonth.length - 1].text = viCnt;
		voCommonMonth.options[voCommonMonth.length - 1].value = viCnt
	}
}

function FillDurationYear(psDrpName)
{
	var voCommonMonth = eval("document.Form1." + psDrpName)
	var vsTempDate = new Date()
	for(viCnt=0; viCnt <= 12; viCnt++)
	{
		voCommonMonth.length = voCommonMonth.length + 1
		voCommonMonth.options[voCommonMonth.length - 1].text = viCnt;
		if(viCnt == 12)
		{
			voCommonMonth.options[voCommonMonth.length - 1].value = viCnt + "+"
		}
		else
		{
			voCommonMonth.options[voCommonMonth.length - 1].value = viCnt
		}
	}
}

function FillDurationMonth(psDrpName)
{
	var voCommonMonth = eval("document.Form1." + psDrpName)
	var vsTempDate = new Date()
	for(viCnt=0; viCnt <= 12; viCnt++)
	{
		voCommonMonth.length = voCommonMonth.length + 1
		voCommonMonth.options[voCommonMonth.length - 1].text = viCnt;
		voCommonMonth.options[voCommonMonth.length - 1].value = viCnt
	}
}

function DisplayImages_Photos(psHdnPhotoname, psImagePhoto, psId, psUpdateType, psImagePath, piColumns)
{
	var vsLogo = document.getElementById(psHdnPhotoname).value
	document.getElementById(psHdnPhotoname).value = ""

	var vsOldPath = psImagePath
	var vsNewPath = psImagePath
	if(psId != "")
	{
		vsNewPath = vsNewPath + psId + '/'
	}
	//document.Form1.hdnVehiclePhotos.value = vsLogo
	var vaLogo = vsLogo.split("|")
	
	var vsPhotoTables = "<table cellpadding=2 cellspacing=2 border=0>"
	var viPhotosCount = 0
	if(vsLogo.length > 0)
	{
		viPhotosCount = vaLogo.length-1;
	}
	vsLogo = ""
	var vsImgLogo = ""
	
	//return false
	for(viPhotoCnt=0; viPhotoCnt < viPhotosCount; viPhotoCnt++)
	{
		vsPhotoTables = vsPhotoTables + "<tr>"	
		for(viPhotocol=0; viPhotocol < piColumns; viPhotocol ++)
		{
			if(viPhotoCnt < viPhotosCount)
			{
				if(psUpdateType == "U")	// When selling new car apid not generated so updatetype is "I" then not need to
				{															// replace with apid, but while updating or back from review apid generated
																			// and images from root path deleted, so replace is required
					if(vaLogo[viPhotoCnt].indexOf(psId) == -1)
					{
						vaLogo[viPhotoCnt] = vaLogo[viPhotoCnt].replace(vsOldPath, vsNewPath)		
					}
				}
				
				if(vaLogo[viPhotoCnt] != "")
				{
					vsImgLogo = vaLogo[viPhotoCnt]
					vsPhotoTables = vsPhotoTables + "<td align=center class=clsPhotoListBorder>"	
					vsPhotoTables = vsPhotoTables + "<img src='" + vaLogo[viPhotoCnt] + "' width=130 height=165>"	
					vsPhotoTables = vsPhotoTables + "<br><span height=30><a href='#' onclick=removePhotoCommon('" + vaLogo[viPhotoCnt] + "','" + psHdnPhotoname + "','" + psImagePhoto + "','" + psId + "','" + psUpdateType + "','" + psImagePath + "','" + piColumns + "'); style='font-size:11px;color:#000000;'><u>remove</u></a></span>"
					vsPhotoTables = vsPhotoTables + "</td>"	
					
					vsLogo = vsLogo + vaLogo[viPhotoCnt] + "|"
					
					viPhotoCnt++;
				}
			}
		}
		viPhotoCnt--;
		vsPhotoTables = vsPhotoTables + "</tr>"	
	}
	if(viPhotosCount <= 0)
	{
		vsPhotoTables = vsPhotoTables + "<tr>"	
	    vsPhotoTables = vsPhotoTables + "<td align=center class=clsPhotoListBorder>"	
	    vsPhotoTables = vsPhotoTables + "<img src='../Images/Upload_Photo.jpg' height=55 width=55>"	
	    vsPhotoTables = vsPhotoTables + "</td>"	
		vsPhotoTables = vsPhotoTables + "</tr>"	
	}
	vsPhotoTables = vsPhotoTables + "</table>"	
	if(vsImgLogo == "")
	{
		//document.getElementById(psImagePhoto).src = "../Images/Upload_Photo.jpg"
		document.getElementById(psHdnPhotoname).value = ""
	    document.getElementById(psImagePhoto).innerHTML = vsPhotoTables
	}
	else
	{
	    document.getElementById(psImagePhoto).innerHTML = vsPhotoTables
		//document.getElementById(psImagePhoto).src = vsImgLogo
		document.getElementById(psHdnPhotoname).value = vsLogo
	}
}

function removePhotoCommon(psPhoto, psHdnPhotoname, psImagePhoto, psId, psUpdateType, psImagePath, piColumns)
{
	if(confirm("Are you sure!"))
	{
		//DisplayProcessing()
		var vsPhotos = document.getElementById(psHdnPhotoname).value
		vsPhotos = vsPhotos.replace(psPhoto + "|", "")
		document.getElementById(psHdnPhotoname).value = vsPhotos
        DisplayImages_Photos(psHdnPhotoname, psImagePhoto, psId, psUpdateType, psImagePath, piColumns)
	}
}


function GetQueryString(psQueryString)
{
	vsQueryString = window.location.search.substring(1)
	vaQueryString = vsQueryString.split("&")
	
	for(viCnt=0; viCnt < vaQueryString.length; viCnt++)
	{
		vaTemp = vaQueryString[viCnt].split("=")
		if(vaTemp[0]==psQueryString)
		{
			return vaTemp[1];
			break;
		}
	}
	return ""
}


function mOverSubMenuLevel2(poObj)
{
	poObj.style.backgroundColor = "red"
}


function ViewProcessing()
{
	vsLoading = "<br><br><br><bR><br><br><br><bR><br><br><br><img src='images/loading52.gif' border=0><br><br>"
	document.getElementById("divProcessing").className = "clsShowProcessing"
	//document.getElementById("divProcessing").style.visibility = "visible"
	document.getElementById("divProcessing").style.display = "block";
	document.getElementById("divProcessing").innerHTML = vsLoading
	document.getElementById("divProcessing").style.height = document.body.offsetHeight  //document.Form1.offsetHeight ///
	document.getElementById("divProcessing").style.width = document.Form1.offsetWidth
	//document.body.scroll = "no"
	if(window.parent.frames.length == 3)
	{
	    document.getElementById("divProcessing").style.height = 615
	}
}

function ViewProcessingModule(psDiv)
{
	vsLoading = "<br><br><center><img src='images/loading52.gif' border=0><br><br></center>"
	//document.getElementById(psDiv).className = "clsShowProcessing"
	//document.getElementById("divProcessing").style.visibility = "visible"
	document.getElementById(psDiv).innerHTML = vsLoading
	//document.getElementById(psDiv).style.height = 200  //document.Form1.offsetHeight ///
	//document.getElementById(psDiv).style.width = 200
}

function StopProcessingModule(psDiv)
{
	document.getElementById(psDiv).innerHTML = ""
	document.getElementById(psDiv).style.height = 0
	document.getElementById(psDiv).style.width = 0
}


function StopProcessing()
{
	vsLoading = ""
	document.getElementById("divProcessing").innerHTML = vsLoading
	document.getElementById("divProcessing").style.height = 0
	document.getElementById("divProcessing").style.width = 0
	document.getElementById("divProcessing").className = "clsHideProcessing"
	document.getElementById("divProcessing").style.visibility = "hidden"
}

function WatchVehicleVideo(psVideoUrl)
{
	var windowprops = "height=251,width=321,toolbar=no,location=yes,addressbar=yes,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"
    window.open("../Root_WebForms/Video_Play.aspx?qVideo=" + psVideoUrl, "", windowprops)
}

function DisplayPhotos(psHdnPhotoname, psImagePhoto, psId, psUpdateType, psImagePath, piColumns)
{
	var vsLogo = document.getElementById(psHdnPhotoname).value
	document.getElementById(psHdnPhotoname).value = ""
	
	var vsOldPath = psImagePath
	var vsNewPath = psImagePath
	if(psId != "")
	{
		vsNewPath = vsNewPath + psId + '/'
	}
	//document.Form1.hdnVehiclePhotos.value = vsLogo
	var vaLogo = vsLogo.split("|")
	
	var vsPhotoTables = "<table cellpadding=0 cellspacing=0 width=100% border=0>"
	var viPhotosCount = 0
	if(vsLogo.length > 0)
	{
		viPhotosCount = vaLogo.length-1;
	}
	
	vsLogo = ""
	var vsImgLogo = ""
	
	//return false
	for(viPhotoCnt=0; viPhotoCnt < viPhotosCount; viPhotoCnt++)
	{
		vsPhotoTables = vsPhotoTables + "<tr>"	
		for(viPhotocol=0; viPhotocol < piColumns; viPhotocol ++)
		{
			if(viPhotoCnt < viPhotosCount)
			{
				if(psUpdateType == "U")	// When selling new car apid not generated so updatetype is "I" then not need to
				{															// replace with apid, but while updating or back from review apid generated
																			// and images from root path deleted, so replace is required
					if(vaLogo[viPhotoCnt].indexOf(psId) == -1)
					{
						vaLogo[viPhotoCnt] = vaLogo[viPhotoCnt].replace(vsOldPath, vsNewPath)		
					}
				}
				
				if(vaLogo[viPhotoCnt] != "")
				{
					vsImgLogo = vaLogo[viPhotoCnt]
					vsPhotoTables = vsPhotoTables + "<td align=center class=clsPhotoListBorder>"	
					vsPhotoTables = vsPhotoTables + "<img src='" + vaLogo[viPhotoCnt] + "' height=55 width=55>"	
					vsPhotoTables = vsPhotoTables + "<br><span height=30><a href='#' onclick=removePhoto('" + vaLogo[viPhotoCnt] + "'); style='font-size:11px;color:#000000;'><u>remove</u></a></span>"
					vsPhotoTables = vsPhotoTables + "</td>"	
					
					vsLogo = vsLogo + vaLogo[viPhotoCnt] + "|"
					viPhotoCnt++;
				}
			}
		}
		viPhotoCnt--;
		vsPhotoTables = vsPhotoTables + "</tr>"	
	}
	vsPhotoTables = vsPhotoTables + "</table>"	

	if(vsImgLogo == "")
	{
		document.getElementById(psImagePhoto).src = "../Images/Upload_Photo.jpg"
		document.getElementById(psHdnPhotoname).value = ""
	}
	else
	{
		document.getElementById(psImagePhoto).src = vsImgLogo
		document.getElementById(psHdnPhotoname).value = vsLogo
	}
}


function round(number,X) 
{
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function LoanCalculator() 
{
	if ((document.Form1.txtLoanAmount.value == null || document.Form1.txtLoanAmount.value.length == 0) 
	    || (document.Form1.drpMonths.value == null || document.Form1.drpMonths.value.length == 0) 
	    || (document.Form1.txtInterestRate.value == null || document.Form1.txtInterestRate.value.length == 0))
	{ 
		document.Form1.txtEMI.value = ""
	}
	else
	{
		var viLoanAmount = document.Form1.txtLoanAmount.value;
		viLoanAmount = viLoanAmount - (parseFloat("0" + document.Form1.txtDownPayment.value));
		var viMonths  = document.Form1.drpMonths.value;
		var viIntRate  = document.Form1.txtInterestRate.value / 1200;
        
		var viMonthlyPayment = formatNumeric(viLoanAmount * viIntRate / (1 - (Math.pow(1/(1 + viIntRate), viMonths))));
		document.Form1.txtEMI.value = "$" + viMonthlyPayment
		//document.getElementById("spnBiWeekly").innerHTML = round(viMonthly * 24/52,2);
	}
}

function LoanCalculatorReverse() 
{
	if ((document.Form1.txtEffordableEMI.value == null || document.Form1.txtEffordableEMI.value.length == 0) 
	    || (document.Form1.drpMonths1.value == null || document.Form1.drpMonths1.value.length == 0) 
	    || (document.Form1.txtInterestRate1.value == null || document.Form1.txtInterestRate1.value.length == 0))
	{
	    document.Form1.txtCostofVehicle.value = ""
	}
	else
	{
	    viInterestRate = document.Form1.txtInterestRate1.value / 1200
	    viDownPayment = parseFloat(0 + document.Form1.txtDownPayment1.value)
		var viMonthlyPayment = document.Form1.txtEffordableEMI.value;
		if(document.Form1.txtInterestRate1.value == 0)
		{
            viTotalVehicleCost = ( viMonthlyPayment * document.Form1.drpMonths1.value) + viDownPayment;
		}
		else
		{
		    viTotalVehicleCost = formatNumeric(viMonthlyPayment * ( ( 1 - ( 1 / Math.pow( 1 + viInterestRate, document.Form1.drpMonths1.value) ) ) / viInterestRate) + viDownPayment)
        }		    
		document.Form1.txtCostofVehicle.value = "$" + viTotalVehicleCost
	}
}

function formatNumeric( str ) 
{
    var fraction;
    numerals = new String(str);
    index = numerals.indexOf(".");
	if( index != -1 )
	{
		fraction = numerals.substring( index, index+3 );
		numerals = numerals.substring( 0, index );
	}
    ln = numerals.length;
    beg = numerals.substring( 0, ln-3 );
    end = numerals.substring( ln-3 );
    retVal=beg+((ln>3)?",":"")+end+((fraction==null)?".00":fraction);
    return retVal;
}


function insertAtCaret(areaId,text) 
{
	var txtarea = document.getElementById(areaId);
	var scrollPos = txtarea.scrollTop;
	var strPos = 0;
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? 
		"ff" : (document.selection ? "ie" : false ) );
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.innerHTML.length);
		strPos = range.text.length;
	}
	else if (br == "ff") strPos = txtarea.selectionStart;
	
	var front = (txtarea.innerHTML).substring(0,strPos);  
	var back = (txtarea.innerHTML).substring(strPos,txtarea.innerHTML.length); 
	txtarea.innerHTML=front+text+back;
	strPos = strPos + text.length;
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.innerHTML.length);
		range.moveStart ('character', strPos);
		range.moveEnd ('character', 0);
		range.select();
	}
	else if (br == "ff") {
		txtarea.selectionStart = strPos;
		txtarea.selectionEnd = strPos;
		txtarea.focus();
	}
	txtarea.scrollTop = scrollPos;
}

function DisplayPhotoList(psPhotoId, psPhotos, piCol, pbShowRemove)
{
	var vsPhotos = psPhotos

	var vaPhotos = vsPhotos.split("|")
	
	var vsPhotoTables = "<table cellpadding=2 cellspacing=2 border=0>"
	var viPhotosCount = 0
	if(vsPhotos.length > 0)
	{
		viPhotosCount = vaPhotos.length-1;
	}
	
	vsPhotos = ""
	for(viPhotoCnt=0; viPhotoCnt < viPhotosCount; viPhotoCnt++)
	{
		vsPhotoTables = vsPhotoTables + "<tr>"	
		for(viPhotocol=0; viPhotocol < piCol; viPhotocol ++)
		{
			if(viPhotoCnt < viPhotosCount)
			{
				if(vaPhotos[viPhotoCnt] != "")
				{
				    vaId_Photos = vaPhotos[viPhotoCnt].split(",")
				    if(vaId_Photos[0] == psPhotoId)
				    {
					    vsPhotoTables = vsPhotoTables + "<td align=center class=clsPhotoListBorder>"	
					    vsPhotoTables = vsPhotoTables + "<img src='" + vaId_Photos[1] + "' height=55 width=100>"	
					    if(pbShowRemove)
					    {
					        vsPhotoTables = vsPhotoTables + "<br><span height=30><a href='#' onclick=removeImage('" + vaId_Photos[0] + "','" + vaId_Photos[1] + "','" + vaId_Photos[2] + "'); style='font-size:11px;color:#000000;'><u>remove</u></a></span>"
					    }
					    vsPhotoTables = vsPhotoTables + "</td>"	
    					
					    vsPhotos = vsPhotos + vaId_Photos[1] + "|"
					}
					else
					{
					    viPhotocol--;
					}
				    viPhotoCnt++;
				}
			}
		}
		viPhotoCnt--;
		vsPhotoTables = vsPhotoTables + "</tr>"	
	}
	vsPhotoTables = vsPhotoTables + "</table>"	
	return vsPhotoTables
	//document.getElementById("divPhotoList").innerHTML = vsPhotoTables
}



//history.go(1);
//window.title="fsdfsd"

function checkValueTable(ptblChk)
{
		var vbCheck = false;
		for(i=0;i<ptblChk.rows.length;i++)
		{
				if(ptblChk.rows[i].cells[0].childNodes[0].checked)
						{vbCheck=true}
		}
		return vbCheck
}

function checkValue(strObject)
{
	for(i=0;i<document.Form1.elements.length;i++)
	{
		objName = String(document.Form1.elements(i).name)
		if(objName.indexOf(strObject) >= 0)	
		{
			if(isEmpty(document.Form1.elements(i).value))
			{
				document.Form1.elements(i).focus()
				return true
			}
			else
			{
				return false
			}
			break;
		}
	}
}

function isEmpty(strValue)
{
	var strNew;
	strNew=''
	for(intC=0;intC<=strValue.length-1;intC++)
	{
		if(strValue.substring(intC,intC+1) != " ")
		{
			return false
			break;
		}
	}
	return true
}

var whitespace = " \t\n\r";		
function isWhitespace(s)
{   var i;
	//if (isEmpty(s)) return true;
	var s = s.toString();
	if(Number(s)==0)
	{
		return true
	}
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isNumeric(s)
{
	if (typeof(s)=='undefined') return false;

	s = s.toString();
	
	if (arguments.length > 1 && s.length <=0) return false;
	
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (!(c==',' || c=='.') && !isDigit(c)) return false;
	}

	return true;
}

function kPress(strVal,poText)
{
	if(strVal=="TITLE")		//Capital Alpha Numeric
	{
		if(event.keyCode == 58)
			{event.keyCode=0}
		if(poText.value.length == 0)
		{
			if(event.keyCode >= 97 && event.keyCode <= 122)
				{event.keyCode = event.keyCode - 32}
		}
		if(event.keyCode==39 || event.keyCode < 65 || event.keyCode > 122 || (event.keyCode > 91 && event.keyCode < 97))
		{
			if(event.keyCode >=65 && event.keyCode <=97 || event.keyCode > 58)
				{event.keyCode=0}
		}
	}
	if(strVal=="CAN")		//Capital Alpha Numeric
	{
		
		if(event.keyCode == 58)
			{event.keyCode=0}
		if(event.keyCode >= 97 && event.keyCode <= 122)
			{event.keyCode = event.keyCode - 32}
		if(event.keyCode==39 || event.keyCode < 65 || event.keyCode > 122 || (event.keyCode > 91 && event.keyCode < 97))
		{
			if(event.keyCode >=65 && event.keyCode <=97 || event.keyCode > 58 || event.keyCode == 32)
				{event.keyCode=0}
		}
	}
	if(strVal=="AN")		//Alpha Numeric
	{
		if(event.keyCode == 58)
			{event.keyCode=0}
		if(event.keyCode==39 || event.keyCode < 65 || event.keyCode > 122 || (event.keyCode > 91 && event.keyCode < 97))
		{
			if(event.keyCode !=32 && event.keyCode !=46 && (event.keyCode < 47 || event.keyCode > 58))
				{event.keyCode=0}
		}
	}
	if(strVal=="NUM")		//Numeric
	{
		if(event.keyCode<48 || event.keyCode > 57)
		{
			event.keyCode=0
		}
	}
	if(strVal=="NUMD")		//Numeric
	{
		if(event.keyCode<48 || event.keyCode > 57)
		{
			if(event.keyCode!=46)
			{
				event.keyCode=0
			}
			
		}
	}
	if(strVal=="NOSPACE")		//No Space
	{
		if(event.keyCode == 32)
		{
			event.keyCode=0;
		}	
	}
	if (strVal=="")
	{
		if(event.keyCode<=47 || event.keyCode>=59)
		{event.keyCode=0;}	
	}
}

function myTime(objTime)
{
	s = new String(objTime.value)
	if(s.length==2)
	{
		objTime.value += ":"
	}
	if(s.length>1)
	{
		if(s.substring(2,3) != ":")
		{
			objTime.value = s.substring(0,2) + ":" + s.substring(2,4)
		}
	}	
}

function setTime(objTime)
{
	s = new String(objTime.value)
	
	if (parseInt(s) > 60)
	{
		alert("Time can not be greater than 60 Minutes.");
		return false;
	}
}
/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Below New Function.										   */
/*	Reason		:	Place Time In Correct Format.									   */
/*-------------------------------------------------------------------------------------*/
function fnFixedTime(objTime)
{
	s = new String(objTime.value);
	switch(parseInt(s.length))
	{
		case 1:
			objTime.value = "00:0" + s;
			break;
		case 2:
			objTime.value = "00:" + s;
			break;
		case 3:
			objTime.value = "00" + s;
			break;
		case 4:
			objTime.value = "0" + s;
			break;
	}
}
/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Above New Function.										   */
/*	Reason		:	Place Time In Correct Format.									   */
/*-------------------------------------------------------------------------------------*/

function fnMaxLength(poText,piLength)
{
	
	s = new String(poText.value)
	if(s.length>(piLength-1))
	{
		event.keyCode=0;
	}
}

function EnableDisable(poControl,pbEnable)
{
	if(pbEnable)
		{pbEnable=false}
	else
		{pbEnable=true}
	poControl.disabled = pbEnable
	if(pbEnable)
	{
		poControl.style.backgroundColor="#d9dad2"
	}
	else
	{
		poControl.style.backgroundColor="#ffffff"
	}
}

function ReadOnlyObject(poControl,pbEnable)
{
	/*if(pbEnable)
		{pbEnable=false}
	else
		{pbEnable=true}*/
	poControl.readOnly = pbEnable
	if(pbEnable)
	{
		poControl.style.backgroundColor="#d9dad2"
	}
	else
	{
		poControl.style.backgroundColor="#ffffff"
	}
}

function CloseMe()
{
	window.close();
}

/*function GoToPage(psPage)
{
	window.parent.location.href=psPage
}
*/

function TimeValid(poTime)
{
	var vsTime
	vsTime = poTime.value
	vsTime = vsTime.replace(":","")
	if(vsTime.length<4)
	{
		alert("Please enter Time in proper format")
		return false
	}
	if(vsTime.substring(0,2) <=0 && vsTime.substring(2,4) <=0)
	{
		alert("Please enter correct time")
		return false
	}
	if((vsTime.substring(0,2) >24 || vsTime.substring(0,2) <=0))
	{
		alert("Enter correct hh")
		return false
	}
	if(vsTime.substring(2,4) >60 || vsTime.substring(2,4) <0)
	{
		alert("Enter correct mm")
		return false
	}
	return true
}

function ChkValidation(psChk,psFormName)
{
	var vsName
	var vsChecked=false
	var voForm 
	if(typeof(psFormName)=="undefined")
	{
		psFormName="Form1"
	}
	voForm = eval("document." + psFormName)
	if(typeof(voForm.elements.length) == 'undefined')
	{
		return false
	}
	else
	{
		for(vicnt=0;vicnt<voForm.elements.length;vicnt++)
		{
			vsName = voForm.elements[vicnt].name
			if(vsName.indexOf(psChk)>=0)
			{
				if(voForm.elements[vicnt].checked)
				{
					vsChecked = true
					break;
				}
			}
		}
	}	
	return vsChecked
}

function CloseMe()
{
	window.close();
}

function RemoveMsg()
{
	document.all.lblerrmsg.innerText = ""
}

function ProcessingMsg()
{
	document.all.lblerrmsg.innerText = "Processing please wait....."
}

// Added by Ashwini 05-mar-04
function DateToStr(psdate)
{
  
	var vsdate 
	var vsdd 
	var vsmm 
	var vsyy 

	vsdd = psdate.substr(0,2)
	vsmm = psdate.substr(3,2)
	vsyy = psdate.substr(6,4)
	vsdate = vsyy + vsmm + vsdd
		
	return(vsdate)
}

function GetSysTodayDate()
{
	var vsCurrDate = new Date()
	var vsdate
	var vsmonth
	var vsyear
	
	vsdate = vsCurrDate.getDate()
	if(vsdate < 10)
		vsdate = "0" + vsdate
	vsmonth = vsCurrDate.getMonth() + 1
	if(vsmonth < 10)
		vsmonth = "0" + vsmonth
	vsyear = vsCurrDate.getFullYear()
	
	varReturn = vsmonth + "/" + vsdate + "/" + vsyear
	return varReturn
}


function GetSysTodayDate_MMDDYYYY()
{
	var vsCurrDate = new Date()
	var vsdate
	var vsmonth
	var vsyear
	
	vsdate = vsCurrDate.getDate()
	if(vsdate < 10)
		vsdate = "0" + vsdate
	vsmonth = vsCurrDate.getMonth() + 1
	if(vsmonth < 10)
		vsmonth = "0" + vsmonth
	vsyear = vsCurrDate.getFullYear()
	
	varReturn = vsmonth + "/" + vsdate + "/" + vsyear
	return varReturn
}

function GetBackDate_MMDDYYYY(psDays)
{
    var vsCurrDate = new Date()
    vsCurrDate.setDate(vsCurrDate.getDate()-psDays)

	var vsdate
	var vsmonth
	var vsyear
	
	vsdate = vsCurrDate.getDate()
	if(vsdate < 10)
		vsdate = "0" + vsdate
	vsmonth = vsCurrDate.getMonth() + 1
	if(vsmonth < 10)
		vsmonth = "0" + vsmonth
	vsyear = vsCurrDate.getFullYear()
	
	varReturn = vsmonth + "/" + vsdate + "/" + vsyear
	return varReturn
}

// Added by Ashwini 05-mar-04
function CheckDate(psfrom_dt,psto_dt)
{

	if (psfrom_dt > psto_dt)
	{
		alert('To date is less than from date. Please Check');
		return false;
	}
	else
	{
		return true;
	}
	
}


/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Below New Function.										   */
/*	Reason		:	To validate marks entry.										   */
/*-------------------------------------------------------------------------------------*/
function myMarks(objMarks)
{
	s = new String(objMarks.value)
	if (s.length==1)
	{
		if (s.substring(0, 1)==".")
		{
			if(event.keyCode==46){ event.keyCode = 0;}	
		}
	}
	if (s.length==2)
	{
		if (s.substring(0, 1)=="." || s.substring(1, 2)==".")
		{
			if(event.keyCode==46){ event.keyCode = 0; }
		}
		else
		{
			if (s.substring(0, 1)!="." || s.substring(1, 2)!=".")
			{ 
				if(event.keyCode==46){ event.keyCode = 0; }
				objMarks.value += "." 
			}
		}
	}
	if(s.length==3)
	{
		if (s.substring(0, 1)==".")
		{ event.keyCode =0; }
		if(s.substring(1, 2)=="." || s.substring(2, 3)==".")
		{
			if(event.keyCode==46){ event.keyCode = 0; }
		}
	}
	if(s.length==4)
	{
		if (s.substring(1, 2)==".")
		{ event.keyCode =0; }
		if(s.substring(2, 3)==".")
		{
			if(event.keyCode==46){ event.keyCode = 0; }
		}
	}
	if(s.length==5)
	{
		if(s.indexOf(".")>0)
		{
			if(event.keyCode==46){ event.keyCode = 0; }
		}
	}
}

/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Above New Function.										   */
/*-------------------------------------------------------------------------------------*/



/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Below New Function.										   */
/*-------------------------------------------------------------------------------------*/
function fnSetMarks(objMarks)
{
	s = new String(objMarks.value);

	if(s.length==5)
	{
		if(s.indexOf(".")<0)
		{
			objMarks.value = s.substring(0, 2) + "." + s.substring(3, 5);
		}
	}	
}

/*-------------------------------------------------------------------------------------*/
/*	End Block	:	Added Above New Function.										   */
/*-------------------------------------------------------------------------------------*/





/*-------------------------------------------------------------------------------------*/
/* Start Block	: Newly Added Function.												   */
/* Reason		: To return Month No												   */
/*-------------------------------------------------------------------------------------*/
function GetMonthNo(Mon)
		{
			Mon = Mon.toLowerCase()
			var MonthNo;
			if (Mon=="jan" || Mon=="january") 
			{
				MonthNo="1"
			}
			if (Mon=="feb" || Mon=="february")
			{
				MonthNo="2"
			}
			if (Mon=="mar" || Mon=="march")
			{
				MonthNo="3"
			}
			if (Mon=="apr" || Mon=="april")
			{
				MonthNo="4"
			}
			if (Mon=="may" || Mon=="may")
			{
				MonthNo="5"
			}
			if (Mon=="jun" || Mon=="june")
			{
				MonthNo="6"
			}
			if (Mon=="jul" || Mon=="july")
			{
				MonthNo="7"
			}
			if (Mon=="aug" || Mon=="august")
			{
				MonthNo="8"
			}
			if (Mon=="sep" || Mon=="september")
			{
				MonthNo="9"
			}
			if (Mon=="oct" || Mon=="october")
			{
				MonthNo="10"
			}
			if (Mon=="nov" || Mon=="november")
			{
				MonthNo="11"
			}
			if (Mon=="dec" || Mon=="december")
			{
				MonthNo="12"
			}
			
			return MonthNo
		}
/*-------------------------------------------------------------------------------------*/
/* End Block	: Newly Added Function.												   */
/*-------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------*/
/* Start Block	: Newly Added Function.												   */
/* Reason		: To check proper Date Format										   */
/*-------------------------------------------------------------------------------------*/
	function fnCheckDate(objStDate, objEndDate)
		{
			var Str_StartDate = new String(objStDate.value);
			var Str_EndDate = new String(objEndDate.value);
			var Str_Date = new Date();
						
			if (Str_StartDate.length == 0 || Str_EndDate.length == 0)
			{
				alert('Please Select Date.');
				return false;
			}
			else if (Str_StartDate.length == 0 && Str_EndDate.length != 0)
			{
				alert('Please Select From Date.');
				return false;
			}
			else if (Str_StartDate.length != 0 && Str_EndDate.length == 0)
			{
				alert('Please Select To Date.');
				return false;
			}
			else if (Str_StartDate.length != 0 && Str_EndDate.length != 0)
			{
				var dt_StartDate = new Date(Str_StartDate.substr(7,4), GetMonthNo(Str_StartDate.substr(3,3)) - 1 , Str_StartDate.substr(0,2), 0, 0, 0);
				var dt_EndDate = new Date(Str_EndDate.substr(7,4), GetMonthNo(Str_EndDate.substr(3,3)) - 1 , Str_EndDate.substr(0,2), 0, 0, 0);
				if (dt_StartDate > dt_EndDate)
					{
						alert('Please Select From Date Less Than To Date.');
						return false;
					}
					else
					{
						return true;
					}
			}
			
		}


/*-------------------------------------------------------------------------------------*/
/* End Block	: Newly Added Function.												   */
/*-------------------------------------------------------------------------------------*/


/********************************Date Validation*////////////////

function GetDt(objDate)
{
	try
	{
		//var myObj = eval(thedate)
		if(objDate.disabled==false)	
		{
			//window.open ("../funclib/calendar.asp?objdt="+objDate.name,null,"height=170,width=270,resizable=no,status=no,toolbar=no,menubar=no,left=360,top=200");
			var vsDate = window.showModalDialog("../ClassLibrary/calendar.asp?objdt="+ objDate.name,"","center:1;dialogWidth:20;dialogHeight:13;help:no;resizable:yes;status:no;scroll:no;")

			if(typeof(vsDate) != "undefined")
			{
				objDate.value = vsDate
			}
		}
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function datecompare(frmdt,todt,poFocusOn,psMsg)
{
	if(dtos(frmdt.value) > dtos(todt.value))
	{
		if(typeof(psMsg)=="undefined")
		{
				alert("To date cannot be less then from date!")
		}
		else
		{
				alert(psMsg)
		}		
		if(typeof(poFocusOn)=="object")
		{
				poFocusOn.focus()
		}		
		return false
	}
}


function valdate(tgDate,nAllowFutDt)    //for validating date 
{
	try
	{
		if (tgDate.value.length < 10)
		{
			if (typeof(document.all.errmsg)!="undefined")
			{
				errormsg("Input Date in DD/MM/YYYY format")
			}
			else
			{
				alert("Input date in DD/MM/YYYY format");
			}	
			tgDate.select();
			tgDate.focus();
			return(false);
		}
		mon1=tgDate.value.substr(2,1);
		mon2=tgDate.value.substr(5,1);
		if( mon1 != "/" || mon2!= "/")
		{
			if (typeof(document.all.errmsg)!="undefined")
			{
				errormsg("Input Date in DD/MM/YYYY format")
			}
			else
			{
				alert("Input date in DD/MM/YYYY format");
			} 
			tgDate.select();
			tgDate.focus();
			return(false);
		}
		dd=tgDate.value.substr(0,2);
		mm=tgDate.value.substr(3,2);
		yy=tgDate.value.substr(6,4);
		chk=isNaN(dd);
		if ( isNaN(dd) || isNaN(mm) || isNaN(yy))
		{
			if (typeof(document.all.errmsg)!="undefined")
			{
				errormsg("Input Date in DD/MM/YYYY format")
			}
			else
			{
				alert("Input date in DD/MM/YYYY format");
			}
			tgDate.select();
			tgDate.focus();
			return(false);
		}
		if ((dd==0) || (dd > 31) || (mm==0)	|| (mm >12) ||(yy==0) || (yy <=1900))
		{
			if (typeof(document.all.errmsg)!="undefined")
			{
				errormsg("Invalid Date")
			}
			else
			{
				alert("Invalid Date");
			}	
			tgDate.select();
			tgDate.focus();
			return(false);
		}
		if (mm==2)
		{
			nleap= yy % 4 ;
			if (nleap!=0 && dd>28)
			{
			if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Invalid Date")
				}
				else
				{
					alert("Invalid Date");
				}	
				tgDate.select();  
				tgDate.focus();
				return(false); 
			}
			else if (dd>29)
			{
			if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Invalid Date")
				}
				else
				{
					alert("Invalid Date");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			} 
		}
		else if (mm==4 || mm==6 || mm==9 || mm==11)
		{
			if (dd>30) 
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Invalid Date")
				}
				else
				{
					alert("Invalid Date");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
		}
		if (nAllowFutDt==0)   // not allowing future date
		{
			today = new Date();
			td = today.getDate();
			mth = today.getMonth();
			yr = today.getYear();
			mth++;
			if (yy>yr)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Future Year")
				}
				else
				{
					alert("Future Year!");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
			else if ( yy==yr && mm>mth)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Future Month")
				}
				else
				{
					alert("Future Month!");
				}     
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
			else if ((yy==yr && mm==mth) && dd>td)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Future Date")
				}
				else
				{
					alert("Future Date!");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
		}

		if (nAllowFutDt==1)   // not allowing past date
		{
			today = new Date();
			td = today.getDate();
			mth = today.getMonth();
			yr = today.getYear();
			mth++;
			if (yy<yr)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{	
					errormsg("Past Date not Allowed!")
				}
				else
				{
					alert("Past Date not Allowed!");
				}	
				tgDate.select();
				tgDate.focus();
				return(false);
			}
			else if ( yy==yr && mm<mth)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Past Date not Allowed!")
				}
				else
				{
					alert("Past Date not Allowed!");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
			else if ((yy==yr && mm==mth) && dd<td)
			{
				if (typeof(document.all.errmsg)!="undefined")
				{
					errormsg("Past Date not Allowed !")
				}
				else
				{
					alert("Past Date not Allowed");
				}	
				tgDate.select();
				tgDate.focus();
				return(false); 
			}
		}
		return(true);
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function gtDay(strDate)
{
	try
	{
		var mydate = new String(strDate)
		return (mydate.substring(0,2))
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function gtMonth(strDate)
{
	try
	{	
		var mydate = new String(strDate)
		return (mydate.substring(5,3))
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function gtYear(strDate)
{
	try
	{
		var mydate = new String(strDate)
		return (mydate.substring(10,6))
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function dtos(strDate)
{
	try
	{
		var myDate=new String(strDate)
		if(myDate!="")
			{return (myDate.substring(10,6) + myDate.substring(5,3) + myDate.substring(0,2))}
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function stod(strDate)
{
	try
	{
		var myDate = new String(strDate)
		if(myDate!="")
			{return (myDate.substring(8,6) + "/" + myDate.substring(6,4) + "/" + myDate.substring(0,4))}
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}

function mydate(objdt)    // keyhandler for date text box
{
	try
	{
		var aday = new Array(0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		var yr=gtYear(objdt.value);
		var lp= yr % 4;
		if(lp==0)
			{aday[2]=29}
		if (event.keyCode==43)      //+ key
		{
			if (objdt.value!=='')
			{
				if (valdate(objdt,2)==true)
				{
					nmonth= new Number(gtMonth(objdt.value));
					nday= new Number(gtDay(objdt.value));
					nyear= new Number(gtYear(objdt.value));
					if (nday+1>aday[nmonth])
					{
						if (nmonth==12)
						{
							nyear=nyear+1
							newdate='01' +'/01/'+nyear
						}
						else
						{
							newdate='01' +'/'+ lpad(nmonth+1,2,'0') +'/'+nyear
						}
					}
					else
					{
						newdate=lpad(nday+1,2,'0') +'/'+lpad(nmonth,2,'0')+'/'+nyear;
					}
					objdt.value=newdate;
					return
				}
			}
			else
			{
				var today
				today = new Date();
				newdate = lpad(today.getDate(),2,"0") + "/";
				newdate += lpad(today.getMonth() + 1,2,"0") + "/";
				newdate += today.getFullYear();
				objdt.value=newdate;
			}
			event.keyCode=0
		}
		else if (event.keyCode==45)  // - key
		{
			if (objdt.value!=='')
			{
				if (valdate(objdt,2)==true)
				{
					nmonth= new Number(gtMonth(objdt.value));
					nday= new Number(gtDay(objdt.value));
					nyear= new Number(gtYear(objdt.value));
					if (nday==1)
					{
						if (nmonth==1)
						{
							nyear=nyear-1
							newdate='31' +'/12/'+nyear
						}
						else
						{
							newdate='01' +'/'+ lpad(nmonth-1,2,'0') +'/'+nyear
						}
					}
					else
					{
						newdate=lpad(nday-1,2,'0') +'/'+lpad(nmonth,2,'0')+'/'+nyear;
					}
					objdt.value=newdate;
					return
				}
			}
			else
			{
				var today
				today = new Date();
				newdate = lpad(today.getDate(),2,"0") + "/";
				newdate += lpad(today.getMonth() + 1,2,"0") + "/";
				newdate += today.getFullYear();
				objdt.value=newdate;
			}
			event.keyCode=0
		}
		if((event.keyCode!=13 && event.keyCode!=27) && event.keyCode<=47 || event.keyCode>=59)
		{
			event.keyCode=0
		}
		s = new String(objdt.value);
		if (s.length==2 || s.length==5)
		{
			objdt.value = objdt.value + "/"
		}
	}
	catch(e)
	{
		return false
	}
}

function rpad(strValue,nLength,strStuff)
{
	try
	{
		var mystring = new String(strValue)
		var newstring=''
		mystring=mystring.replace('  ',' ')
		nLength=nLength-mystring.length+1
		for(i=1;i<nLength;i++)
			{newstring= newstring+strStuff}
		return (strValue+newstring)
	}
	catch(e)
	{
		alert(e.description)
		return false
	}
}


//------------------------------------------------------------------------------------------------------------------------------------------------ //
// Function Name	: chkValidEntry()
// Input Parameter	: 1. objChkCtrlIn  => Control To Check Duplicate Entry In.
//					  2. objChkCtrlVal => Value To Check Duplicate Entry.(Array) 
//					  3. vsOperator	   => Comparision Operator.
// Purpose			: Check For No Duplicate Entry. 
// Created By		: Paresh.																														
// Created On		: 6-Jul-2004
// Modified By		: --
// Modified On		: --
// Reason			: --
// Changes			: --
//------------------------------------------------------------------------------------------------------------------------------------------------ //
function chkValidEntry(objChkCtrlIn, objChkCtrlVal, vsOperator)
{
	// Define & Initialize Variable.
	var ChkCtrlVal = '';
	var vOperator = '';
	var vsMsg = '';
	// Loop For Control To Check.
	for (viCtr = 2; viCtr <= objChkCtrlIn.rows.length; viCtr++)
	{
		ChkCtrlVal = '';
		vOperator = '';
		vsMsg = '';
		// Loop For Value To Check.
		for (viCnt = 0; viCnt<=objChkCtrlVal.length-1; viCnt++)
		{
			var viTmp = viCtr-1;
			var viTmpCnt = viCnt + 1;
			ChkCtrlVal = ChkCtrlVal + vOperator + "objChkCtrlIn.rows[" + viTmp + "].cells[" + viTmpCnt + "].innerText == objChkCtrlVal[" + viCnt + "]";
			switch (vsOperator)
			{
				case 'AND':
					vOperator = ' && ';
					break;
				case 'OR':
					vOperator = ' || ';
					break;
			}
			if (viCnt == 0)
			{
				vsMsg = vsMsg + objChkCtrlVal[viCnt];
			}
			else
			{
				vsMsg = vsMsg + " " + vsOperator + " " + objChkCtrlVal[viCnt];
			}
		}
		
		if (eval(ChkCtrlVal))
		{
			alert ("Defination For " + vsMsg + " Is Already Done.");
			window.event.returnValue = false;
			break;
		}
	}					
}

	function lpad(strValue,nLength,strStuff)
	{
		try
		{
			var mystring = new String(strValue)
			var newstring=''
			mystring=mystring.replace('  ',' ')
			nLength=nLength-mystring.length+1
			for(i=1;i<nLength;i++)
				{newstring= newstring+strStuff}
			return (newstring+strValue)
		}
		catch(e)
		{
			alert(e.description)
			return false
		}
	}

	function rpad(strValue,nLength,strStuff)
	{
		try
		{
			var mystring = new String(strValue)
			var newstring=''
			mystring=mystring.replace('  ',' ')
			nLength=nLength-mystring.length+1
			for(i=1;i<nLength;i++)
				{newstring= newstring+strStuff}
			return (strValue+newstring)
		}
		catch(e)
		{
			alert(e.description)
			return false
		}
	}

//------------------------------------------------------------------------------------------------------------------------------------------------ //
// Function End.
//------------------------------------------------------------------------------------------------------------------------------------------------ //			

	function CheckDecimalValue(objCtrl)
	{
		vsCtlValue = new String(objCtrl.value)
				
		/*// If Entered Value Is Start With Decimal Then Don't Allow To Again Put Decimal.
		if (vsCtlValue.length==1)
		{
			if (vsCtlValue.substring(0, 1)==".")
			{
				if(event.keyCode==46){ event.keyCode = 0;}	
			}
		}*/
		ChkDecimalPosition(vsCtlValue, 2)
	}
	
	function ChkDecimalValue(objCtrl, viMaxLength, viPrecision, viScale)
	{
		vsCtlValue = new String(objCtrl.value);
		
		// Check If Any Decimal Present Or Not.
		
		if (event.keyCode == 46)
		{
			alert(vsCtlValue.length)
		}
		
		
		//alert(vsCtlValue.length);
		/*if(vsCtlValue.length > viPrecision && vsCtlValue.length < viPrecision + 1)
		{
			//alert(event.keyCode);
			if (event.keyCode != 46)
			{
				event.keyCode = 0;
			}
		}*/
	}
	
	
		
	function ChkAfterDecimalValue(vsValue, viMaxAllow)
	{
	// Check Any Decimal Position In A Supplied Value.
		if (vsValue.indexOf(".") >= 0)
		{
		    if(event.keyCode==46){ event.keyCode = 0;}
			// If Found Then Allow Only 2 Digits After Decimal.
			var vsAfterDecimalVal = vsValue.substr(vsValue.indexOf(".")+1, vsValue.length);
			if (vsAfterDecimalVal.length > viMaxAllow - 1)
			{
				event.keyCode = 0;
			}
		}
	}	
	
	function OpenReport(psReportName)
	{
		var nHeight = screen.availHeight-50
		var nWidth = screen.availWidth-10
		
		var vsReportName = new String(psReportName)
		if(vsReportName.indexOf("?") > 0)
		{
			var vsRpt_Name = vsReportName.substring(0, vsReportName.indexOf("?"));
			var vsQry_Str = vsReportName.substring(vsReportName.indexOf("?")+1, vsReportName.length);
			window.open("../Reports/frm_R_Frame.aspx?ReportName=" + vsRpt_Name + "&QryStr=" + vsQry_Str,"","height=" + nHeight + ",width=" + nWidth + ",left=0,top=0,status=yes")
		}
		else
		{
			window.open("../Reports/frm_R_Frame.aspx?ReportName=" + psReportName,"","height=" + nHeight + ",width=" + nWidth + ",left=0,top=0,status=yes")
		}
		
			
		//window.open("frm_R_Frame.aspx?ReportName=" + psReportName ,"","height=" + nHeight + ",width=" + nWidth + ",left=0,top=0,status=yes")
	}


	function ShowHelpWindow(psModule, psId, piIdCol, psName, piNameCol, psRetFocus, psSearch, psLoadList, psHeading,psSubmit)
	{
		if(typeof(psSubmit)=="undefined")
				{psSubmit=""}
		var vsQuryString = "qsModule=" + psModule + "&ctrl_Name=" + psId + "$" + piIdCol + "&ctrl_Name=" + psName + "$" + piNameCol + "&ret_Focus=" + psRetFocus + "&qsSearch=" + psSearch + "&qsLoadList=" + psLoadList + "&qsHead=" + psHeading + "&qsSubmit=" + psSubmit
		window.open("../Controls/frm_SearchList.aspx?" + vsQuryString, "PopUpWindow", "left=10,top=150,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=770");
	}


function GetSysTodayDate_DMYYY_NoZero()
{
	var vsCurrDate = new Date()
	var vsdate
	var vsmonth
	var vsyear
	
	vsdate = vsCurrDate.getDate()
	vsmonth = vsCurrDate.getMonth() + 1
	vsyear = vsCurrDate.getFullYear()
	
	varReturn =  vsmonth + "/" + vsdate  + "/" + vsyear
	return varReturn
}

function mOver(poObj)
{
    poObj.style.cursor='hand'
}


function onMOver(obj, psClassName)
{
    obj.className = psClassName         //"clsHomeListingHOver"
    obj.style.cursor = "pointer"
    obj.style.cursor = "hand"
}

function onMOut(obj, psClassName)
{
    obj.className = psClassName         //"clsHomeListingOut"
}

function GoToWebPage(psWebPageName, nOpt)
{
    window.location.href = psWebPageName
}

function RemovePageNoCookie()
{
	eraseCookie("cookie_Auto_PageNo")
	eraseCookie("cookie_Product_PageNo")
	eraseCookie("cookie_RealEstate_PageNo")
}
