function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isArray(com) {
	if (typeof(com.length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function isArraySelectBox(com) {
	if (typeof(com[0].length) == "undefined") {
		return false;
	}
	else {
		return true;
	}
}

function trim(str) {
	var strTrim = "";
	var i, j;
	
	if (isEmpty(str)) return strTrim;
	
	for (i=0; i<str.length; i++) {
		if (str.charAt(i) != " ") break;
	}
	for (j=str.length-1; j>=0; j--) {
		if (str.charAt(j) != " ") break;
	}
	
	strTrim = str.substr(i, j-i+1);
	return strTrim;
}

function isEmpty(str) {
	return ((str==null) || (str.length==0));
}

function isWhiteSpace(str) {
	return isEmpty(trim(str));
}

function isDigit(d) {
	return ((d >= "0") && (d <= "9"));
}

function isLetter(c) {
	return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
}

function isNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr)) {
			return false;
		}
	}
	return true;
}
function isInteger(s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isFloat(s){
  var i;
  var seenDecimalPoint = false;
  if (isEmpty(s)) 
    if (isFloat.arguments.length == 1) return false;
    else return (isFloat.arguments[1] == true);
  if (s == '.') return false;
  for (i = 0; i < s.length; i++){   
    var c = s.charAt(i);
    if ((c == '.') && !seenDecimalPoint) 
	  seenDecimalPoint = true;
    else if (!isDigit(c)) return false;
  }
  return true;
}

function isDate (year,month,day) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) )
        return true;
    else
        return false
}


function isAlphaNumeric(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isDigit(chr) && !isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isAlphaOnly(strNum) {
	var i;
	
	if (isWhiteSpace(strNum) == true) {
		return false;
	}
	
	strNum = trim(strNum);
	
	for (i=0; i<strNum.length; i++) {
		var chr = strNum.charAt(i);
		if (!isLetter(chr)) {
			return false;
		}
	}
	return true;
}

function isRange(formObj, min, max)
{
	if(formObj.length < min || formObj.length > max)
	{
		return false;
	}
	return true;
}


function isEmail(s)
{   
	
	//alert(s); 
   	// is s whitespace?
    //if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++;
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++;
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else
	return true;
}

//Function to check whether the string is a valid integer
//Function to check whether the zipcode is a valid US zip code
function isZIPCode(field) 
{
	var valid = "0123456789";
	var hyphencount = 0;
	
	if (field.length!=5) {
	alert("Please enter your 5 digit zip code.");
	return false;
	}
	for (var i=0; i < field.length; i++) {
	temp = "" + field.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
	alert("Invalid characters in your zip code.  Please try again.");
	return false;
	}

	}
	return true;
}

function isMoney(str) 
{
	var valid = "0123456789.-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isPhoneNumber(str) 
{
	var valid = "0123456789()-"
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
			//ok = "no";
			return false;
	}
	return true;
}

function isCheckedRadio(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(typeof(count) == 'undefined') {
			checked = objRadio.checked;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = true;
				}
			}
		}
	}
	return checked;
}

function getRadioVal(objRadio) {
	checked = false;
	if (objRadio) {
		count = objRadio.length;
		if(typeof(count) == 'undefined') {
			checked = objRadio.value;
		} 
		else {
			for(var i=0; i<count; i++) {
				if(objRadio[i].checked) {
					checked = objRadio[i].value;
				}
			}
		}
	}
	return checked;
}


function isSelected(frmObjSelect)
{
	if (frmObjSelect.value == -1) {
		return false;
	}
	else {
		return true;
	}
}




function popupNameWindow(page_url,name, width, height, opt) {
	temp= window.open(page_url,name,'width='+width+',height='+height+','+opt);
	temp.focus();
	
}

function popupWindow(page_url, width, height, opt) {
	window.open(page_url,'popup_window','width='+width+',height='+height+','+opt);
}

function nameWindow(page_url,name, width, height, opt) {
	temp = window.open(page_url,name,'width='+width+',height='+height+','+opt);
	temp.focus();
}

function printWindow(page_url,width,height) {
	temp = window.open(page_url,'popup_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=1,menubar=0,scrollbars=1');
	temp.focus();
	
}


function imageWindow(boardname,id,width,height) {
	window.open('image_viewer.php?board='+boardname+'&id='+id,'image_window','width='+width+',height='+height+',toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=1');
}



function imgView(img_obj) {
	if(window.popup != undefined) window.popup.close();
	if (typeof(img_obj) == 'string') {
		var win_scrollbars = 'no';
		var width_plus = 0;
		var img_name = img_obj;
	} else if (img_obj.height > 400) {
		var win_scrollbars = 'yes';
		var width_plus = 20;
		var img_name = img_obj.src;
	} else {
		var win_scrollbars = 'no';
		var width_plus = 0;
		var img_name = img_obj.src;
	}
	popup = window.open('about:blank','imgView','width=10,height=10, toolbar=0,menubar=0,resizable=yes,scrollbars='+win_scrollbars+', top=50, left=50');
	popup.document.writeln('<html><title>Photo Viewer</title>'
		+ '<body topmargin="0" rightmargin="0" leftmargin="0" bgcolor="#FFFFFF">'
		+ '<sc'+'ript>function reSize() { if(document.all("pre_img").width > 0) resizeTo(((document.all("pre_img").width > 800)?800:document.all("pre_img").width) + 10 + '+width_plus+',((document.all("pre_img").height > 600)?600:document.all("pre_img").height) + 50);} </scr'+'ipt>'
		+ '<img src=' + encodeURI(img_name) + ' border=0 onclick=self.close() style="cursor:hand" name=pre_img id=pre_img onload="reSize()">'
		+ '');
} 

/* Scrolling function */
var scrollerheight=150;		// ½ºÅ©·Ñ·¯ÀÇ ¼¼·Î 
var html,total_area=0,wait_flag=true;
	
var bMouseOver = 1;
var scrollspeed = 1;		// Scrolling ¼Óµµ         
var waitingtime = 3000;		// ¸ØÃß´Â ½Ã°£
var s_tmp = 0, s_amount = 35;
var startPanel=0, n_panel=0, i=0;
	
function startscroll()
{ // ½ºÅ©·Ñ ½ÃÀÛ
	i=0;
	for (i in scroll_content)
		n_panel++;
			
	n_panel = n_panel -1 ;
	startPanel = Math.round(Math.random()*n_panel);
	if(startPanel == 0)
	{
		i=0;
		for (i in scroll_content) 
			insert_area(total_area, total_area++); // area »ðÀÔ
	}
	else if(startPanel == n_panel)
	{
		insert_area(startPanel, total_area);
		total_area++;
		for (i=0; i<startPanel; i++) 
		{
			insert_area(i, total_area); // area »ðÀÔ
			total_area++;
		}
	}
	else if((startPanel > 0) || (startPanel < n_panel))
	{
		insert_area(startPanel, total_area);
		total_area++;
		for (i=startPanel+1; i<=n_panel; i++) 
		{
			insert_area(i, total_area); // area »ðÀÔ
			total_area++;
		}
		for (i=0; i<startPanel; i++) 
		{
			insert_area(i, total_area); // area »ðÀÔ
			total_area++;
		}
	}
	window.setTimeout("scrolling()",waitingtime);
}

function scrolling(){ // ½ÇÁ¦·Î ½ºÅ©·Ñ ÇÏ´Â ºÎºÐ
	if (bMouseOver && wait_flag)
	{
		for (i=0;i<total_area;i++){
			tmp = document.getElementById('scroll_area2'+i).style;
			tmp.top = parseInt(tmp.top)-scrollspeed;
			if (parseInt(tmp.top) <= -scrollerheight){
				tmp.top = scrollerheight*(total_area-1);
			}
			if (s_tmp++ > (s_amount-1)*scroll_content.length){
				wait_flag=false;
				window.setTimeout("wait_flag=true;s_tmp=0;",waitingtime);
			}
		}
	}
	window.setTimeout("scrolling()",1);
}

function insert_area(idx, n){ // area »ðÀÔ
	html='<div style="left: 0px; width: 100%; position: absolute; top: '+(scrollerheight*n)+'px" id="scroll_area2'+n+'">\n';
	html+=scroll_content[idx]+'\n';
	html+='</div>\n';
	document.write(html);
}

/* Scrolling function End */

	function getCookie(name) { 
		var index = document.cookie.indexOf(name + "="); 
		if (index == -1) return null; 
		index = document.cookie.indexOf("=", index) + 1; 
		var endstr = document.cookie.indexOf(";", index); 
		if (endstr == -1) endstr = document.cookie.length; 
		return unescape(document.cookie.substring(index, endstr)); 
	} 
	function setCookie(name, value) { 
		var today = new Date(); 
		var expiry = new Date(today.getTime() + 24 * 60 * 60 * 1000); 
		document.cookie = name + "=" + escape(value) + ((today) ? "; expires=" + expiry.toGMTString() : ""); 
	} 
	
	function addBookMark(strUrl,strName) {
	
		 if ((navigator.appName == "Microsoft Internet Explorer") 
		 && (parseInt(navigator.appVersion) >= 4)) {
		 	window.external.AddFavorite(strUrl,strName);
		 }
 
	} 
	
function getcities(state){
			document.getElementById('cities').innerHTML = "";
			/*
			doing this in case someone changes their mind and wants to select a different state. When they do - any stores that are already listed will be cleared.
			*/ 
			
			var xmlhttp=false;
			try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
			try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
			xmlhttp = false;
			}
			}
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
			}
			var file = 'getcities.php?state=';
			xmlhttp.open('GET', file + state, true);
			xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if( content ){
			document.getElementById('cities').innerHTML = content;
			document.all.cityblank.style.display = 'none';
			}
			}
			}
			xmlhttp.send(null)
			return;
			;
}

function getcities2(state,city){
			document.getElementById('cities').innerHTML = "";
			/*
			doing this in case someone changes their mind and wants to select a different state. When they do - any stores that are already listed will be cleared.
			*/ 
			
			var xmlhttp=false;
			try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
			try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
			xmlhttp = false;
			}
			}
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
			}
			var file = 'getcities.php?w=130&state='+state+'&city='+city;
			xmlhttp.open('GET', file, true);
			xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if( content ){
			document.getElementById('cities').innerHTML = content;
			//document.all.cityblank.style.display = 'none';
			}
			}
			}
			xmlhttp.send(null)
			return;
			;
}
function getcities2_w(state,city,w){
			document.getElementById('cities').innerHTML = "";
			/*
			doing this in case someone changes their mind and wants to select a different state. When they do - any stores that are already listed will be cleared.
			*/ 
			
			var xmlhttp=false;
			try {
			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
			try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
			} catch (E) {
			xmlhttp = false;
			}
			}
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			xmlhttp = new XMLHttpRequest();
			}
			var file = '/getcities.php?w='+w+'&state='+state+'&city='+city;
			xmlhttp.open('GET', file, true);
			xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if( content ){
			document.getElementById('cities').outerHTML = document.getElementById('cities').outerHTML;
			document.getElementById('cities').innerHTML = content;
			//document.all.cityblank.style.display = 'none';
			}
			}
			}
			xmlhttp.send(null)
			return;
			;
}

function checkInteger(tObj) {
	if(!isInteger(tObj.value)) {
		alert('¼ýÀÚ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.');
		tObj.focus();
	}
}

function SetNum(obj){
 val=obj.value;
 re=/[^0-9]/gi;
 obj.value=val.replace(re,"");
}

function SetNumDot(obj){
 val=obj.value;
 re=/[^0-9.]/gi;
 obj.value=val.replace(re,"");
}

function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(dateStr + " Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}

function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(dateStr + " Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}


function isValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute < 0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

function dateDiff(first_date,first_time,second_date, second_time) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

if (isValidDate(first_date) && isValidTime(first_time)) { // Validates first date 
date1temp = new Date(first_date + " " + first_time);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits

if (isValidDate(second_date) && isValidTime(second_time)) { // Validates first date 
date2temp = new Date(second_date + " " + second_time);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits

// sets difference date to difference of first date and second date

diff.setTime(date2.getTime() - date1.getTime());

timediff = diff.getTime();
/*
weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);

hours = Math.floor(timediff / (1000 * 60 * 60)); 
timediff -= hours * (1000 * 60 * 60);
*/
mins = Math.floor(timediff / (1000 * 60)); 
timediff -= mins * (1000 * 60);
/*
secs = Math.floor(timediff / 1000); 
timediff -= secs * 1000;
*/
	return mins;
}

