window.onload = function()
{
  initCheckBehavior();
}
function redirectFrmTab(absolutePath, page){
	if(page != ''){
		document.getElementById('tab-title').innerHTML = page.toUpperCase();
	}
	else{
		document.getElementById('tab-title').innerHTML = 'VIDEO';
	}
		
	var fullPath=absolutePath+document.getElementById('tab-title').innerHTML.toLowerCase();
	redirect(fullPath);
}


function redirect(path){	
	window.location=path;
}
	
function showpic(id,imgno){
	
	for(i=1;i<=imgno;i++){
		if(i!=id){
    		document.getElementById(i+'pic').style.display='none'; 
		} else {
			document.getElementById(i+'pic').style.display='block';
		}
	}
}

function showDiv2Upload(showDiv){
	alert (showDiv);
	var isUploadDivVisible=false;
		if(!isUploadDivVisible){
			document.getElementById('showDiv').style.display='block';
			document.getElementById('divToShowUploadBox').innerHTML='here';
			var isUploadDivVisible=true;
			}
			else{
			document.getElementById('showDiv').style.display='none';
			document.getElementById('divToShowUploadBox').innerHTML='hide';
			var isUploadDivVisible=false;
				}
	
	}
	
function showHide2Div(showDiv,HideDiv){
	
	document.getElementById(showDiv).style.display='';
	document.getElementById(HideDiv).style.display='none';
	}	
	
function showHide(showDiv){
	if(document.getElementById(showDiv).style.display=='none')
		document.getElementById(showDiv).style.display='';
	else
		document.getElementById(showDiv).style.display='none';
}

function sliderDiv(showDiv){
	if(document.getElementById(showDiv).style.display=='none')
			$("#"+showDiv).show('slow');
		else
			$("#"+showDiv).hide('slow');	
		
	}
function showHideUploadForm(showDiv){
		var arrayVI=new Array('picture','video','hotlink','newslink','product','videoseries');
		for(var i=0;i<arrayVI.length;i++){			
			$("#"+arrayVI[i]+"Upload").hide('slow');			
		}	
		if(document.getElementById(showDiv+"Upload").style.display=='none')
			$("#"+showDiv+"Upload").show('slow');
		else
			$("#"+showDiv+"Upload").hide('slow');
		}

function isValidEmail(strEmail){	
	var msg;
	var i;
	var len=strEmail.length;
	if(strEmail=="") {
			msg="0";
	} 
	else {
		if((strEmail.charAt(0)=="@") || (strEmail.charAt(0)==".")) {
			msg="0";
		} else {
	//	checking the number of the @ and dots in the email add	
			var countAt=0;
			var countDot=0;
			for (i=0; i<len; i++) {
				if(strEmail.charAt(i)=="@") {
					countAt=countAt+1;
				}	
				if(strEmail.charAt(i)==".") {
					countDot=countDot+1;
				}
			} //end of for (i=0; i<strEmail.length; i++) {...	
			if((countAt!=1) || (countDot<1)) {
				msg="0";
			} else {
		//	checking the position of the @ with respect to the dot 
				var posDot=0;
				var posAt=0;
				posDot=strEmail.lastIndexOf(".");
				posAt=strEmail.indexOf("@");
				if((posAt>posDot) || (posDot==(posAt+1))) {
					msg="0";
				} else {
			//	checking the dot position and the @ postion at the end
					if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {
						msg="0";
					} else {
						/* 	checking for the invalid characters
						 if(ereg('[^A-Za-z0-9_]', strEmail)) {
					msg="Only letters, numbers and underscores(_).";		*/
						msg = "1";
					} //end of if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {...
				} //end of if((posAt>posDot) || (posDot==(posDot+1))) {...
			} //end of if((countAt!=1) ||(countDot<1)) {...		
		} //end  if((strEmail.charAt(i)=="@") || (strEmail.charAt(i)==".")) {...
	} //end of if(strEmail=="") {...
	return msg;	
}
function sendEmailForQuestion(){
	if(document.getElementById('emailnote').checked)
	document.getElementById('emailnote').value=1;
	else
	document.getElementById('emailnote').value=0;
	}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function showHideDiv(showDivId,hideDivId){	
	document.getElementById(hideDivId).style.display="none";	
	document.getElementById(showDivId).style.display="block";	
	}
	
function showpic(id,imgno){
	for(i=1;i<=imgno;i++){
		if(i!=id){
    		document.getElementById(i+'pic').style.display='none'; 
		} else {
			document.getElementById(i+'pic').style.display='block';
		}
	}
}

function showLikeDislike(showDiv){
	if(showDiv=='likes-display'){
		document.getElementById('dislikes-display').style.display='none';
		document.getElementById('likes-display').style.display='block';
		document.getElementById('dislikes-link').className='inactive-likes';
		document.getElementById('likes-link').className='active-likes';
	}
	if(showDiv=='dislikes-display'){
		document.getElementById('likes-display').style.display='none';
		document.getElementById('dislikes-display').style.display='block';
		document.getElementById('likes-link').className='inactive-likes';
		document.getElementById('dislikes-link').className='active-likes';
	}
}


function concatUsers(object){
	var valueVar=document.getElementById('tpmembers').value;
	var varLength=valueVar.length;
	var arrayValue;
	var storeTemp='';			
	if(object.checked)
		valueVar+=', '+object.value;
	else{
		arrayValue=valueVar.split(", ");		
		for(var i=1;i<arrayValue.length;i++){			
			if(arrayValue[i]!=object.value)
				storeTemp+=", "+arrayValue[i];				
			}
		valueVar=storeTemp;
		}
	document.getElementById('tpmembers').value=valueVar;
	}
function showHideErrorMessages(showDivId){
	var arrayStored=new Array('showUserHint','showEmailHint');
	for(var i=0;i<arrayStored.length;i++)
	$('#'+arrayStored[i]).slideUp('fast');
	$('#'+showDivId).slideDown('fast');
	}
	
function showHideCommentBox(id){
	document.getElementById('hiddenReviewId').value=id;
	document.getElementById('idforCommentBox').style.display="block";	
	}
function seeifanyoneischecked(){
	var elems=document.getElementById('form1').elements.length;
	var str='';
	 for(i=0; i<elems; i++)
	 	if (document.getElementById('form1').elements[i].id=='checkbox' && document.getElementById('form1').elements[i].checked)
		 	str += document.getElementById('form1').elements[i].value + ',';
	if(str==''){
		alert('Please select the records');
		return false;
	}
	if(confirm('Are you sure you want to delete?')==true){
		return true;
	}
	else return false;
} 


function seeIfAnyCheckboxIsChecked(form){
	var elems=form.elements.length;
	var str='';
	 for(i=0; i<elems; i++)
	 	if (form.elements[i].id=='checkbox' && form.elements[i].checked)
		 	str += form.elements[i].value + ',';
	if(str==''){
		alert('Please select the records');
		return false;
	}
	if(confirm('Are you sure you want to delete?')==true){
		return true;
	}
	else return false;
} 

function initCheckBehavior()
{	
  var i,a;
  for (i = 0; i < document.links.length; ++i) {
    a = document.links[i];
    if (a.id.indexOf('UncheckAll_') != -1) {
      a.onclick = doCheckBehavior;
      a._CBNAME_ = a.id.substr(11) + '[]';
      a._CBCHECKED_ = false;
    }
    else if (a.id.indexOf('CheckAll_') != -1) {
      a.onclick = doCheckBehavior;
      a._CBNAME_ = a.id.substr(9) + '[]';
      a._CBCHECKED_ = true;
    }
  }
}
function doCheckBehavior()
{
  var i, cb = document.getElementsByName(this._CBNAME_);
  for (i = 0; i < cb.length; ++i) {
    cb[i].checked = this._CBCHECKED_;
  }
  return false;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=500,left = 262,top = 134');");
}

function taketootherpage(page){
	document.location=page;
}


//for picture view
function ShowPicture(){
	document.getElementById('picdiv').style.display='block';
}
function HidePicture(){
	document.getElementById('picdiv').style.display='none';
}

function ShowPictureList(id){
	document.getElementById('picdiv'+id).style.display='block';
}
function HidePictureList(id){
	document.getElementById('picdiv'+id).style.display='none';
}

function blankHint(divname){
	document.getElementById(divname).innerHTML='<div class="ajaxhints"><font color="#993300">Can not be blank</font></div>';
}

function sort_table(sort_title, sort_order, page, fullpath){
		
	var url = '';
	
	switch(sort_order){
		
		case '':
		case 'ASC':
			url =  fullpath + 'humormaster/index.php?page='+page+'&sort_title=' + sort_title +'&sort_order=DESC';
			break;
			
		case 'DESC':
			url =  fullpath +'humormaster/index.php?page='+page+'&sort_title=' + sort_title +'&sort_order=ASC';
			break;
		
		default:
			url = fullpath +'humormaster/index.php?page='+page;
			break;
	}
	window.location = url;
}
function show_default_best_of_section(fullpath, section){
	
	showBestOfSection(fullpath, section);
}

function toggle_element_visibility( e, expr ){
		
		var ele;
		
		ele = document.getElementById(e);
		
		if(expr)
			ele.style.display = 'none';
			
		else
			ele.style.display = '';
}
