
function couponChecked(elem) {
	
	
		if (elem.checked == true) {
		// if checked
		panelCookie(elem.id, 'couponChecked');
		}
		else {
		// if unchecked
		panelCookie(elem.id, 'couponUnchecked');
		}
}

function panelCookie(coupon, couponStatus){
var exdate=new Date();
var expiredays = 7;
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=coupon + "=" +escape(couponStatus)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function clearSavedCoupons(){
  // note: document.cookie only returns name=value, not the other components
  var tab_cookies = document.cookie.split( ';' );
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');
    // and trim left/right whitespace while we're at it
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
    // if the extracted name matches passed search_name
    if (cookie_name.search('bismancoupon')>-1) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
		panelCookie(cookie_name, 'couponUnchecked');
      }
    }
  }
  
}




function loadCookies(){
var inputs = document.getElementsByTagName('input');
	for(p=0; p<inputs.length; p++){
		if(inputs[p].id.search('bismancoupon')>-1){
			var cookie = getCookie(inputs[p].id);
			if (cookie != 'couponChecked'){
				inputs[p].checked = false;
			}
			else{
				inputs[p].checked = true;
			}
		}
	}
}

function loadSavedCoupons(){
	var savedCount = 0;
var inputs = document.getElementsByTagName('input');
	for(p=0; p<inputs.length; p++){
		if(inputs[p].id.search('bismancoupon')>-1){
			var cookie = getCookie(inputs[p].id);
			if (cookie != 'couponChecked'){
				inputs[p].parentNode.parentNode.parentNode.className += ' nosave';
			}
			else{
				savedCount +=1;	
				inputs[p].parentNode.parentNode.parentNode.className += ' savecoupon';
			}
			
		}
	}
	if(savedCount < 1){
		document.getElementById('nocoupons').innerHTML = 'You have no saved coupons.';
		document.getElementById('topclear').className += ' hide';
		document.getElementById('bottomclear').className += ' hide';
		document.getElementById('topupdate').className += ' hide';
		document.getElementById('bottomupdate').className += ' hide';
	}
	document.getElementById('printsavedcoupons').className+=' finished';
}
function countSavedCoupons(){
		var cookieCount = 0;
	var tab_cookies = document.cookie.split( ';' );
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');
    // and trim left/right whitespace while we're at it
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
    // if the extracted name matches passed search_name
    if (cookie_name.search('bismancoupon')>-1) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
		 var cookieVal = unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
		  if(cookieVal == 'couponChecked'){
			  cookieCount+=1;
		  }
		
      }
    }
  }
  if(cookieCount>0 && document.getElementById('cookieCount') != null && document.getElementById('printCoupons') != null){
  	document.getElementById('cookieCount').innerHTML = '<a href="/?id=53">'+cookieCount +' Coupons</a>';
	document.getElementById('printCoupons').innerHTML = '<a href="/?id=53">Print</a>';
	
	  var cookieCountDiv2=document.getElementById('secondcCount');
	  var printCouponDiv2=document.getElementById('secondPrintDiv');
	  if(printCouponDiv2!='' && printCouponDiv2!='' && printCouponDiv2!=null && cookieCountDiv2!='' && cookieCountDiv2!='' && cookieCountDiv2!=null){
	  	cookieCountDiv2.innerHTML = '<a href="/?id=53">'+cookieCount +' Coupons</a>';
	  	printCouponDiv2.innerHTML = '<a href="/?id=53">Print</a>';
	  }
  }
  else{
	  document.getElementById('cookieCount').innerHTML = '<div class="nosavedcoupons">You have no<br />saved coupons.</div>';
	  document.getElementById('printCoupons').innerHTML = '';
	  
	  var cookieCountDiv2=document.getElementById('secondcCount');
	  var printCouponDiv2=document.getElementById('secondPrintDiv');
	  if(printCouponDiv2!='' && printCouponDiv2!='' && printCouponDiv2!=null && cookieCountDiv2!='' && cookieCountDiv2!='' && cookieCountDiv2!=null){
	  	cookieCountDiv2.innerHTML = '<div class="nosavedcoupons">You have no<br />saved coupons.</div>';
	  	printCouponDiv2.innerHTML = '';
	  }
  }
}


function getCookie(search_name) {
	search_name = search_name;
  // note: document.cookie only returns name=value, not the other components
  var tab_cookies = document.cookie.split( ';' );
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');
    // and trim left/right whitespace while we're at it
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
    // if the extracted name matches passed search_name
    if (cookie_name==search_name) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
		return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
		
      }
      // cookie is initialized but no value => result = null
      return null;
    }
  }
  return null;
} 


function getElementsByStyleClass () {
	
  var all = document.getElementsByTagName('*');
  
  var elements = new Array();
  
  for (var e = 0; e < all.length; e++){
	if (all[e].className == "couponrow"){
      elements[elements.length] = all[e];
	}
  }

		for (var i=0; i<elements.length; i++) {
		
				elements[i].onmouseover=function() {
					this.className+=" couponhover";
				}
				elements[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" couponhover\\b"), "");
				}
		
		}


}
function clickAdType(){
	document.getElementById('ad_type_fov_Text66_input').onclick = toggleAdType;
	document.getElementById('ad_type_fov_Image67_input').onclick = toggleAdType;
	if(document.getElementById('ad_type_fov_PDF68_input')!=null){
		document.getElementById('ad_type_fov_PDF68_input').onclick = toggleAdType;	
	}
	
	toggleAdType();
}
function toggleAdType(){
	
	var text = document.getElementById('ad_type_fov_Text66_input');
	var image = document.getElementById('ad_type_fov_Image67_input');
	var pdf = document.getElementById('ad_type_fov_PDF68_input');
	
	var pdfdiv = document.getElementById('adtypepdf');
	var textdiv = document.getElementById('adtypetext');
	var imagediv = document.getElementById('adtypeimage');
	
	if(text.checked===true){
		if(pdfdiv!=null && pdfdiv!='' && pdfdiv!=undefined){
			pdfdiv.style.display='none';
		}
		imagediv.style.display='none';
		textdiv.style.display='block';
	}
	if(pdfdiv!=null && pdfdiv!='' && pdfdiv!=undefined){
		if(pdf.checked===true){
			if(pdfdiv!=null && pdfdiv!='' && pdfdiv!=undefined){
				pdfdiv.style.display='block';
			}
			imagediv.style.display='none';
			textdiv.style.display='none';
		}
	}
	if(image.checked===true){
		if(pdfdiv!=null && pdfdiv!='' && pdfdiv!=undefined){
			pdfdiv.style.display='none';
		}
		imagediv.style.display='block';
		textdiv.style.display='none';
		
	}
}


function clickHelpType(){
	document.getElementById('ad_type_fov_Text70_input').onclick = toggleHelpType;
	document.getElementById('ad_type_fov_PDF71_input').onclick = toggleHelpType;
	toggleHelpInitiate();
}
function toggleHelpInitiate(){
	var pdfdiv = document.getElementById('pdf');
	var textdiv = document.getElementById('text');
	var text = document.getElementById('ad_type_fov_Text70_input');
	var pdf = document.getElementById('ad_type_fov_PDF71_input');

	if(pdf.checked==true){
		pdfdiv.className = pdfdiv.className +' show';
		textdiv.className = textdiv.className +' hide';
	}
	else{
		textdiv.className = textdiv.className +' show';
		pdfdiv.className = pdfdiv.className +' hide';
	}
	toggleHelpType();
}
function toggleHelpType(){
	var pdfdiv = document.getElementById('pdf');
	var textdiv = document.getElementById('text');
	var text = document.getElementById('ad_type_fov_Text70_input');
	var pdf = document.getElementById('ad_type_fov_PDF71_input');
	
	if(pdf.checked == true){
			pdfdiv.className = pdfdiv.className.replace('hide','show');
			textdiv.className = textdiv.className.replace('show','hide');
	}
	else{
			textdiv.className = textdiv.className.replace('hide','show');
			pdfdiv.className = pdfdiv.className.replace('show','hide');
	}
}

	var flippers = new Array();
	var thisflipperlink =0;
function flipper(){
	var elms = document.getElementsByTagName('*');
	for(frs=0; frs<elms.length; frs++){
		if(elms[frs].className.search('link')>-1 && elms[frs].parentNode.className.search('flipper')>-1){
			flippers[flippers.length] = elms[frs];
			elms[frs].className = elms[frs].className + ' hide';
		}
	}
	if(flippers.length>0){
		flippers=flippers.sort(randOrd);
		
		var number = 100000;
			while(number>flippers.length-1){
				if(flippers.length<=10){
					number = Math.floor(Math.random()*11);
				}
				else if(flippers.length>10 && flippers.length<100){
					number = Math.floor(Math.random()*101);
				}
			}
			
			var index = number;
			for(l=0;l<flippers.length;l++){
				if(flippers[l].className.search('show')>-1){
					flippers[l].className = flippers[l].className.replace('show','hide');
				}
		}
		
		flippers[index].className = flippers[index].className.replace('hide','show');
		thisflipperlink = index;
		
		
			flipperChange(flippers, index, 0);
	}
	
}
var to;
var nextindex=0;
var thelastone = -1;

function flipperChange(flippers, index, button){

	thediv=document.getElementById('flipper');
	
	for(l=0;l<flippers.length;l++){
			if(flippers[l].className.search('show')>-1){
				flippers[l].className = flippers[l].className.replace('show','hide');
			}
	}
		if(index<0){
			index=flippers.length-1;
		}
		
		flippers[index].className = flippers[index].className.replace('hide','show');
	
	
	
	//thediv.innerHTML = thediv.innerHTML +'<br />' + index;
	
	if(index+1==flippers.length){
		nextindex=0;
	}
	else{
		nextindex = index+1;	
	}
	
	if(button=='pause'){
		clearTimeout(to);
	}
	else{
		clearTimeout(to);
		to = setTimeout("flipperChange(flippers, nextindex);",10000);
	}
	
	thelastone = index-1;
	button=0;
	
	thisflipperlink = index;
}


/*function randomSort(){
couponsdiv = document.getElementById('randomsort').getElementsByTagName('div');	
newcoupons = new Array();
for(g=0; g<couponsdiv.length; g++){
	if(couponsdiv[g].className.search('storeCoupon')>-1){
		newcoupons[newcoupons.length] = couponsdiv[g];	
	}
}
newcoupons=newcoupons.sort(randOrd);
var newinner ='';
for(o=0; o<newcoupons.length; o++){
		newinner += '<div class="storeCoupon">'+newcoupons[o].innerHTML+'</div>';
}
document.getElementById('randomsort').innerHTML = newinner;
}*/
function randomize(thisid, thatclass, thistagname){
	thisid = escape(thisid);
	thatclass=escape(thatclass);
	thistagname = escape(thistagname);
	
	couponsdiv = new Array();
couponsdiv = document.getElementById(thisid).getElementsByTagName(thistagname);	
newcoupons = new Array();
for(g=0; g<couponsdiv.length; g++){
	if(couponsdiv[g].className.search(thatclass)>-1){
		newcoupons[newcoupons.length] = couponsdiv[g];	
	}
}
newcoupons=newcoupons.sort(randOrd);
var newinner ='';
for(o=0; o<newcoupons.length; o++){
		newinner += '<'+thistagname+' id="'+newcoupons[o].id+'" class="'+thatclass+'">'+newcoupons[o].innerHTML+'</'+thistagname+'>';
}
document.getElementById(thisid).innerHTML = newinner;
}
function randOrd(){
return (Math.round(Math.random())-0.5);
}



function adCategories(){
	selectlist=document.getElementById('category_input');
	selectlist.onchange =openSubCats;
}

function openSubCats(){
	selectlist=document.getElementById('category_input');
	alldivs = document.getElementsByTagName('div');
	
	for(d=0;d<alldivs.length;d++){
		if(alldivs[d].className.search('subcat')>-1){
			alldivs[d].style.display='none';
			
			checkboxes = alldivs[d].getElementsByTagName('input');
			for(f=0;f<checkboxes;f++){
				checkboxes[f].checked = false;
			}
			
		}
		
	}
	
	cat = selectlist.options[selectlist.selectedIndex].text;

	cat = cat.replace(' ','');
	cat = cat.replace(' ','');
	cat = cat.replace(' ','');
	cat = cat.replace(' ','');
	cat = cat.replace(' ','');
	cat = cat.replace(' ','');
	subcatdiv = document.getElementById(cat);
	if(subcatdiv!='' && subcatdiv!=undefined && subcatdiv!=null){
		subcatdiv.style.display='block';
	}
	
	
}

function sortedJS(){
var output='';
var category='';
var sort1='';
var sort1dir='';
var sort2='';
var sort2dir='';
var sort3='';
var sort3dir='';
var mainsort='';
var mainsortdir='';

var levels='';
var randomizer=0;
var goldl='';
var silverl='';
var bronzel='';
var sortstuff='';
var randomsorter='';
var searchstring='';

var titletag='';

category = getVar('category');
sortfield = getVar('sortfield');
sortdir = getVar('sortdir');


goldl = getVar('goldl');
silverl = getVar('silverl');
bronzel = getVar('bronzel');
randomizer = getVar('randomizer');

gold ='<script type="text/javascript" src="/components/form/jsforms.php?template_id=113';	
bronze ='<script type="text/javascript" src="/components/form/jsforms.php?template_id=50';
silver = ' <script type="text/javascript" src="/components/form/jsforms.php?template_id=137';
catheading = category;
	if(category!=''){
		category += '&amp;category='+category;
	}

searchstring ='&amp;maxrows=100000'+category+'"></script>';


	if(goldl=='' && silverl=='' && bronzel==''){
		output += gold+searchstring;
		output += silver+searchstring;
		output += bronze+searchstring;	
	}
	else{
		if(goldl!=''){
			output += gold+searchstring;
		}
		if(silverl!=''){
			output += silver+searchstring;
		}
		if(bronzel!=''){
			output += bronze+searchstring;
		}
	}

	if(randomizer>0 && sortfield=='' && sortdir==''){
		randomsorter='<script type="text/javascript">randomize("randomsort","storeCoupon","div");</script>';
		output ='<div id="randomsort">'+output+'</div>'+randomsorter;
	}

	document.write(output);
	if(sortfield!='' && sortdir!=''){
		userSort(sortfield, sortdir, 'initial');
	}
	
		catheading = catheading.replace('%20',' ');
		catheading = catheading.replace('%20',' ');
		catheading = catheading.replace('%20',' ');
		catheading = catheading.replace('%20',' ');
		

		document.getElementById('sortheading').innerHTML = catheading;

	document.title = 'BisManCoupons.com >> '+catheading;

	
}

function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }
sortbylinks = new Array();

function userSort(field, dir, caller){
	if(caller!='initial'){
		for(sl=0;sl<sortbylinks.length;sl++){
			if(sortbylinks[sl].className.search(caller.className)>-1){
				sortbylinks[sl].style.fontWeight='bold';
			}
			else{
					sortbylinks[sl].style.fontWeight='normal';
			}
		}
	}
	switch(field){
		case 'store':
			sortStoreName(field, dir);
		break; 
		case 'createddate':
			sortCreatedDate(field, dir);
		break; 
		case 'expiredate':
			sortExpireDate(field, dir);
		break; 
	}
}
		 
function sortStoreName(field, dir){
	//storenames = new Array();
	//expiredates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	
	if(field=='store'){
		if(dir=='asc'){
			storenames = storenames.sort();
			for(t=0;t<storenames.length;t++){
				for(s=0;s<storenames[t].length;s++){
					coupon = 'couponForm'+storenames[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			storenames = storenames.sort();
			for(t=storenames.length-1;t>=0;t--){
				for(s=0;s<storenames[t].length;s++){
					coupon = 'couponForm'+storenames[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	
	
	document.getElementById('randomsort').innerHTML = output;
}

function sortExpireDate(field, dir){
	//storenames = new Array();
	//expiredates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	
	if(field=='expiredate'){
		for(o=0;o<expiredates.length;o++){
				year = expiredates[o][0].substr(6, 4);
				month = expiredates[o][0].substr(3,2);
				day = expiredates[o][0].substr(0,2);
				newdate = year+''+month+''+day;
				expiredates[o][0] = newdate;
			}
		if(dir=='asc'){
			expiredates = expiredates.sort();
			for(t=0;t<expiredates.length;t++){
				for(s=0;s<expiredates[t].length;s++){
					coupon = 'couponForm'+expiredates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			expiredates = expiredates.sort();
			for(t=expiredates.length-1;t>=0;t--){
				for(s=0;s<expiredates[t].length;s++){
					coupon = 'couponForm'+expiredates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	
	
	document.getElementById('randomsort').innerHTML = output;
}

function sortCreatedDate(field, dir){
	//storenames = new Array();
	//expiredates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	if(field=='createddate'){
		for(o=0;o<createddates.length;o++){
				year = createddates[o][0].substr(6, 4);
				month = createddates[o][0].substr(3,2);
				day = createddates[o][0].substr(0,2);
				newdate = year+''+month+''+day;
				createddates[o][0] = newdate;
			}
		if(dir=='asc'){
			createddates = createddates.sort();
			for(t=0;t<createddates.length;t++){
				for(s=0;s<expiredates[t].length;s++){
					coupon = 'couponForm'+createddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			createddates = createddates.sort();
			for(t=createddates.length-1;t>=0;t--){
				for(s=0;s<createddates[t].length;s++){
					coupon = 'couponForm'+createddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.parentNode.innerHTML;
					output += '<div class="storeCoupon">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	document.getElementById('randomsort').innerHTML = output;
}
function dailySpecials(thisid){
	div = document.getElementById(thisid);
	if(div.innerHTML.length>0){
		div.parentNode.style.display='block';	
	}
	else{
		div.parentNode.style.display='none';	
	}
}
function userStoreSort(field, dir, caller){
	if(caller!='initial'){
		for(sl=0;sl<sortbylinks.length;sl++){
			if(sortbylinks[sl].className.search(caller.className)>-1){
				sortbylinks[sl].style.fontWeight='bold';
			}
			else{
					sortbylinks[sl].style.fontWeight='normal';
			}
		}
	}
	switch(field){
		case 'store':
			storeSortStoreName(field, dir);
		break; 
		case 'modifieddate':
			storeSortModifiedDate(field, dir);
		break; 
		case 'createddate':
			storeSortCreatedDate(field, dir);
		break; 
	}
}
function storeSortStoreName(field, dir){
	//storenames = new Array();
	//modifieddates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	
	if(field=='store'){
		if(dir=='asc'){
			storenames = storenames.sort();
			for(t=0;t<storenames.length;t++){
				for(s=0;s<storenames[t].length;s++){
					coupon = 'store'+storenames[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+storenames[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			storenames = storenames.sort();
			for(t=storenames.length-1;t>=0;t--){
				for(s=0;s<storenames[t].length;s++){
					coupon = 'store'+storenames[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+storenames[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	

	document.getElementById('randomstores').innerHTML = output;
}

function storeSortModifiedDate(field, dir){
	//storenames = new Array();
	//modifieddates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	
	if(field=='modifieddate'){
		for(o=0;o<modifieddates.length;o++){
				year = modifieddates[o][0].substr(6, 4);
				month = modifieddates[o][0].substr(3,2);
				day = modifieddates[o][0].substr(0,2);
				newdate = year+''+month+''+day;
				modifieddates[o][0] = newdate;
			}
		if(dir=='asc'){
			modifieddates = modifieddates.sort();
			for(t=0;t<modifieddates.length;t++){
				for(s=0;s<modifieddates[t].length;s++){
					coupon = 'store'+modifieddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+modifieddates[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			modifieddates = modifieddates.sort();
			for(t=modifieddates.length-1;t>=0;t--){
				for(s=0;s<modifieddates[t].length;s++){
					coupon = 'store'+modifieddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+modifieddates[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	
	
	document.getElementById('randomstores').innerHTML = output;
}

function storeSortCreatedDate(field, dir){
	//storenames = new Array();
	//modifieddates = new Array();
	//createddates = new Array();	
	output='';
	coupon='';
	if(field=='createddate'){
		for(o=0;o<createddates.length;o++){
				year = createddates[o][0].substr(6, 4);
				month = createddates[o][0].substr(3,2);
				day = createddates[o][0].substr(0,2);
				newdate = year+''+month+''+day;
				createddates[o][0] = newdate;
			}
		if(dir=='asc'){
			createddates = createddates.sort();
			for(t=0;t<createddates.length;t++){
				for(s=0;s<createddates[t].length;s++){
					coupon = 'store'+createddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+createddates[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		if(dir=='dsc'){
			createddates = createddates.sort();
			for(t=createddates.length-1;t>=0;t--){
				for(s=0;s<createddates[t].length;s++){
					coupon = 'store'+createddates[t][s+1];
					coupon = document.getElementById(coupon);
					coupon = coupon.innerHTML;
					output += '<div id="store'+createddates[t][s+1]+'" class="store">'+coupon+'</div>';
					s++;
				}
			}
		}
		
	}
	document.getElementById('randomstores').innerHTML = output;
}
function removeLink(){
	divs = document.getElementsByTagName('div');
	
	boxes = new Array();
	
	for(g=0;g<divs.length;g++){
		if(divs[g].className.search('box')>-1 && divs[g].parentNode.className.search('store')>-1){
			boxes[boxes.length] = divs[g];
		}
	}
	
	for(b=0;b<boxes.length;b++){
		output='';
		innerdivs = boxes[b].getElementsByTagName('div');
		tonlys = new Array();
		thelink = boxes[b].getElementsByTagName('a')[0];
		for(t=0;t<innerdivs.length;t++){
			if(innerdivs[t].className.search('tonly')>-1){
				tonlys[tonlys.length]=innerdivs[t];	
			}
		}
		for(to=0;to<tonlys.length;to++){
			output+='<a href="'+thelink.href+'">'+tonlys[to].innerHTML+'</a>';
		}
		boxes[b].innerHTML=output;
		boxes[b].style.display='block';
	}
	

}
function goldCouponPost(){
	goldtable=document.getElementById('formtable_10');
	posttable=document.getElementById('goldpostlink');
	if(goldtable!=null && goldtable!='' && goldtable!=undefined){
		if(posttable!='' && posttable!=null && posttable!=undefined){
			posttable.style.display='';	
		}
	}
	else{
		if(posttable!='' && posttable!=null && posttable!=undefined){
			posttable.style.display='none';	
		}
	}
}
function proOpinionPost(){
	var profileview = document.getElementById('profopinionview');
		ptable=document.getElementById('formtable_5');
		linktable = document.getElementById('opinionpostlink');
		if(ptable!='' && ptable!=null && ptable!=undefined){
			
			if(linktable!='' && linktable!=null && linktable!=undefined && ptable.rows.length>0){
				linktable.style.display='none';
			}
		}
		else{
			if(profileview=='' || profileview==null || profileview==undefined){
				if(linktable!='' && linktable!=null && linktable!=undefined){
					window.location = linktable.getElementsByTagName('a')[0].href;
				}
			}
			else{
				if(linktable!='' && linktable!=null && linktable!=undefined){
					linktable.style.display='none';
				}	
			}
		}
}
function storeProfilePost(){
	var profileview=document.getElementById('indvstore');
		ptable=document.getElementById('formtable_4');
		linktable = document.getElementById('storeprofilepostlink');
		
		if(ptable!='' && ptable!=null && ptable!=undefined){
			if(linktable!='' && linktable!=null && linktable!=undefined && ptable.rows.length>0){
				linktable.style.display='none';
			}
		}
		else{
			if(profileview=='' || profileview==null || profileview==undefined){
				if(linktable!='' && linktable!=null && linktable!=undefined){
					window.location = linktable.getElementsByTagName('a')[0].href;
				}
			}
			else{
				if(linktable!='' && linktable!=null && linktable!=undefined){
					linktable.style.display='none';
				}	
			}
		}
}
function pdfPost(){
	var profileview=document.getElementById('pdfrowview');
		ptable=document.getElementById('formtable_14');
		linktable = document.getElementById('pdfpostlink');
		
		if(ptable!='' && ptable!=null && ptable!=undefined){
			if(linktable!='' && linktable!=null && linktable!=undefined && ptable.rows.length>0){
				linktable.style.display='none';
			}
		}
		else{
			if(profileview=='' || profileview==null || profileview==undefined){
				if(linktable!='' && linktable!=null && linktable!=undefined){
					window.location = linktable.getElementsByTagName('a')[0].href;
				}
			}
			else{
				if(linktable!='' && linktable!=null && linktable!=undefined){
					linktable.style.display='none';
				}	
			}
		}
}
function helpWantedPost(){
	var profileview = document.getElementById('helpadview');
		ptable=document.getElementById('formtable_7');
		linktable = document.getElementById('helpwantedpostlink');
		if(ptable!='' && ptable!=null && ptable!=undefined){
			
			if(linktable!='' && linktable!=null && linktable!=undefined && ptable.rows.length>0){
				linktable.style.display='none';
			}
		}
		else{
			if(profileview=='' || profileview==null || profileview==undefined){
				if(linktable!='' && linktable!=null && linktable!=undefined){
					window.location = linktable.getElementsByTagName('a')[0].href;
				}
			}
			else{
				if(linktable!='' && linktable!=null && linktable!=undefined){
					linktable.style.display='none';
				}	
			}
		}
}
function allLinkNames(){
linkNames(3);
linkNames(4);
linkNames(5);
linkNames(7);
linkNames(10);
linkNames(12);	
linkNames(14);	
}
function linkNames(formid){
		formtable = document.getElementById('formtable_'+formid);
		if(formtable!=null && formtable!='' && formtable!=undefined){
			therows = formtable.rows;
			for(r=1;r<therows.length;r++){
				thecells = therows[r].cells;
				for(c=0;c<thecells.length;c++){
					links=thecells[c].getElementsByTagName('a');
					for(l=0;l<links.length;l++){
						if(links[l].innerHTML.search('EDIT')>-1){
							thecells[0].innerHTML = '<a href="'+links[l].href+'">'+thecells[0].innerHTML+'</a>';
						}
					}
				}
			}
		}
}
function submitStoreSearch(){
	bname = document.getElementById('business_name_input');
	if(bname.value=='Business Name'){
		bname.value='';	
	}
}

function secureMember(){
	var masterlogin = getVar('masterlogin');
	
	if(masterlogin>0){
		window.location='http://mg-coupon.taopowered.net/?id=45';
	}
	
}
function addStats(){
	var tviewsdiv = document.getElementById('totalviewsdiv');
	var tuniquediv = document.getElementById('totaluniquesdiv');

	tviewsdiv.innerHTML = totalviews;
	tuniquediv.innerHTML = uniqueviews;
	
}
function showIfData(data, writehtml){
	 while(data.search(' ')>-1){
	 	data = data.replace(' ', '');  
	 }
	 if(data.length>0){
	 	document.write(writehtml);
	 }
}

function showIfDataElse(data, ifhtml, elsehtml){
	while(data.search(' ')>-1){
		data = data.replace(' ', '');
	}
	if(data.length>0){
		document.write(ifhtml);
	}
	else{
		var elsedata=elsehtml;
		while(elsedata.search(' ')>-1){
			elsedata = elsedata.replace(' ', '');
		}
		if(elsedata.length>0){
			document.write(elsehtml);
		}
	}
}
function loadSavedCoupons2(){
	var allCookies=document.cookie.split(';');
	var savedCoupons=new Array();
	var equaltest=0;
	for(x=0;x<allCookies.length;x++){
		if(allCookies[x].search('bismancoupon')>-1 && allCookies[x].search('couponChecked')>-1){
			equaltest=allCookies[x].indexOf('=',13);
			savedCoupons[savedCoupons.length]=allCookies[x].substr(13,equaltest-13);
		}
	}
	var output='';
	for(x=0;x<savedCoupons.length;x++){
		output+='<script type="text/javascript" src="/components/form/jsforms.php?template_id=113&amp;maxrows=1&amp;form_data_id='+savedCoupons[x]+'"></script>';
	}
	document.getElementById('printsavedcoupons').className+=' finished';
	document.write(output);
	if(savedCoupons.length<=0){
		document.getElementById('nocoupons').innerHTML = 'You have no saved coupons.';
	}
}


