function do_video_extraction(theForm){
  if(check_video_extraction(theForm)){  	
  	xajax_doExtractVideo(theForm.keyword.value,theForm.site.value);  	
  	return true;	
  }else{	
	return false;
  }	
}

function check_video_extraction(theForm){
   if(checkspace(theForm.keyword.value)) {
	theForm.keyword.focus();
        alert("Please input keyword!");
	return false;
   }
   
   
   return true;		
}

function do_CSVImportForm(theForm){
	if(check_csvmport(theForm)){		
		xajax.upload('doCSVImport','CSVImportForm');
		return true;
	}else{	
		return false;
	}
}

function check_csvmport(theForm){
	if(checkspace(theForm.format.value)){
		alert("Please select format!");
		return false;
	}
	if(checkspace(theForm.file.value)){
		alert("Please select file!");
		return false;
	}
	return true;		
}
function showLoginForm(formName){
	xajax_showLoginForm(formName);		
}

function do_send(theForm){
	if(check_send(theForm)){
		xajax_doSend(xajax.getFormValues("send_form"),theForm.subject.value,theForm.body.value);		
	}
}

function do_import(theForm){
  if(check_login(theForm)){  	
  	xajax_doImport(theForm.importer.value,theForm.login.value,theForm.password.value);  	
  }	
}

function do_import_profile(theForm){
  if(check_login(theForm)){  	
  	xajax_doImportProfile(theForm.importer.value,theForm.login.value,theForm.password.value);  	
  }	
}



function check_send(theForm){
   if(checkspace(theForm.subject.value)) {
	theForm.subject.focus();
        alert("Please input email subject!");
	return false;
   }
   
   if(checkspace(theForm.body.value)) {
	theForm.body.focus();
        alert("Please input email content!");
	return false;
   }
   var selectemail = false;
   var theArray=document.getElementsByName('email_array[]');
   for (i = 0; i < theArray.length; i++) {
		if(theArray[i].checked == true){
			selectemail = true;
			break;
		}
	}
	if(!selectemail){
		alert("Please select more than one email address");
		return false;
	}
    return true;		
}

function check_login(theForm){
   if(checkspace(theForm.login.value)) {
	theForm.login.focus();
        alert("Please input login name!");
	return false;
   }
   
   if(checkspace(theForm.password.value)) {
	theForm.password.focus();
        alert("Please input password!");
	return false;
   }
   return true;		
}

function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}

function getObjectByID(id){
	var theObject;
	if(document.getElementById)
		theObject=document.getElementById(id);
	else
		theObject=document.all[id];
	return theObject;
}

function select_all(theClickBox) {
		var theArray=document.getElementsByName('email_array[]');	
			if ( theClickBox.checked ) {
				for (i = 0; i < theArray.length; i++) {
					theArray[i].checked = true ;
				}
				if ( typeof theArray[0] != 'object' ) {
					theArray.checked = true;
				}
				getObjectByID('all1').checked = true;
				getObjectByID('all2').checked = true;
			} else {
				for (i = 0; i < theArray.length; i++) {
					theArray[i].checked = false ;
				}
				if ( typeof theArray[0] != 'object' ) {
					theArray.checked = false;
				}
				getObjectByID('all1').checked = false;
				getObjectByID('all2').checked = false;
			}
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
