/**
 * general.js
 *
 * Copyright (c) 2003-2008 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * Site-wide common JavaScript functions. 
 *
 * $Id: general.js,v 1.25 2008/06/13 20:16:45 asmecher Exp $
 */


/**
  * Elimina el texto de una caja de texto.
  */
    function deletetext(id)
   {
           document.getElementById(id).value="";
		   document.getElementById(id).focus();           
   }



/**
 * Prompt user for confirmation prior to loading a URL.
 */
function confirmAction(url, msg) {
	if (confirm(msg)) {
		if (url) {
			document.location.href=url;
		}
		return true;
	}
	return false;
}

/**
 * Open window displaying help.
 */
function openHelp(url) {
	window.open(url, 'Help', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,scrollbars=1');
}

/**
 * Open window displaying comments.
 */
function openComments(url) {
	window.open(url, 'Comments', 'width=700,height=600,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for preview.
 */
function openWindow(url) {
	window.open(url, 'Window', 'width=600,height=550,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}

/**
 * Open window for reading tools.
 */
function openRTWindow(url) {
	window.open(url, 'RT', 'width=820,height=500,screenX=100,screenY=100,toolbar=0,resizable=1,scrollbars=1');
}
function openRTWindowWithToolbar(url) {
	window.open(url, 'RT', 'width=700,height=500,screenX=100,screenY=100,toolbar=1,resizable=1,scrollbars=1');
}

/**
 * browser object availability detection
 * @param objectId string of object needed
 * @param style int (0 or 1) if style object is needed
 * @return javascript object specific to current browser
 */
function getBrowserObject(objectId, style) {
	var isNE4 = 0;
	var currObject;

	// browser object for ie5+ and ns6+
	if (document.getElementById) {
		currObject = document.getElementById(objectId);
	// browser object for ie4+
	} else if (document.all) {
		currObject = document.all[objectId];
	// browser object for ne4
	} else if (document.layers) {
		currObject = document.layers[objectId];
		isNE4 = 1;
	} else {
		// do nothing
	}
	
	// check if style is needed
	if (style && !isNE4) {
		currObject = currObject.style;
	}
	
	return currObject;
}

/**
 * Load a URL.
 */
function loadUrl(url) {
document.location.href=url;	
}



function create() {
}

/* 	Public function, to be invoked in the web site. 
 */
 
function getCountDown(date) {
  var currentDate = new Date();

  var timeLeft = date.getTime() - currentDate.getTime();
  var days = Math.floor(timeLeft / (1000 * 60 * 60 * 24)) + 1;
  
  out = ''
  
  if (days <=0)
   return ('')
  else {
   	out += (days)
  	return (out += ' days left!')
  }
}

function showCallforPapers()  {
	
	var currentDate = new Date();
	
	var numberOfEvents = 4   
	events = new Array()
	for(var i=0; i<numberOfEvents; i++) { events[i] = new create(); }


	events[0].name = '<strong>Submission Deadline</strong>: <abbr title="September">Sep</abbr>. 16, 2009'
	events[0].date = new Date('09/16/2009') 
	
	events[1].name = '<strong>Notification of Acceptance</strong>: <abbr title="November">Nov</abbr>. 07, 2009'
	events[1].date = new Date('11/07/2009')
	
	events[2].name = '<strong>Camera-Ready Version</strong>: <abbr title="December">Dec</abbr>. 03, 2009'
	events[2].date = new Date('12/03/2009')
	
	events[3].name = '<strong>Publication</strong>: <abbr title="March">Mar</abbr>. 25, 2010'
	events[3].date = new Date('01/25/2010')

	var output = ""
	
	output += '<p><strong>Submitting your paper?</strong> '
	output += 'Download <a type="pdf" href="http://www.hci-rg.com/Resources/eminds/eMinds - call for papers.pdf">call for papers</a></p>'
	
	output += '<p><strong>Next Issue:</strong> Vol II, Issue 6, 2010.</p>'
	output += '<p class="image"><img src="http://www.hci-rg.com/Resources/eminds/Vol 2, No 6 (2010)/eMinds-Cover-Vol 2, No 6 (2010)-lr.gif" alt="eMinds Cover." width="108" height="171"/></p>'
	
		
	output += '<p><strong>Publication Schedule</strong>:</p>'

	
   	output += '<ul>'
	
	dateAlreadyShown= false
	
	for(var j=0; j < numberOfEvents; j++) {
	
		if ( (currentDate.getTime() - events[j].date.getTime()) <=0) {
			output += '<li>'
			output += events[j].name
			
			if (!dateAlreadyShown) {
				output += ' <strong>['
				output += getCountDown(events[j].date)
				output += ']</strong>'
				dateAlreadyShown= true
			}
			output += '.</li>'
		}
	}
	output += '</ul>'
	
					
	document.write (output)
}



extArray  =  new  Array(".zip",  ".pdf");
function LimitAttach(form, file) {
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
			ext = file.slice(file.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArray.length; i++) {
				if (extArray[i] == ext) { allowSubmit = true; break; }
			}
			if (allowSubmit) form.submit();
			else
				alert("Please only upload files that end in types:  "
				+ (extArray.join("  ")) + "\nPlease select a new "
				+ "file to upload and submit again.");
}

function LimitAttach(file) {
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
			ext = file.slice(file.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArray.length; i++) {
				if (extArray[i] == ext) { allowSubmit = true; break; }
			}
			if (!allowSubmit)
				alert("Please only upload files that end in types:  "
				+ (extArray.join("  ")) + "\nPlease select a new "
				+ "file to upload and submit again.");
				
	return allowSubmit;
}

extArrayZip  =  new  Array(".zip");
function LimitAttachZip(file) {
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
			ext = file.slice(file.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArrayZip.length; i++) {
				if (extArrayZip[i] == ext) { allowSubmit = true; break; }
			}
			if (!allowSubmit)
				alert("Please only upload files that end in types:  "
				+ (extArrayZip.join("  ")) + "\nPlease select a new "
				+ "file to upload and submit again.");
				
	return allowSubmit;
}




function valida_envia(){ 
    //valido el interés
    if (document.forms['profile'].interests.selectedIndex==0){
       alert("You need to select a Reviewing interest.")
       document.forms['profile'].interests.focus()
       return 0;
    }

    //el formulario se envia
    document.forms['profile'].submit();
} 


function valida_envia_manager(){ 
    //valido el interés
    if (document.forms['userForm'].interests.selectedIndex==0){
       alert("You need to select a Reviewing interest.")
       document.forms['userForm'].interests.focus()
       return 0;
    }

    //el formulario se envia
    document.forms['userForm'].submit();
} 






