// JavaScript Document

var tr;
function changeLinkCss(upperTab,upperLink,leftMenuTr,LeftMenuLink)
{
/*
if(upperTab!=0)
 	document.getElementById(upperTab).className='linkboldtext1';
 if(upperLink!=0)
 	document.getElementById(upperLink).className='linkboldtext1';
 if(leftMenuTr!=0)
 	document.getElementById(leftMenuTr).className='currentlink';
 if(LeftMenuLink!=0)
 	document.getElementById(LeftMenuLink).className='currentlink';
 tr = leftMenuTr;*/
}
function showHideTab(tabId)
{
  hideRow("tabHome");
  hideRow("tabComp");
  hideRow("tabUserM");
  hideRow("tabEvents");
  hideRow("tabQuestion");
  hideRow("tabSetting");
  hideRow("tabReport");
  hideRow("tabEventsAll");
  showRow(tabId);
}

function onMouseOver1(id,lnk)
{
if(id!=0 && id!=tr)
 document.getElementById(id).bgColor="#FFFFFF";
}

function onMouseOut1(id,lnk)
{
if(id!=0 && id!=tr)
  document.getElementById(id).bgColor="#EAF1F9";
}

function funcdelete(val)
{
	
	if(val == 1)
		flag = confirm("Are you sure you want to delete this record?");
	else
		flag = confirm("Are you sure you want to delete selected records?");

	if(flag == false)
	return false;
}

function funcapprovelist(val)
{
	
	if(val == 1)
		flag = confirm("Are you sure you want to approve this listing?");
	else
		flag = confirm("Are you sure you want to approve selected listings?");

	if(flag == false)
	return false;
}

function funcApprove(val)
{
	
	if(val == 1)
		flag = confirm("Are you sure you want to Approve selected image(s)?");
	else
		flag = confirm("Are you sure you want to Disapprove selected image(s)?");

	if(flag == false)
	return false;
}

function funcActiveInactive(val,status)
{
	
	if(status == 'Inactive')
	{
	 flag = confirm("Are you sure you want to activate this record?");
	}
	else
	 flag = confirm("Are you sure you want to Inactivate this record?");
	if(flag == false)
	return false;
}

function funcdeletelistings(FieldName)
{

	 var objCheckBoxes = document.getElementsByName(FieldName);
		 cnt =0 ;
		 str='';
		for(i=0;i<objCheckBoxes.length;i++){
			if(objCheckBoxes[i].checked == true)
			{
			 	cnt++;
				str = str + objCheckBoxes[i].value+',';
			}
		}
		document.getElementById("AccountId").value = str
		document.getElementById("num").innerHTML = "("+cnt+")";
	
}

function funcapprovelistings(FieldName)
{

	 var objCheckBoxes = document.getElementsByName(FieldName);
		 cnt =0 ;
		 str='';
		for(i=0;i<objCheckBoxes.length;i++){
			if(objCheckBoxes[i].checked == true)
			{
			 	cnt++;
				str = str + objCheckBoxes[i].value+',';
			}
		}
		document.getElementById("AccountId").value = str
		document.getElementById("num").innerHTML = "("+cnt+")";
		
	
}

function CheckAllCBoxes(FieldName)
{
	
	
	 //var objCheckBoxes = document.forms[FormName].elements[FieldName];	
	  var objCheckBoxes = document.getElementsByName(FieldName);
  	 var countCheckBoxes = objCheckBoxes.length;
	// set the check value for all check boxes
	flag = false;

	  for(var i = 0; i < countCheckBoxes; i++)
	  {		 
	  
   		if(objCheckBoxes[i].checked )
		{			
		
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {
		  alert('Please select atleast one record to approve!');
		  return false;
	  }
	  return true;
}

function CheckAllCheckBoxes(FieldName)
{
	
	 //var objCheckBoxes = document.forms[FormName].elements[FieldName];	
	  var objCheckBoxes = document.getElementsByName(FieldName);
  	 var countCheckBoxes = objCheckBoxes.length;
	// set the check value for all check boxes
	flag = false;

	  for(var i = 0; i < countCheckBoxes; i++)
	  {		 
	  
   		if(objCheckBoxes[i].checked )
		{			
		
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {
		  alert('Please select atleast one record to delete.');
		  return false;
	  }
	  return true;
}

function CheckAllPhotoCheckBoxes(FieldName)
{
	
	 //var objCheckBoxes = document.forms[FormName].elements[FieldName];	
	  var objCheckBoxes = document.getElementsByName(FieldName);
  	 var countCheckBoxes = objCheckBoxes.length;
	// set the check value for all check boxes
	flag = false;

	  for(var i = 0; i < countCheckBoxes; i++)
	  {		 
	  
   		if(objCheckBoxes[i].checked )
		{			
		
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {
		  alert('Please select at least one photo.');
		  return false;
	  }
	  return true;
}

function CheckAllCheckBoxes1(FieldName)
{
	
	 var objCheckBoxes = document.getElementsByName(FieldName);
	
	 var countCheckBoxes = objCheckBoxes.length;
	
	// set the check value for all check boxes
	flag = false;

	  for(var i = 0; i < countCheckBoxes; i++)
	  {		 
	  
   		if(objCheckBoxes[i].checked )
		{			
		
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {
		  alert('Please select atleast one record to delete.');
		  return false;
	  }
	  return true;
}
function CheckAllCheckBoxesImport(FieldName)
{
	
	 var objCheckBoxes = document.getElementsByName(FieldName);
	
	 var countCheckBoxes = objCheckBoxes.length;
	
	// set the check value for all check boxes
	flag = false;

	  for(var i = 0; i < countCheckBoxes; i++)
	  {		 
	  
   		if(objCheckBoxes[i].checked )
		{			
		
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {
		  alert('Please select atleast one record to import.');
		  return false;
	  }
	  return true;
}
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	
 if(!document.forms[FormName])
  return;
 var objCheckBoxes = document.forms[FormName].elements[FieldName];
 if(!objCheckBoxes)
  return;
 var countCheckBoxes = objCheckBoxes.length;
 if(!countCheckBoxes)
  objCheckBoxes.checked = CheckValue.checked;
 else
  // set the check value for all check boxes
  for(var i = 0; i < countCheckBoxes; i++){
	  if(objCheckBoxes[i].disabled != true)
	   objCheckBoxes[i].checked = CheckValue.checked;
  }
}

function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode;

	if (unicode!=8 && unicode !=9 &&  unicode !=  17 && unicode != 43 && unicode !=45 && unicode != 41  && unicode !=40  && unicode !=37  && unicode !=38   && unicode !=39 && unicode !=46)
	{ 	
		//if the key isn't the backspace,Tab key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
			return false; //disable key press
	}
}
function zipnumbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode;

	if (unicode!=8 && unicode !=9 &&  unicode !=  17 && unicode != 43 &&  unicode != 45 &&  unicode != 41  && unicode !=40  && unicode !=37  && unicode !=38   && unicode !=39 && unicode !=46)
	{  
		//if the key isn't the backspace,Tab key (which we should allow)
		if (unicode<48||unicode>57  ) //if not a number
			return false; //disable key press
	}
}
function phonenumbersonly(e)
{

	var unicode = e.charCode? e.charCode : e.keyCode;

	if (unicode!=8 && unicode !=9 && unicode != 43 && unicode !=45 && unicode != 41  && unicode !=40  && unicode !=32 && unicode !=  17  && unicode !=  8 && unicode !=37  && unicode !=38 &&  unicode !=39&& unicode !=46)
	{ 	
		//if the key isn't the backspace,Tab key (which we should allow)
			if( (unicode >= 48  && unicode <=57 ) || (unicode >= 65  && unicode <=90 ) || (unicode >= 97  && unicode <= 122 ))
				return true;
			else
				return false; //disable key press

	}
}


function checkvalidation(){
	credit_cards = document.getElementsByName('credit_cards[]');

	invoice  = document.getElementsByName('invoice[]');
	cflag = false;
	iflag = false;
	cc_cnt=0;
	inv_cnt=0;
	for(i=0;i<credit_cards.length;i++){
	
		if(credit_cards[i].checked == true)
		{
			cflag= true;
			cc_cnt++;
			//break;
		}
	}
		
	for(i=0;i<invoice.length;i++){
		if(invoice[i].checked == true)
		{
			iflag= true;
			inv_cnt++;
			//break;
		}
	}
		
		if(cflag == false && iflag == false){
			alert("Please select  any one option credit cards / Invoice .");
			return false;
		}
		
		if(cflag == true && iflag == true){
			alert("Please select either credit cards  option or Invoice option.");
			return false;
		}

		if(cc_cnt > 1 || inv_cnt > 1)
		{
			alert("Please select only one checkbox from credit cards option/Invoice option.");
			return false;			   
	   }
		
		/*if(cflag == true ){
			document.frmPaymentOption.setAttribute('action','payment.php');
		}else {
			document.frmPaymentOption.setAttribute('action','manage_advertiser.php');
		}*/
		
	}
	
function setMaxLength() {

	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<p><span>0</span>/'+ x[i].getAttribute('maxlength')+'</p>';
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength ;
			 x[i].onblur = setlength;
	 
			x[i].onkeyup();
			
		}
	}
}
function setlength(){
	var currentLength = this.value.length;
	
	var maxLength = this.getAttribute('maxlength');
	if (currentLength > maxLength){
		alert("Max of "+maxLength+" characters allowed here.");	
		this.relatedElement.firstChild.nodeValue=maxLength;		
	}
	this.value = this.value.substring(0, maxLength);
 
	} 
function realtime(){
	var obj = document.getElementById('business_description1');
	 tag='';
	if(obj.value.length > 350) 
	val = obj.value.substr(0,350) + '...';
	else
	val = obj.value;
	if(document.getElementById('BUdesc')){
		strval =document.getElementById('BUdesc').innerHTML;	 
		if(strval.indexOf("<p>") != -1)
		document.getElementById('BUdesc').innerHTML = '<p>'+ val +'</p>';
		else if(strval.indexOf("<h2><b>") != -1) 
		document.getElementById('BUdesc').innerHTML = '<h2><b>'+ val +'</h2><b>';
		else
		document.getElementById('BUdesc').innerHTML = val;
	}
}
	
function checkMaxLength( ) {
 
 if(window.event)
unicode=window.event.charCode? window.event.charCode : window.event.keyCode;
else
unicode=0;
 
 
if(unicode != 37 && unicode != 40 && unicode !=39 && unicode != 38 && unicode != 36 && unicode != 35 &&  unicode != 46 && unicode != 33 && unicode !=  34 &&   unicode !=  17  && unicode !=  8 && unicode !=9 && unicode != 43 && unicode !=45 && unicode != 41 ){
var maxLength = this.getAttribute('maxlength');
	var val;
	val = (this.value); //Trim	
	//this.value = val;
//	var currentLength = val.length;
	var currentLength = this.value.length;
	//if (currentLength > maxLength)
	//this.value = this.value.substring(0, maxLength);
	this.relatedElement.firstChild.nodeValue = currentLength;
	
	if(this.name =="business_description1")
	{
		realtime();
	}
	 
	// not innerHTML
 }
}
function Trim(str)
{ 
	while(str.charAt(0) == (" ") )
	{ str = str.substring(1);
	}
	
	while(str.charAt(str.length-1) == " " )
	{ str = str.substring(0,str.length-1);
	}
	return str;
}
function email_validation(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
function validateEmailv2(email)
{
	if(email.length <= 0)
		{
		return true;
		}
		var splitted = email.match("^(.+)@(.+)$");
		if(splitted == null) return false;
		if(splitted[1] != null )
			{
			var regexp_user=/^\"?[\w-_\.]*\"?$/;
			if(splitted[1].match(regexp_user) == null) return false;
			}
		if(splitted[2] != null)
			{
			var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
			if(splitted[2].match(regexp_domain) == null) 
				{
				var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
				if(splitted[2].match(regexp_ip) == null) return false;
				}
			return true;
			}
		return false;
}

function setHiddenValues(){
	
	credit_cards = document.getElementsByName('credit_cards[]');
	invoice  = document.getElementsByName('invoice[]');	
	var value;

	for(i=0;i<credit_cards.length;i++){
	
		if(credit_cards[i].checked == true)
		{
			value = credit_cards[i].value.split("#");
			document.frmPaymentOption.desc.value=value[0];
			document.frmPaymentOption.rate.value=value[1];
			document.frmPaymentOption.payment_option.value=value[2];
	
		}
	}
	for(i=0;i<invoice.length;i++){
		if(invoice[i].checked == true)
		{
			value = invoice[i].value.split("#");
			document.frmPaymentOption.desc.value=value[0];
			document.frmPaymentOption.rate.value=value[1];
			document.frmPaymentOption.payment_option.value=value[2];
		}
		}
}
function unCheckCheckAll(obj,field){

	if(obj.checked == false)	
	document.getElementById(field).checked = false;
}


function verify(f)
{
	
    var msg = '';
    var empty_fields = "";
    var errors = "";
	
	 for(var i = 0; i < f.length; i++) 
	 {
        var e = f.elements[i];
		 if (e.type == "checkbox") 
		 {

			if(e.name != 'onsite_staff_available[]' &&  e.name != 'credit_cards[]' && e.name != "venue_type[]" && e.name != "services[]"){
		 	if(checkboxchecked(e.name) == false)
			{			
				name= (e.name).replace('[]','');	
				
				name= (name).replace('_id',' ');					
				
				name= (name).replace('_',' ');					
				
				name= (name).replace('_',' ');			
				
			 	errors = 'Please select at least one ' + name + " option";					
			}
		  }
		 }
			
	 }    	
    if (!empty_fields && !errors) 
	{
		return true;
	}
	else
	{
		if (empty_fields && flag == false) 
		{       
			if (errors) msg += "\n";
		}
	
		msg += errors;
		alert(msg);
		
		return false;
	}
	
	return true;
}

function checkboxchecked(FieldName)
{
	
	 var objCheckBoxes = document.getElementsByName(FieldName);
	
  	 var countCheckBoxes = objCheckBoxes.length;
	 
	 var countCheckBoxes = objCheckBoxes.length;	
	// set the check value for all check boxes
	 flag = false;
	  for(var i = 0; i < countCheckBoxes; i++)
	  {		  		
		if(objCheckBoxes[i].checked )
		{				
			flag = true;
			break;
		}
	  }
	  if(flag == false)
	  {		
		  return false;
	  }
	
}
function validate_other(){

flag1 = do_select();
flag2 = do_text_check();
 
	if(flag1 == true ){		
		if(flag2 == false){
		alert("Please select Time limit option.");
		return false;
		}
	}
	else{
	alert("please enter text for Time limit option."); 
	 return false;
	}
	return true;
}
function do_select()
{
var music_sound = document.getElementsByName("music_sound[]");
 flag = true;
for(var i=0;i<music_sound.length;i++)
	{	
		  if(i == 4){				  
			if(music_sound[i].checked == true  && document.getElementById('time_litmit_text').value =='' ){			
			 flag = false;
			}
		
		}
	}
 return flag;
}

function do_text_check(){
var music_sound = document.getElementsByName("music_sound[]");
  flag = true;
if(document.getElementById('time_litmit_text').value != ''){

	for(var i=0;i<music_sound.length;i++)
	{	
	  if(i == 4){
		  
	   if(music_sound[i].checked)
	   flag = true;
	   else
	   flag = false;
	   }   
	 
	}
 }

 return flag;
}
function setBuDescriptionText(obj,tag){
	
	if(obj.value.length > 350) 
	val = obj.value.substr(0,350) + '...';
	else
	val = obj.value;
	if(tag == 'p')
	document.getElementById('BUdesc').innerHTML = '<p>'+ val +'</p>';
	else if(tag == '<h2><b>')
	document.getElementById('BUdesc').innerHTML = '<h2><b>'+ val +'</h2><b>';
	else
	document.getElementById('BUdesc').innerHTML = val;
}

function setContactInfoText(obj,field){	

 
	street_address1 = document.getElementById("street_address1").value;
	street_address2 = document.getElementById("street_address2").value;
	city 			= document.getElementById("city").value;
	state 			= document.getElementById("state").value;
	phone 			= document.getElementById("phone").value;
	str='';
	if(street_address1 != '')
	str = street_address1 +", " ;
	
	if(street_address2 != '')
	str += street_address2 +", " ;
	
	if(city != '')
	str += city +", " ;
		
	str += state +"  " + phone ;
	 
	document.getElementById(field).innerHTML = str;
}