//changes color property in styles of object
function changeColor(obj, newColor) {
	 obj.style.color = newColor;
}

//changes version details in text fields
function changeVersionDetails(versionId, versions) {
  //condition ( whether version is selected or not)
  if(versionId != "") {
    totalVersions = versions.length;
	currentVersion = "";
	tempVersion = "";

	//finding selected version
	for(i=0; i<totalVersions; i++) {
	  tempVersion = versions[i].version;
	  if(tempVersion.id == versionId) 
	     currentVersion = tempVersion;
	}
    
	//assigning values to different fields
	if(currentVersion != "") {
	  limitDailyField = document.getElementById('user_api_key_limit_daily');
	  limitMonthlyField = document.getElementById('user_api_key_limit_monthly');
	  priceField = document.getElementById('user_api_key_price');
	  validUptoField = document.getElementById('user_api_key_valid_upto');
	
	  if(limitDailyField != null) limitDailyField.value = currentVersion.limit_daily;  
	  if(limitMonthlyField != null) limitMonthlyField.value = currentVersion.limit_monthly;  
	  if(priceField != null) priceField.value = currentVersion.price;  
	  if(validUptoField != null) validUptoField.value = currentVersion.valid_upto;  
	}
  }
}

//convert dd-mm-yy format date to a number
function dateToNumber(strDate){
  strDate=strDate.split('-');
  strDate=strDate.join('/');
  return Date.parse(strDate);
}

//hides and shows text field value
function hideShowTextFieldValue(obj,defaultValue,event) {
	 if(event=="focus" && obj.value==defaultValue)  {
	 	obj.value = ""; 
	 }  else if(event=="blur" && obj.value=="")	
		obj.value = defaultValue;
}

//checks whether key is numeric key or dot key
function isNumericKeyOrDotKey(keyCode) {
  //if(keyCode<44 || keyCode>57 || keyCode==45 || keyCode==47)
  if((keyCode>=48 && keyCode<=57) || keyCode==46)
  	 return true;  
  else	 
     return false;     
}

//checks minMax values of particular attribute
function minMaxCheck(fieldObj,type) {
  fieldId = fieldObj.id
  fieldValue = fieldObj.value
  valueType = fieldId.substring(0,7); //gives first three characters in string  ( nbl_min or nbl_max )
  attributeName = fieldId.substring(8); //gives characters from index 4  ( attribute name)
 
  if(valueType == "nbl_min") {
  	 minValue = fieldObj.value;  //minimum value of attribute 
     //finding maximum value of attribute
     otherFieldId = "nbl_max_"+attributeName;
	 otherFieldObj = document.getElementById(otherFieldId);  
     maxValue = otherFieldObj.value;  
  } else if(valueType == "nbl_max") {
  	 maxValue = fieldObj.value;  //minimum value of attribute 
     //finding manimum value of attribute
     otherFieldId = "nbl_min_"+attributeName;
	 otherFieldObj = document.getElementById(otherFieldId);  
     minValue = otherFieldObj.value; 
  }
	  
  if(minValue == "" || maxValue == "") {
  	  fieldObj.style.borderColor = "";
	  otherFieldObj.style.borderColor = "";
  } else {
  	  if (type == "Number"){
	  	minValue = parseFloat(minValue);
        maxValue = parseFloat(maxValue);
	  }else if (type == "Date"){	  	
		minValue = dateToNumber(minValue);
		maxValue = dateToNumber(maxValue);		
	  }	  
	  if(minValue > maxValue) {
	  	fieldObj.style.borderColor = "red";
	    otherFieldObj.style.borderColor = "red";
	  }
	  else { 
	    fieldObj.style.borderColor = "";
	    otherFieldObj.style.borderColor = "";
	  }
  }  
}

//password assist path
function passwordAssistPath(emailFieldId, forgotPasswordLinkId, defaultEmail) {
  emailField = document.getElementById(emailFieldId);
  forgotPasswordLink = document.getElementById(forgotPasswordLinkId);
  
  if(emailField != null && forgotPasswordLink != null && emailField.value != defaultEmail) {
      forgotPasswordLink.href += "?email="+emailField.value;
  }  
}

//vertical scroll detector
//used for positioning the app-dev-vert image dynamically
function scrollingDetector()
{
	if (navigator.appName == "Microsoft Internet Explorer") {
		//topPosition = document.body.scrollTop;
		topPosition = document.documentElement.scrollTop;
		windowHeight = document.documentElement.clientHeight;
	}else{
		topPosition = window.pageYOffset;
		windowHeight = window.innerHeight;
	}
	//assigning default values
	if(typeof topPosition == 'undefined') topPosition = 0;
	if(typeof windowHeight == 'undefined') windowHeight = 600;
					
	//script for positioning the app-dev-vert image dynamically based vertical scroll bar
	appDevVertImage = document.getElementById('app-dev-vert-image');
	if(appDevVertImage != null) {
		appDevVertImage.style.top =  (topPosition+((windowHeight*2)/3)-50)+'px';
		appDevVertImage.style.display = 'inline';
	}
}

//onscroll event
//window.onscroll=scrollingDetector;

//hide and shows the object with effects
function toggleObject(objectId) {	
	object = document.getElementById(objectId); 
    $("#"+objectId).slideToggle("slow");
}

// removes leading and ending whitespaces
//function trim(value) {
//	return value.replace(/^\s+|\s+$/g, ''); 
//}








