//for select and copy
function copy_select(field_val)
{
//var isOpera = navigator.userAgent.indexOf(“Opera”) > -1;
//var isIE = navigator.userAgent.indexOf(“MSIE”) > 1 && !isOpera;
//var isMoz = navigator.userAgent.indexOf(“Mozilla/5.”) == 0 && !isOpera;

var tempval=eval("document."+field_val);
tempval.focus();
tempval.select();
//user_pref("clipboard.autocopy", true);
therange=tempval.createTextRange();
//therange=tempval.setSelectionRange("0",100");
therange.execCommand("Copy");
}


// Set Focus on Control
function SetFocus(obj)
{
		obj.focus();
}

// To Check the Control's Blank Value 
function IsBlank(obj,msg)
{
		if(Trim(obj.value) == "")
		{
			alert(msg);
			obj.focus();
			return false;
		}
		return true;
}

function IsHeight(obj,msg)
{
		if(Trim(obj.value) == "")
		{
			alert(msg);
			obj.focus();
			return false;
		}
		return true;
}
// To Validate the Email
function IsEmail(obj, msgstr)
{
	if(Trim(obj.value) == "")
	{
		alert(msgstr);
		obj.focus();
		return false;
	}
	else
	{
	    if(obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    	    return true;
	    else
		{
			alert(msgstr);
			obj.focus();
    	    return false;
		}
	}
}

// Height Function
function IsHeight(obj, msgstr)
{
	if(Trim(obj.value) == "")
	{
		alert(msgstr);
		obj.focus();
		return false;
	}
	else
	{
	    if(obj.value.search(/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/) != -1)
    	    return true;
	    else
		{
			alert("Invalid Height!  Please input Like: 23.3");
			obj.focus();
    	    return false;
		}
	}
}

// Weight Function
function IsWeight(obj, msgstr)
{
	if(Trim(obj.value) == "")
	{
		alert(msgstr);
		obj.focus();
		return false;
	}
	else
	{
	    if(obj.value.search(/^\d+$/) != -1)
    	    return true;
	    else
		{
			alert("Invalid Weight!  Please input Like: 12");
			obj.focus();
    	    return false;
		}
	}
}

//profile birthdate validation
function Profile_Birthdate() {
		var myDayStr = document.frmuserprofile.bDay.value;
		var myMonthStr = document.frmuserprofile.bMonth.value;
		var myYearStr = document.frmuserprofile.bYear.value;
		var myMonth = new Array('Month','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 
		var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
		
		var myDate = new Date();
		myDate.setFullYear( myYearStr, myMonthStr-1, myDayStr );
		if ( myDate.getMonth()!= myMonthStr  ) {
		 // alert( ' "' + myDateStr + '" IS a valid date.' );
		 return true;
		} 
		else {
		  alert( ' "' + myDateStr + '" is NOT a valid date.' );
		return false;
		}
}

// Trim Function
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}

// Right Trim Function
function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;

	}
	return strTemp;
}

//Right Trim Function
function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}
//dev by om
function age_limit(form_name)
{

var lowlimit = new Date();
	lowlimit.setYear(lowlimit.getYear()-14);
		// the + 1 below is because js months are indexed from zero
		if(form_name=="frmregister")
		{
			var enteredAge = new Date(document.frmregister.bYear.value, (document.frmregister.bMonth.value - 1) , document.frmregister.bDay.value);
		}
		else// if(form_name=="frmuserprofile")
		{
			
			var enteredAge = new Date(document.frmuserprofile.bYear.value, (document.frmuserprofile.bMonth.value - 1) , document.frmuserprofile.bDay.value);
		}// Birthday date must be entered

		if(form_name=="frmregister")
			{
			with (document.frmregister)
				{
					if (!bYear.value|!bDay.value|!bMonth.selectedIndex) 
					{
						alert ("Please enter a valid date for your birthdate.");
						return false;
					}
				}

			}
		else //if(form_name=="frmuserprofile")
			{	
			with (document.frmuserprofile)
				{
					if (!bYear.value|!bDay.value|!bMonth.selectedIndex) 
						{
							alert ("Please enter a valid date for your birthdate.");
							return false;
						}
				}
			}
		if (enteredAge > lowlimit)
			{
				alert ("You must be 14 or older to use this site.");
				return false;
			}

	return true;
}
//dev end

// Select & Unselect All Check box of Form
//Check Individual Checkbox
function selectUnselect(obj)
{
	var chkLength = obj.elements.length;
	var flag = true;
	for(i=0; i<chkLength; i++)
	{
		if(obj.elements[i].type == 'checkbox')
		{
			if(!obj.elements[i].checked && obj.elements[i].name != 'chkSelectAll')
				flag = false;
		}
	}
	obj.chkSelectAll.checked = flag;
}

//Check Select All
function selectAll(obj)
{
	var chkLength = obj.elements.length;
	for(i=0; i<chkLength; i++)
	{
		if(obj.elements[i].type == 'checkbox')
		{
			if(obj.chkSelectAll.checked)
				obj.elements[i].checked = true;
			else
				obj.elements[i].checked = false;
		}
	}
}

// Delete Entry
function DeleteEntry(obj,delid)
{
	if(!confirm('Are you sure you want to delete this record'))
		return false;
	obj.DelId.value = delid;
	obj.submit();
	return true;
}


// DeleteSelected  Entry
function DeleteSelectedEntry(obj,action,del)
{
	if(!Checkselection(obj))
	{
		if(action == "photo")
			alert('Por favor selecciona al menos una foto');
		else if(action == "video")
			alert('Por favor selecciona al menos un Video');
		else if(action == "mail")
			alert('Por favor selecciona al menos un Mail');
		return false;
	}
	if(del == 'delete')
	{
		try
		{
		if(!confirm(obj.sure_delete.value))
			return false;
		}
		catch(e)
		{
			if(!confirm('Estás seguro de que quieres borrar?'))
			return false;
		}
	}
	if(action != '')
	{
	if (action=="photo" || action=="video")
	{
		obj.del_sel.value = del;
		obj.submit();
	}
	else
	{
		obj.del_sel.value = del;
		//obj.action = action;
		obj.submit();
		
	}
		
	}
	else
	{

		obj.del_sel.value = del;
		obj.submit();
	}
	return true;
}

function DeleteSelectedVideos(obj,msjError,msjSure)
{
	if(!Checkselection(obj))
	{
		alert(msjError);
		return false;
	}
	if(!confirm(msjSure))
			return false;
	obj.del_sel.value = 'delete';
	obj.submit();
	return true;
}

//Check before Delete Entry
function Checkselection(obj)
{
	var chkLength = obj.elements.length;
	var flag = false;
	for(i=0; i<chkLength; i++)
	{
		if(obj.elements[i].type == 'checkbox')
		{
			if(obj.elements[i].checked)
				flag = true;
		}
	}
	return flag;
}

// Read Mail
function ReadMail(obj,mailid)
{
	
	obj.hidMailId.value = mailid;
	obj.action = 'read_mail.php';
	obj.submit();
}
//Register Birthdate Validator
function Birthdate() {
			var myDayStr = document.frmregister.bDay.value;
			var myMonthStr = document.frmregister.bMonth.value;
			var myYearStr = document.frmregister.bYear.value;
			var myMonth = new Array('Month','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 
			var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
			
			var myDate = new Date();
			myDate.setFullYear( myYearStr, myMonthStr-1, myDayStr );
			if ( myDate.getMonth()!= myMonthStr  )
			{
			 // alert( ' "' + myDateStr + '" IS a valid date.' );
			} 
			else {
			  alert( ' "' + myDateStr + '" is NOT a valid date.' );
			  return false;
			}
			return true;
}

function URLEncode(urlToEncode)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = urlToEncode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}

function URLDecode(urlToDecode)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = urlToDecode
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}