/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = '100%';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}
function numeric(e) {
	//return ((e.keyCode == 8) || (e.keyCode == 46) || (e.keyCode > 47 && e.keyCode <58)); 	
	if(e.keyCode == 11 || e.keyCode == 9 || (e.keyCode>=96 && e.keyCode<=105)){
		return true;
	}
	if(e.keyCode == 46 || e.keyCode == 190) {
		return true;
	}
	if((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode == 8 )){
		return true;
	}else{		
		return false;
	}
}	


function toggleLoginDefault(el,type) {
		var txt,ctl;
		//alert(el.name);
		if(type=="username") {
			txt = "Enter your Email Address";
			ctl = el.name; // txt_femail'.$i
		} else {
			txt = "Year of Birth"; 
			ctl = el.name;
		}
	
		if (el.defaultValue==el.value) { 
			el.value = ""; 
		} else if (el.value=="" && document.getElementById(ctl)) {
			document.getElementById(ctl).value=txt;
		}
	}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}
//window.onload = initShowHideDivs;
function check(frm)
{
	/*var Phone1=document.form1.text_mobile1;
	var Phone2=document.form1.text_mobile2;
	var Phone3=document.form1.text_mobile3;
	var email_address=true;
	var zip_code=true;	
	if (((Phone1.value==null)||(Phone1.value=="")) || ((Phone2.value==null)||(Phone2.value=="")) || ((Phone3.value==null)||(Phone3.value==""))){
		 alert("Please Enter a Valid Phone Number")
		 Phone1.focus()
		 return false;
	   }
	   var Phone= Phone1.value + Phone2.value + Phone3.value;	
		if (document.getElementById('want_phone') && document.getElementById('want_phone').checked==true && checkInternationalPhone(Phone)==false){
			alert("Please Enter a Valid Phone Number")
			Phone1.value = Phone2.value= Phone3.value="";
			Phone1.focus()
			return false;
	}
	
	if(frm.txt_brth.value=="")
	{
		alert("Please enter The Year of Birth");
		frm.txt_brth.focus();
		return false;
	}*/
	
	if(frm.txt_email.value=="")
	{
		alert("Please Enter the E-Mail Address");
		frm.txt_email.focus();
		return false;
	}
		if(!isEmail(frm.txt_email.value))
	{
		alert("Please enter the valid email address");
		frm.txt_email.focus();
		return false;
	}
	/* if(document.getElementById('step21') && document.getElementById('step21').style.display=='none'){
		 document.getElementById('step21').style.display=document.getElementById('step22').style.display=document.getElementById('step23').style.display=document.getElementById('step24').style.display="";
		 return false;
	}
	if(document.getElementById('c_address') && document.getElementById('c_address').checked){
		if(document.form1.txt_zip.value=="")
			{
				alert("Please enter the Zipcode");
				document.form1.txt_zip.focus();
				return false;
			}
	}
	var len1=document.form1.txt_zip.value.length;
	if(document.getElementById('chk_address') && document.getElementById('chk_address').checked){
		zipcode=document.form1.txt_zip.value;
		for(i=0;i<len1;i++) 
		{
			x = zipcode.substr(i,1)
			if( !( (x >= '0' && x <= '9') || x == '-' || x=='(' || x==')') )
			{
				alert("Please Enter a valid zip code");
				document.form1.txt_zip.focus();
				return false;
			}
			if(document.form1.txt_zip.value.length>6) {
			alert("Please enter a valid zip code");
			document.form1.txt_zip.focus();
			return false
			}
		}	
	}
	if(document.getElementById('step31') && document.getElementById('step31').style.display=='none'){
		 document.getElementById('step31').style.display=document.getElementById('step32').style.display=document.getElementById('step33').style.display=document.getElementById('step34').style.display=document.getElementById('step35').style.display="";
		 return false;
	}*/
	return true;
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function isEmail(mailstr)
{
	a = mailstr.indexOf(".");
	b = mailstr.indexOf("@");
	c = mailstr.indexOf(" ");
	d = mailstr.lastIndexOf(".");
	e = mailstr.length;
	if( (a == -1) || (b == -1) || (c != -1) || (d < b) || ( d == e - 1) || (b+1 == a) )
		return false;
	else
		return true;
	
}
function clearDefault(val){
 return;
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}


function addEvent() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById("theValue").value -1)+ 2;
  numi.value = num;
  var divIdName = "my"+num+"Div";
  var newdiv = document.createElement('div');
  newdiv.setAttribute("id",divIdName);
  newdiv.innerHTML = "<table border='0' cellpadding='2' cellspacing='2'>"+
								   "<tr><td colspan='2' align='center'><b>Gift Card Selection and Amounts</b></td>"+
									"</tr><tr><td>Business:</td><td><input type='text' name='businees[]' size='25px'></td>"+
									"</tr><tr><td>Gift Card Amount:</td><td><input maxlength='7' type='text' name='amount[]' size='10px'></td>"+
									"</tr><tr><td>Quantity:</td><td><input type='text' name='quantity[]' maxlength='5' size='10px'></td>"+
									"</tr><tr><td colspan='2' align='right'>"+
									"<a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\">Remove Gift Card</a>"+
									"</td></tr></table>";
  ni.appendChild(newdiv);
}

function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

function alertmsg()
{
	var a;
	a=confirm("Do you want to print");
	if(a==true)
	{
		window.print();
	}
}

function select_all(frm,selected,type){
	var sel_val='';
	switch(type){
		case 'phone':
		case 'print':
		   for (var i=0; i <frm.length; i++)
			{
			   frm[i].checked=selected;
			}
		break;
		case 'send_to_phone':
		case 'send_to_print':
		   /*if(frm.length=='undefined'){
			alert(frm.checked);  
		   }*/
		   for (var i=0; i <frm.length; i++)
			{
			   if(frm[i].checked){
				   sel_val+=frm[i].value+',';
			   }
			}
			if(sel_val!=''){
			  sel_val=sel_val.substr(0,sel_val.length-1);
			}
			if(sel_val!=''){
				if(type=='send_to_phone'){
				   location.href='rockfordcoupons.php?catid=&couponid='+sel_val;
				}else if(type=='send_to_print'){
				   window.open('printcoupon.php?print=1&Id='+sel_val,'print_now','scrollbars=yes,status=1,resizable=yes,toolbar=1,width=430px,height=350px');
				}
			}
		break;
	}
}

function clearDefaultTellaFrd(el) {
if (el.defaultValue==el.value) { el.value = ""; }
}

function toggleDefault(el,idx,type) {
	var txt,ctl;

	if(type=="email") {
		txt = "Email Address";
		ctl = "txt_femail"+idx; // txt_femail'.$i
	} else {
		txt = "Friend's Name"; 
		ctl = "txt_fname"+idx;
	}

	if (el.defaultValue==el.value) { 
		el.value = ""; 
	} else if (el.value=="") {
		document.getElementById(ctl).value=txt;
	}
}

function showCHKbox(type,sts){
	var dis='';
	if(sts==false){
		dis='none';
	}
	if(document.getElementById('div'+type)){
		document.getElementById('div'+type).style.display=dis;
	}
}
function ValidHuge(frm){
	var error='';
	if(frm.chk_P && frm.chk_P.checked){
		if((frm.ddP && frm.ddP.checked==false) && (frm.mdP && frm.mdP.checked==false)){
			error+='Text Message Deals : Please select anyone Daily or Monthly Deals\n';	
		}
		if(frm.text_mobile1 && frm.text_mobile1.value.length<3){
	  		error+='Please enter 3 digit Area code in the first box\n';
		}
		if(frm.text_mobile2 && frm.text_mobile2.value.length<3){
			error+='Please enter 3 digit prefix in the second box\n';
		}
		if(frm.text_mobile3 && frm.text_mobile3.value.length<4){
			error+='Please enter 4 digit suffix in the third box';
		}
	}
	if(frm.chk_M && frm.chk_M.checked){
		if((frm.ddM && frm.ddM.checked==false) && (frm.mdM && frm.mdM.checked==false)){
			error+='Emailed Deals : Please select anyone Daily or Monthly Deals\n';	
		}
	}
	if(error!=''){
	   alert(error);
	   return false;
	}else {
	   return true;
	}
}

