var newwin;

function launchwin(winurl,winname,winfeatures) {
    newwin = window.open(winurl,winname,winfeatures);
}

function jumpNow(theForm) {
                theForm.submit();
                return (true);
}

function checkLength(maxlen, inp, statusField){
    inp.onchange = inp.onkeyup;
    if (inp.value.length > maxlen) {
        statusField.value="Warning: " + (inp.value.length - maxlen) + " characters over the limit";
        return false;
    } 
    statusField.value= "" + (maxlen - inp.value.length) + " characters remaining";
    return true;
}

function insertText(textValue) {
    CKEDITOR.instances.content.insertText(textValue);
}

function dhtmlReplaceTextarea(fieldName, height, contextPath) {
    CKEDITOR.replace( fieldName,
        {
            toolbar : 'Basic'          
        });
}

function dhtmlReplaceHTMLTextarea(fieldName, height, contextPath) {
    CKEDITOR.replace( fieldName,
        {
            basicEntities  : 'false'
        });
}   

function detectBrowserForCKEditor()
{
   var browser=navigator.appName;
   if (browser=="Microsoft Internet Explorer")
   {
	alert("Internet Explorer is not compatible with using the CKEditor on adding or editing the news item on this page.\nPlease close the browser and add or edit the news item using Firefox or Safari.");
   }
}


function validateQuantity(quantity){	
   // Make sure that quantity is 10 or below
   if (quantity.value > 10) {
		alert('Maximum quantity is 10');
		quantity.value = 10;
		return false;
   }
   if (quantity.value < 1) {
		alert('Minimum quantity is 1');
		quantity.value = 0;
		return false;
   }

   return true;
}
	 

function validateAmount(amount){


    if(amount.value == null || amount.value.length == 0){
		alert("Please enter amount.\n\n");
	 	return false;
    }

    if (!/^[\d-'.']*$/.test(amount.value)) {
        alert('Only valid numbers allowed!');
		return false;
    }
    
    var tempValue =  parseFloat(amount.value);
    if (tempValue < 5) {
       alert("$5 is the minimum amount per donation.\n\n");
       return false;
   }
   if(tempValue > 60000){
   		alert('$60000 is the maximum amount per donation\n\n');
   		return false;
    }
   if(tempValue >0)
	   amount.value = tempValue.toFixed(2); 
	   
   return true;
}

function validateDate(year, month, day){
	var currentDate = new Date();
	var selectedDate = new Date(year, month, day);
	var days = Math.round((selectedDate.getTime() - currentDate.getTime())/(1000*60*60*24));
	if(days > 90){
		alert("Donation date can not be more than 90 days in the future");
		return false;
	}
	if(days < -1){
		alert("Donation date can not be in the past");
		return false;
	}
	return true;
}

