
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;
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function getregid(regidtemp){
  var beginnr =  regidtemp.indexOf('-');
  regid = regidtemp.substr(beginnr + 1,regidtemp.length);
  return regid;
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
function getWidthAndHeight(myImage,xxx,yyy,myimageid){
//   www = myImage.width;
//   hhh=myImage.height;
//     xratio =xxx/www  ;
//     yratio = yyy/hhh ;
//     finalratio = Math.min(xratio,yratio);
//     www1 = parseInt(finalratio*www);
//     hhh1 = parseInt(finalratio*hhh);
//     $(myimageid).width=www1;
//     $(myimageid).height=hhh1;
//      $(myimageid).setStyle({width: www1 , height: hhh1});
//     $(myimageid).setStyle({width: www1+'px'});
//     $(myimageid).setStyle({height: hhh1+'px'});
    return true;
}

function loadFailure(myImage,xxx,yyy){
     alert("'" + myImage.src + "' failed to load.");
    return true;
}

function getImageReSized( srcc,xxx,yyy,myimageid){
  var myImage = new Image();
   myImage.src = srcc;
//   myImage.onload = getWidthAndHeight(myImage,xxx,yyy,myimageid);
getWidthAndHeight(myImage,xxx,yyy,myimageid);
//   myImage.onerror = loadFailure(myImage,xxx,yyy);
//   alert(myImage.src+' = '+srcc);
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
// 			console.log('==='+value+'===');
 			   verifvalue = value.toString().slice(0,8);
// 			console.log('=|='+value+'-----=====>>>>>'+verifvalue+'=|=');
// 			  dumped_text +='XYXYXYXYXYXYXYX:'+ verifvalue + "\"\n"; 
  			if (verifvalue=='function'){
//   				dumped_text += level_padding + "XXXXXXXXX'" + item + "' => \"" + value + "\"\n";
        }else{
  				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
        }
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
