/** ------------------------------------------------------------------------------------------------------------- seek companion subroutines -- **/
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder)
{
	if (window.event&&event.srcElement.value.length>=maxlength) return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
	{
	var pressedkey=/[a-zA-Z0-9\.\,\/]/; //detect alphanumeric keys
	if (pressedkey.test(String.fromCharCode(e.which))) e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder)
{
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder))
	{
	if (lengthleft<0) theform.value=theform.value.substring(0,maxlength)
	placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(theform,thelimit)
{
	var limit_text='<span id="'+theform.toString()+'">'+thelimit+'</span> characters remaining.'
	if (document.all||ns6) document.write(limit_text)
	if (document.all)
	{
	eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
	eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6)
	{
	document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
	document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}

function chckName(str)
{
	if (str.length < 2) { return "The name must contain at least 2 characters."; }
	var illegalChars = /[^a-z\d ]/i; // allow only letters, numbers, spaces
	if ( illegalChars.test(str) ) { return "The name must contain only characters, numbers or spaces."; }
	return "NONE";
}

function chckEmail(str1,str2)
{
	// check if match
	if ( str1 != str2) { return "The email addresses do not match."; }

	var filter=/^.+@.+\..{2,3}$/;
	if (! filter.test(str1) ) return "The email address is invalid.";
	return "NONE";
}

function chckLCODE(str)
{
	// atleast 5 characters
	if (str.length < 5) return "The key lock must be at least 5 characters.";
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ( illegalChars.test(str) ) return "The key lock must contain only characters or numbers. (No spaces).";
	return "NONE";
}

function chckVCODE(str)
{
	// atleast 9 characters
	if (str.length < 9) return "The verification code must be at least 9 characters.";
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ( illegalChars.test(str) ) return "The verification code must contain only characters or numbers. (No spaces).";
	return "NONE";
}

function chckSCODE(str)
{
	// atleast 1 character
	if (str == '') return "Please pick a security photo. It will be used to get your password if you happen to forget it.";
	return "NONE";
}

function chckPassword(str1,str2)
{
	// check if match
	if ( str1 != str2) { return "The password does not match."; }
	// atleast 6 characters
	if (str1.length < 6) return "The password must be at least 6 characters.";
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ( illegalChars.test(str1) ) return "The password must contain only characters or numbers. (No spaces).";
	return "NONE";
}

function chckPhone(str)
{
	var stripped = strip(str);
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) { return "The number contains illegal characters."; }
	return "NONE";
}

function strip(str)
{
	return str.replace(/[\(\)\.\-\ ]/g, '');
}

function chckSreenName(str)
{
	// between 2 - 24 characters
	if (str.length < 2) return "The screen name must be at least 2 characters.";
	if (str.length > 24) return "The screen name must be less than 24 characters long.";
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ( illegalChars.test(str) ) return "The screen name must contain only characters or numbers. (No spaces)";
	return "NONE";
}

function chckURL(str) 
{
	filter = /^http(s?):\/\/([^$@\\ ]+)$/i; 
	//if (str.substring(0,7)!='http://') str='http://'+str;
	if ( !filter.test(str) ) return "The provided URL is invalid. Also, include the 'http://' prefix.";
	return "NONE";
}

function chckDateExp(str)
{
	// get month, day, year
	var year = str.substring(0,4);
	var month = str.substring(5,7);
	var day = str.substring(8,10);

	var now = new Date();
    var tripexp = new Date(parseInt(year,10),parseInt(month,10)-1,parseInt(day,10));

	if( now > tripexp ) { return "The trip seems to be expired."; }
	return "NONE";
}

function chckDates(str1,str2)
{
	// get month, day, year
	var year1 = str1.substring(0,4);
	var month1 = str1.substring(5,7);
	var day1 = str1.substring(8,10);

	var year2 = str2.substring(0,4);
	var month2 = str2.substring(5,7);
	var day2 = str2.substring(8,10);

    var date1 = new Date(parseInt(year1,10),parseInt(month1,10)-1,parseInt(day1,10));
    var date2 = new Date(parseInt(year2,10),parseInt(month2,10)-1,parseInt(day2,10));

	if( date1 > date2 ) { return "Unacceptable dates of travel."; }
	return "NONE";
}

function chckWordLenghtLimit(str,maxlength)
{
	var temp=str.split(/\s+/g);
	for (i=temp.length-1; i > -1; i--)
		if (temp[i].length>maxlength) return "The input contains at least one word that is too long.";
	return "NONE";
}

function chckButtons(btn) 
{
	for (i=btn.length-1; i > -1; i--) 
		if (btn[i].checked) return "NONE"
	return "ERROR";
}

function chckCurrency(str) 
{ 
	regexp = /^(([0-9]{1,3}(\,[0-9]{3})*)|([0-9]{0,3}))(\.[0-9]{2})?$/; 
	if (!regexp.test(str)) return "Please provide the amount you wish to pay in US dollars."
	return "NONE"; 
}














/*




function chckDate(str) 
{ 
	var dtArray = str.split('/'); 
	if (dtArray.length == 3) if (isDate(dtArray[0],dtArray[1],dtArray[2])) return "NONE";
	return "Invalid date provided.";
}

function isDate(m,d,y) 
{ 
	Months = "31/!/28/!/31/!/30/!/31/!/30/!/31/!/31/!/30/!/31/!/30/!/31"; 
	MonthArray = Months.split("/!/"); 
	if (isNaN(parseInt(m,10))) return false; 
	if (isNaN(parseInt(d,10))) return false; 
	if (isNaN(parseInt(y,10))) return false; 
	d = parseInt(d,10); 
	y = parseInt(y,10); 
	m = parseInt(m,10); 
	y = convertYear(y); 
	if (y <= 1900 ) return false; 
	if (m < 1 || m > 12 ) return false; 
	if ( isLeapYear(y)) MonthArray[1] = eval(eval(MonthArray[1]) + 1); 
	if (d<1 || MonthArray[m-1] < d ) return false; 
	
	return true; 
} 

function isLeapYear(Year) 
{ 
	if(Math.round(Year/4) == Year/4) if(Math.round(Year/100) == Year/100) if(Math.round(Year/400) == Year/400) return true; else return false; else return true; 
	return false; 
}

function convertYear(y) 
{ 
	var borderYEAR = 40; 
	yearvalue = parseInt(y,10); 
	if (isNaN(yearvalue)) return y; 
	if (yearvalue - borderYEAR <= 0) { yearvalue = yearvalue + 2000 } 
	else if (yearvalue - 100 < 0) { yearvalue = yearvalue + 1900 } 
	
	return yearvalue; 
} 
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////






function calculate()
{
	if (!document.fileSize)
	{
		alert('This script does not work in your browser.');
		return;
	}
	var size = (document.fileSize)*1;
	var y = document.images;
	var imglength = 0;
	for (i=0;i<y.length;i++)
	{
		imglength += (y[i].fileSize)*1;
	}
	var total = size + imglength;
	var writestring = 'File size HTML: ' + size;
	writestring += '\nFile size images: ' + imglength;
	writestring += '\nTotal file size: ' + total;
	if (total > 40000) writestring += "\nFile too large!";
	alert(writestring);
}

function imgLoad()
{
var strT = new String();
document.getElementById("ShowImg").innerHTML= "";
strT = document.pictureupload_form.pictureupload.value;
if(strT != "")
{
strT = "<img id='Sample' src='" + strT + "' width='100' height='100'></img>";
document.getElementById("ShowImg").innerHTML= strT;
if(!LimitedSize())
{
alert("File Size is more than 100 KB");
document.getElementById("ShowImg").innerHTML= "";
}
}
}

function LimitedSize()
{
var i;
var y = document.images;
for (i=0;i<y.length;i++)
{
if((y[i].id) == 'Sample')
{
if(y[i].fileSize > 102400)
return false;
}
}
return true;
}


function isCurrency(Field) 
{ 
	strValue = Field.value; 
	regexp = /^(([0-9]{1,3}(\,[0-9]{3})*)|([0-9]{0,3}))(\.[0-9]{2})?$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
}

function isFloat(Field) 
{ 
	strValue = Field.value; 
	regexp = /^(\+|\-)?([0-9]+)(((\.|\,)?([0-9]+))?)$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isInteger(Field) 
{ 
	strValue = getValue(Field); 
	regexp = /^(\+|\-)?([0-9]+)$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isUserName(Field) 
{ 
	strValue = getValue(Field); 
	regexp = /^([^$@\\ ]+)$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isCreditCardNumber(Field) 
{ 
	var iChkSum=0; 
	var ccnum = getValue(Field); 
	ccnum = ccnum.replace( /\D/g, "" ); // check for correct card number length 
	if (ccnum.length<13) return false; // make an array and fill it with the individual digits of the cc number 
	ccnumchk=new Array; 
	for (iLoop=0; iLoop < ccnum.length; iLoop++) 
	{ 
		ccnumchk[ccnum.length-1-iLoop] = ccnum.substring(iLoop, iLoop+1); 
	} 
	// perform the weird mathematical method (some base 10 stuff) to 
	// convert the number to a two digit number 
	// for those of you who aren't as familiar with the js operators 
	// i'll comment some of the math lines...well, really just one 
	var skemp=0; 
	for (iLoop=0; iLoop < ccnum.length; iLoop++) 
	{ 
		// if splits is an even number... 
		if (iLoop %2 != 0) 
		{ 
			ccnumchk[iLoop]=ccnumchk[iLoop]*2; 
			if (ccnumchk[iLoop] >= 10) ccnumchk[iLoop]=ccnumchk[iLoop]-9; 
		} 
		// switch ccnumchk[splits] to a number 
		ccnumchk[iLoop]++; 
		ccnumchk[iLoop]--; 
		iChkSum = iChkSum + ccnumchk[iLoop].valueOf(); 
	} 
	if (iChkSum%10 != 0) { return false; } 
	// The result isn't base 10 
	return true; 
} 

function isEmail(Field) 
{ 
	strValue = getValue(Field); 
	regexp = /^[A-Za-z0-9]+[A-Za-z0-9\_\-\.]*\@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,5}$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
}

function isURL(Field) 
{
	strValue = getValue(Field); 
	regexp = /^http(s?):\/\/([^$@\\ ]+)$/i; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isEmailList(Field) 
{ 
	strValue = getValue(Field); 
	// delete all spaces near comma 
	rexp = /, /gi; 
	strValue = strValue.replace(rexp, ','); 
	rexp = / ,/gi; 
	strValue = strValue.replace(rexp, ','); 
	strArray = strValue.split(","); 
	regexp = /^[A-Za-z0-9]+[A-Za-z0-9\_\-\.]*\@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,5}$/; 
	for (var i=0; i < strArray.length; i++) 
	{ 
		if (isEmpty(strArray[i])) return false; 
		if (!regexp.test(strArray[i])) return false; 
	} 
	// set new field value (with removed spaces between comma and addresses) 
	Field.value = strValue; 
	return true; 
} 

function isZip(Field) 
{ 
	strValue = getValue(Field); 
	if (isEmpty(strValue)) { return false; } 
	if (strValue.indexOf('-') >=0 ) { regexp = /^\d{5}-\d{4}$/; } 
	else { regexp = /^\d{5}$/; } 
	return regexp.test(strValue); 
} 

function isPhone(Field) 
{ 
	strValue = getValue(Field); 
	regexp = /^1{0,1} *(-| ){0,1} *[\(]*[0-9]{0,3}[\)]* *(-| ){0,1} *[0-9]{3} *(-| ){0,1} *[0-9]{4}$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isFax(Field) 
{ 
	strValue = getValue(Field); 
	regexp = /^\d{3}-\d{3}-\d{4}$/; 
	if (isEmpty(strValue)) { return false; } 
	return regexp.test(strValue); 
} 

function isEmpty(s) 
{ 
	if (s == null || trim(s) == '') { return true; } 
	else { return false; } 
} 

function isText(f) 
{ 
	return !isEmptyField(f); 
} 

function isNotEmptyDate(val) 
{ 
	return !isEmptyDate(val); 
} 

function isEmptyDate(val) 
{ 
	var ctrl = document.getElementById(val.controltovalidate + '_cal'); 
	return isEmptyField(ctrl); 
} 

function isValidDate(val) 
{ 
	var ctrl = document.getElementById(val.controltovalidate + '_cal'); 
	return isDate(ctrl); 
} 

function isDate2(Field) 
{ 
	if (isEmptyField(Field)) return true; 
	var dtArray = Field.value.split('/'); 
	if (dtArray.length != 3) return false; 
	return CheckDate(dtArray[0],dtArray[1],dtArray[2]); 
} 

function CheckDate(m,d,y) 
{ 
	Months = "31/!/28/!/31/!/30/!/31/!/30/!/31/!/31/!/30/!/31/!/30/!/31"; 
	MonthArray = Months.split("/!/"); 
	if (isNaN(parseInt(m,10))) return false; 
	if (isNaN(parseInt(d,10))) return false; 
	if (isNaN(parseInt(y,10))) return false; 
	d = parseInt(d,10); 
	y = parseInt(y,10); 
	m = parseInt(m,10); 
	y = convertYear(y); 
	if (y <= 1900 ) return false; 
	if (m < 1 || m > 12 ) return false; 
	if ( isLeapYear(y)) MonthArray[1] = eval(eval(MonthArray[1]) + 1); 
	if (d<1 || MonthArray[m-1] < d ) return false; 
	
	return true; 
} 

function convertYear(y) 
{ 
	var borderYEAR = 40; 
	yearvalue = parseInt(y,10); 
	if (isNaN(yearvalue)) return y; 
	if (yearvalue - borderYEAR <= 0) { yearvalue = yearvalue + 2000 } 
	else if (yearvalue - 100 < 0) { yearvalue = yearvalue + 1900 } 
	
	return yearvalue; 
} 

function isLeapYear(Year) 
{ 
	if(Math.round(Year/4) == Year/4)
	{ 
		if(Math.round(Year/100) == Year/100)
		{ 
			if(Math.round(Year/400) == Year/400) return true; 
			else return false; 
		}
		else return true; 
	} 
	return false; 
} 

function getValue(Field) 
{ 
	fieldType = Field.type; 
	if (fieldType == "text") { return getTextValue(Field); } 
	else if (fieldType == "hidden") { return getTextValue(Field); } 
	else if (fieldType == "select-one") { return getListValue(Field); } 
	else if (fieldType == "textarea") { return getTextValue(Field); } 
	else if (fieldType == "file") { return getTextValue(Field); } 
	else if (fieldType == "password") { return getTextValue(Field); } 
	else if (fieldType == "checkbox") { return getCheckboxValue(Field); } 
	else if (isNaN(fieldType)) { return getRadioValue(Field); } 
	else { return getTextValue(Field); } 
} 

function getListValue(Field) 
{ 
	return Field[Field.selectedIndex].value; 
} 

function getTextValue(Field) 
{ 
	return Field.value; 
} 

function getCheckboxValue(Field) 
{ 
	if (Field.checked) return Field.value; 
	return ''; 
} 

function getRadioValue(Field) 
{ 
	found = false; 
	if(isNaN(Field.length)) { return Field.value; } 
	for(var i=0; i< Field.length; i++) 
	{ 
		if ( Field[i].checked ) { return Field[i].value; break; } 
	} 
	return !found; 
} 

function trim(str) 
{ 
	while (str.substring(0,1) == " ") { str = str.substring(1,str.length); } 
	while (str.substring(str.length-1,str.length) == " ") { str = str.substring(0,str.length-1); } 
	return str; 
} 

function isEmptyList(Field) { return isEmpty(Field[Field.selectedIndex].value); } 
function isEmptyText(Field) { return isEmpty(Field.value) } 
function isEmptyCheckbox(Field) { return !Field.checked; } 
function isEmptyField(Field) 
{ 
	fieldType = Field.type; 
	if (fieldType == "text") { return isEmptyText(Field); } 
	else if (fieldType == "hidden") { return isEmptyText(Field); } 
	else if (fieldType == "file") { return isEmptyText(Field); } 
	else if (fieldType == "select-one") { return isEmptyList(Field); } 
	else if (fieldType == "textarea") { return isEmptyText(Field); } 
	else if (fieldType == "password") { return isEmptyText(Field); } 
	else if (fieldType == "checkbox") { return isEmptyCheckbox(Field) } 
	else if (isNaN(fieldType)) { return isEmptyRadio(Field) } 
	else { return isEmptyText(Field); } 
} 

function isDefined(obj) 
{ 
	if(typeof(obj) == "undefined") { return false; } else { return true; } 
} 

function isEmptyRadio(Field) 
{ 
	found = false; 
	if(isNaN(Field.length)) { return !Field.checked; } 
	for(var i=0; i< Field.length; i++) 
	{ 
		if ( Field[i].checked ) { found = true; break; } 
	} 
	return !found; 
} 

function isNotEmptyFile(val) 
{ 
	return !isEmptyFile(val); 
} 

function isEmptyFile(val) 
{ 
	var oid, fid, cid, bDelChecked = false; 
	oid = document.getElementById(val.controltovalidate + '_OLD'); 
	fid = document.getElementById(val.controltovalidate + '_FILE'); 
	cid = document.getElementById(val.controltovalidate + '_CHK'); 
	if (cid != null) { bDelChecked = cid.checked; } return (isEmptyField(oid) && isEmptyField(fid) || isEmptyField(fid) && bDelChecked); 
} 

function isValidFile(val) 
{ 
	if (isEmptyFile(val)) return true; 
	var fid = document.getElementById(val.controltovalidate + '_FILE'); 
	if (isEmptyField(fid)) return true; 
	var filename = getValue(fid); 
	var lastDot = filename.lastIndexOf(".") 
	if (lastDot == -1) return false; 
	var ext = filename.substring(lastDot+1,filename.length);
	filename = filename.substring(0,lastDot);
	if (filename == '') return false; 
	var aExtensions = val.extensions.split(","); 
	for (i=0; i < aExtensions.length; i++) 
	{ 
		if (aExtensions[i] == ext) 
		return true; 
	} 
	return false; 
} 

function limit(fname, width, maxChar) 
{ 
	ctrl = document.getElementById(fname + '_ctrl');
	x = maxChar - ctrl.value.length; 
	if (x < 0) { ctrl.value = ctrl.value.substring(0, maxChar); x = 0; } 
	var ta1, ta2, d; ta1 = document.getElementById(fname + 'TA1'); 
	ta1.style.width = Math.floor(width*(maxChar-x)/maxChar) + 'px'; 
	ta1.alt = maxChar-x+" chars used"; 
	ta2 = document.getElementById(fname + 'TA2'); 
	ta2.style.width = Math.floor(width*x/maxChar) + 'px'; 
	ta2.alt = x + " chars available"; 
	d = document.getElementById(fname + 'DIV'); 
	d.innerHTML = x + " characters left "; 
	window.status = ta1.width + " : " + ta2.width; 
} 











//-- GET SIZE OF UPLOADED IMAGE
//-- GET SIZE OF UPLOADED IMAGE
$file = $_FILES['txtlistingimage']; //file from form
$max_size = 500000; // roughly 500K

if(filesize($file['tmp_name']) > $max_size)
die('File size is too great.');

$img_info = getimagesize($file['tmp_name']);
if(($img_info[0] > 600) ¦¦ ($img_info[1] > 600)) //bracketed each conditional
die('Image dimensions are greater than 600px x 600px.');

if(is_uploaded_file($file['tmp_name'])){
if(move_uploaded_file($file['tmp_name'], $dirupload.$file['name'])){
echo 'w00t! The file was uploaded and is in '.$dirupload;
}
} else {
echo 'No file uploaded to be moved.'; 
*/



