
//global variables for error flag & error form element
var errfound = false;
var elemform;
var click_flag=false;

//function to validate by length
//it check if the element disabled
function ValidateLength(item, len)
{
	if (!item.disabled)
		return (item.value.length >= len);
	else
		return true;
}

//function to validate a number
function ValidatePositiveNumber(item)
{
	if (isNaN(item.value) || item.value == '')
		return false;
	else
		return(item.value >= 0);
} 

//function to validate by length (recomended)
function ValidLength(item, len) {
var chr;
if(item.length >= len){
for(var i=0;i< item.length;i++){ 
chr=item.charAt(i)
 	     if(chr!=" ") return true;
}	
	return false;
	}
else
	return false;
}

//function to validate max length
function ValidMaxLength(item, len)
{
 	return (item.length <= len);
}
//function to validate a realnumber
function ValidRealNumber(item)
{
var item1=item;
var chr=item1.charAt(0);
if(chr=="-" || chr=="+")
{
item1=item1.substring(1,item1.length-1);
}
//var pledgexp = /^\d*$|^\d*\.\d*$|^\d*\,\d*$|^\d*\.\d*\,\d*$|^\d*\,\d*\.\d*$/
var pledgexp = /^\d*$|^\d*\.\d*$|^\d*\,\d*$/

return pledgexp.test(item1);
} 

//function to validate a number
function ValidNumber(item)
{
return (!isNaN(item));
} 

//function to validate a postive number
function ValidpositiveNumber(item)
{
var pledgexp = /^\d*$/
return (!isNaN(item)) && pledgexp.test(item);
} 

// display an error alert text as parm & focus on the error element
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
click_flag=false;
}

function errorselect(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   //elem.select();
   elem.focus();
   errfound = true;

}
//function to validate a number with max & min value
//minval=0 & maxval=0 then no range 
function ValidNumberrange(item, minval, maxval) {
if(minval==0 && maxval==0)
 return ValidNumber(item)  
else
 return (ValidNumber(item) && item<=maxval && item>=minval)
}


function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consecutive spaces and replaces it with one space.
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



//function to validate an email address
function ValidEmail(src) {
 src =trim(src);
 var mycounter=0;   
 var mycounter1=0;  
     for(var i=0;i< src.length;i++){ 
 	     var chr=src.charAt(i)
 	     if(chr=="@") mycounter++;
 	     if(chr==" ")
 	     return false;
 	     }
 	     
 	  for(var i=0;i< (src.length)-1;i++){ 
 	     var chr=src.charAt(i)
 	      var nextchr=src.charAt(i+1)
 	     if(chr==".") mycounter1++; 
 	     if(chr=="." && nextchr==".")
 	     return false;
 	     }
 	     
 	 if(mycounter>1)  return false;       
     if(mycounter1<1)  return false;
     
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }

// to allow the good chars in the form
function checkForOutOfRangeChars_form(form,goodChars) {
	 for (var n=0;n < form.elements.length;n++) {
 	  var address=form.elements[n].value; 
 	  for(var i=0;i< address.length;i++){ 
 	     if(goodChars.indexOf(address.charAt(i))==-1){ 
	        elemform=form.elements[n];
			return true
} }} 
 return false
  }

// to allow the good chars in the element
function checkForOutOfRangeChars(elem,goodChars) {
 	  var address=elem.value; 
 	  for(var i=0;i< address.length;i++){ 
 	     if(goodChars.indexOf(address.charAt(i))==-1){ 
	        elemform=elem;
			return true
} } 
 return false
  }

// to check bad chars in the element
function checkForBadChars(elem,BadChars) {
 	  var address=elem.value; 
 	  for(var i=0;i< address.length;i++){ 
 	     if(BadChars.indexOf(address.charAt(i))!=-1){ 
	        elemform=elem;
			return true
} } 
 return false
  }
  
 function addToFavorite(url,title)
{
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4))
  {
    window.external.AddFavorite(url, title);
  }
}


function openClose(url)
{
	if (window.opener)
	{
		window.opener.location.href = url;
		window.close();
	}
	else
	{
		window.location.href = url;
	}
}


function openYuotube(url)
{
	//window.open(url,'QChatStandAlone','width=1100,height=900')
	
	window.open(url,'QChatStandAlone','width=1200,height=1000,scrollbars=1')

}



//Rezgar -Warning before delete
function confirm_entry_delete(path,msg1){

	if(confirm(msg1))
		{
		location = path;
		return location;
		}
}

