﻿
//Check if Longitude/Latitude cooridantes ex: 39.2356,-123.1354
function IsLatLong(strString)
{
   var strChar;
   var blnResult = true;
   var reg1 = new RegExp(/^([0-9\-]+)\.([0-9]*)(\,)([0-9\-]+)\.([0-9]*)$/);

   if (strString.length != 0) 
   {
        if (strString.match(reg1))
        {
            return true;
        }
        else
        {
            return false;
        }
   }
   else
   {
        return false;
   }
}

//extract left part of string
function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

//extract right part of string
function Right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

//Trim
function TrimString(sInString) {
    
    var strNew = sInString.replace( /0/g, "" );// strip leading

    if (strNew == "")
    {
        return "0";
    }
    else
    {
        return strNew;
    }
}

//Trim the leading zero's of a number
function TrimNumber(s) {
  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  if (s == "")
    {
        return "0";
    }
    else
    {
        return s;
    }
}

//get the pin ID from the string
function StripPinID(str)
{

    var spanStart = str.indexOf("<span");
    var spanEnd = str.indexOf("</span>");
    
    //Get the span tag containing the ID
    var strPinID = str.substring(spanStart, spanEnd + 7);
    
    //Remove the leading text from the pinID
    var strPinID = strPinID.replace(strPinID.substring(0, (strPinID.indexOf(">") + 1)), "");
    
    //Remove the trailing text from the pinID
    var pinID = strPinID.replace(strPinID.substring(strPinID.indexOf("<"), strPinID.length), "");
    
    return pinID;
}

//get the pin type from the string
function StripPinType(str)
{
    var spanStart = str.indexOf("<span");
    var spanEnd = str.indexOf("</span>");
    
    //remove the first span tag containing the pinID
    var strPinType = str.replace(str.substring(spanStart, spanEnd + 7), "");
    
    spanStart = strPinType.indexOf("<span");
    spanEnd = strPinType.indexOf("</span>");
    
    //Get the span tag containing the pin type
    strPinType = strPinType.substring(spanStart, spanEnd + 7);
    
    //Remove the leading text from the pin type
    var PinType = strPinType.replace(strPinType.substring(0, (strPinType.indexOf(">") + 1)), "");

    //Remove the trailing text from the pinID
    PinType = PinType.replace(PinType.substring(PinType.indexOf("<"), PinType.length), "");

    return PinType;
}

//check if value returned is null
function checkNull(value)
{
    if ((value == "") || (value == null))
    {
        return "";
    }
    else
    {
        return value;
    }
}

//check if value returned is null, if not return provided value
function checkEmptyReturnValue(value, returnValue) {

    if ((value == "") || (value == null))
    {
        return "";
    }
    else {
        return returnValue;
    }
    
}