 
function open_msg_box()
{ 
 Effect.Appear("custome_message");
 Effect.Fade("info");
 Effect.Fade("send_now");
 Effect.Fade("back")
 InitializeTimer();
}



function open_msg_box_for_attaching_video()
{

 Effect.Appear("custome_message");
 
 Effect.Fade("info");
 Effect.Fade("send_now");
 Effect.Fade("back");  
}
/////////////////////////////////////////////////////////////
// Timer logic for display focus in text area description box.
/////////////////////////////////////////////////////////////
var secs
var timerID = null
var timerRunning = false
var delay = 150

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 10
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:        
        $('description_body').focus();
        
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

//////////////////////////////////////////////////////////

function open_coupon_box()
{
 Effect.Appear("enter_coupon");
 Effect.Fade("info");
 Effect.Fade("send_now");
 Effect.Fade("back")
}

function hide_coupon_box(){
	Effect.Fade("enter_coupon");	
	
}
  
 function contactusmail()
{   

   var email =  $('email').value ;
    if (email == "")
    {
    alert('Please enter email id');
    return false;
    }
   if (mailcheck($('email').value))
      $('contactusform').submit();
}

function checkmail()
{  
   var emails =  $('email1').value + $('email2').value + $('email3').value;
   if (emails == "")
    {
    alert('Please enter at least one valid email address');
    return false;
    }
   if (mailcheck($('email1').value) && mailcheck($('email2').value) && mailcheck($('email3').value))
      $('invitationform').submit();
}

function mailcheck(str) {
                if (str == "")
                  return true;
                var at="@"
                var dot="."
                var lat=str.indexOf(at)
                var lstr=str.length
                var ldot=str.indexOf(dot)
                if (str.indexOf(at)==-1){
                   alert("Invalid E-mail ID")
                   return false;
                }

                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                   alert("Invalid E-mail ID")
                   return false;
                }

                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                    alert("Invalid E-mail ID")
                    return false;
                }

                 if (str.indexOf(at,(lat+1))!=-1){
                    alert("Invalid E-mail ID")
                    return false;
                 }

                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                    alert("Invalid E-mail ID")
                    return false;
                 }

                 if (str.indexOf(dot,(lat+2))==-1){
                    alert("Invalid E-mail ID")
                    return false;
                 }
                
                 if (str.indexOf(" ")!=-1){
                    alert("Invalid E-mail ID")
                    return false;
                 }

                 return true;                                   
        } 
 
 
 
function event_year(){
    	var sels = document.getElementsByTagName('select');    
    	for(var i=0; i < sels.length; i++)
		{        
    			if (sels[i].id == 'event_event_date_1i')
				{
					if(	sels[i].selectedIndex == 0)
					{
						sels[i].selectedIndex = 0;
						sels[i].options[0].value = 1000;
					}
				}
		}
	document.getElementById('events_form').submit();
 }
 
 
function address_year(){
	var sels = document.getElementsByTagName('select');
	for(var i = 0 ;i < sels.length ; i++)
	{
		if (sels[i].id == 'contact_birth_day_1i')
		{
			if(sels[i].selectedIndex == 0){
		    sels[i].selectedIndex = 0;
			sels[i].options[0].value =1000;
		}
	}	
		
		else if (sels[i].id == 'contact_anniversary_1i')
		{
		  if (sels[i].selectedIndex == 0){
		  sels[i].selectedIndex = 0;
		  sels[i].options[0].value = 1000;
		}
	 }	
}
document.getElementById('contacts_form').submit();
}
 
 
// Invite category : send  vidigreet to multiple people
// added a cancel button to the boxes created

// Comments: Modified the functionality of cancel button as there was an issue while cancelling again and again. 
// Author: Arpit
// Status: Stable
// Date:   2008-03-19
var count1 = 0;
 function add_friend(){	
	var element = document.createElement("div");
	var str= '<table><tr><td><h4 style="text-align: right; color: rgb(85, 85, 85);">Send it to</h4></td><td></td>'
             + '<td><label for="email" style="color: rgb(85, 85, 85); font-size: 90%; font-weight: bold;">Friend\'s Email</label></td>'
             + '<td><input class="textInput" id=email'+count1+' name=email'+count1+' size="30" style="margin-top: 0px; width: 175px;" value="" type="text"></td>'
             + '</tr><tr style="padding-top: 25px;"><td><h4 class="greenText" style="text-align: right;">AND/OR</h4></td><td></td>'
             +'<td><label for="cellnumber" style="color: rgb(85, 85, 85); font-size: 90%; font-weight: bold;">Friend\'s Mobile</label></td>'
             +'<td><input class="textInput" id=cellnumber'+count1+' maxlength="25" name=cellnumber'+count1+' size="30" style="margin-top: 0px; width: 175px;" value="" type="text"></td>'
             + '</tr><tr><td></td><td></td>'
             +'<td><label for="carrier" style="color: rgb(85, 85, 85); font-size: 90%; font-weight: bold; text-align: right;">Mobile Carrier </label></td>'
             +'<td><select id=carrier_mobiletype'+count1+' name=carrier[mobiletype'+ count1 + ']><option value="Alltel">Alltel</option>'
                   +'<option value="AT&amp;T/Cingular">AT&amp;T/Cingular</option>'
                   +'<option value="CellularOne">CellularOne</option>'
                   +'<option value="Nextel/Sprint">Nextel/Sprint</option>'
                   +'<option value="SunCom">SunCom</option>'
                    +'<option value="T-mobile">T-mobile</option>'
                   +'<option value="USCellular">USCellular</option>'
                   +'<option value="Verizon">Verizon</option></select> </td><br>'+ 
				   '<td><a href="" onclick="remove_friend_div();return false;">Cancel</a></td></tr></table><br>';
	
	
    element.innerHTML = str;
	element.id = "add_friend_div_" + count1;
        count1 = count1 + 1;
	document.getElementById('count1').value = count1; 
	document.getElementById('emailgroup').appendChild(element);        
}
 

  
  // Implemented Cancel button functionality while sending vidigreet to multiple people.
  // Comments: Modified the functionality of cancel button as there was an issue while cancelling again and again. 
  // Author: Arpit
  // Status: Stable
  // Date:   2008-03-19
  function remove_friend_div()
  {
      var element_to_remove = document.getElementById("add_friend_div_" + (count1-1));
      document.getElementById("add_friend_div_" + (count1-1)).innerHTML = ""; 
      document.getElementById('emailgroup').removeChild(element_to_remove);
      //decreamenting the count
      count1 = count1 - 1;  
      document.getElementById('count1').value = count1;     
  }

// User Registartion: check_out page , The following function gets called onchange of the drop down options
// The application redirects to paypal site , when paypal is selected in the drop down (calls expreess_checkout to redirect tp paypal)

// function to be called when one year subscription is selected and three email ids needs to be validated
// if the three emails are validated redirect to paypal

function paypal_redirect(){
	
	var email1 = document.getElementById('email1').value;
	var email2 = document.getElementById('email2').value;
	var email3 = document.getElementById('email3').value;
    var check_email = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i;
	var email_inner = "<div class='error'>Oops!  Please specify three valid email ids</div>";
	
	if(email1 == "" && email2 == "" && email3 == ""){
		express_checkout();
		  
	}
	else{
	if (!email1.match(check_email) || !email2.match(check_email) || !email3.match(check_email)){
		
	 $('email_errors').innerHTML = email_inner;
   }
   else{
	express_checkout();
	}}

}


// Application redirects to Paypal 
 
function express_checkout(){
	var sels = document.getElementsByTagName('select');
		var email1 = document.getElementById('email1').value;
	var email2 = document.getElementById('email2').value;
	var email3 = document.getElementById('email3').value;
	for(var i = 0 ;i < sels.length ; i++)
	{
		if (sels[i].id == 'user_payment_type')		
	    {
			  if (sels[i].selectedIndex == 3){
			  Effect.Fade('authorize_fields');
			  document.location.href = '/paypal/express_checkout?email1='+email1+'&email2= '+email2+'&email3=' + email3+ '';
			  }
			  if(sels[i].selectedIndex == 4){
			  Effect.Fade('authorize_fields');
     		  Effect.Fade('discount_emails');
			  Effect.Appear('gift_div');
			  }
    	}	
	}
}


// User Registration : calls the paypal action , when the user selects  paypal in the drop down
// The express checkout redirects the application to paypal 
// when the user subscription is of type 'one day'
function paypal_redirect_for_year(){
	var sels = document.getElementsByTagName('select');
	for(var i = 0 ;i < sels.length ; i++){
		if (sels[i].id == 'user_payment_type'){
			  if (sels[i].selectedIndex == 3){
			  	Effect.Fade('authorize_fields');
			  	document.location.href = '/paypal/express_checkout';
			  }
			  if(sels[i].selectedIndex == 4){
		          Effect.Fade('authorize_fields');	  
		    	  Effect.Appear('gift_div');
	 		  }
		}		
	}
}


// This function is called when checkout form is submitted
// checks for email validations , submits the form when all the three fields are empty or all the three email fields are valid

function check_friends_email(){
	
	var email1 = document.getElementById('email1').value;
	var email2 = document.getElementById('email2').value;
	var email3 = document.getElementById('email3').value;
    var check_email = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i;
	var email_inner = "<div class='error'>Oops! Please specify three valid email ids</div>";
	
	if(email1 == "" && email2 == "" && email3 == ""){
			$("checkout_form").submit();
	}
	else{
	    if (!email1.match(check_email) || !email2.match(check_email) || !email3.match(check_email)){
	       $('email_errors').innerHTML = email_inner;
	       return false;	   
           }
	   else{
	        $("checkout_form").submit();
			}
	    }	
 }


// upgrade membership through paypal

// User upgradation : calls the upgrade through paypal action 
function paypal_upgrade_redirect_for_year(){
	var sels = document.getElementsByTagName('select');
	for(var i = 0 ;i < sels.length ; i++){
		if (sels[i].id == 'user_payment_type'){
			  if (sels[i].selectedIndex == 3){
			  	Effect.Fade('authorize_fields');
			  	document.location.href = '/paypal/upgrade_through_paypal';
			  }
			  if(sels[i].selectedIndex == 4){
			  Effect.Fade('authorize_fields');
			  Effect.Appear('gift_div');
			  }
		}		
	}
}





//////////////////////////////////

function event_remind_me() {
if (document.getElementById('event_event_remind_me').checked){
Effect.Appear('remind_me_on');
}
else{
Effect.Fade('remind_me_on');	
}
}
  
//////////////////////////////////////////////
// toggle parent category arrow in category list

function toggleParent(el) {
	if($(el).className == "parent") { //closed
		$(el).className = "parentOpen";
	} else { //open
		$(el).className = "parent";
	}
}

/////////////////////////////////////////////
// Flash JavaScript interaction functions
// used to send var value to Flash Player
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
 }

 function varSend(mess) {
  var text = mess;
  getFlashMovie("vidigreetPlayer").sendVarToFlash(text);
 }


///////////////// GIFT CERITIFICATE/////////


////////////////  redirect to the paypal site....when buying the gift certificate 

function paypal_redirect_for_gift_certificate(){
	var sels = document.getElementsByTagName('select');
	for(var i = 0 ;i < sels.length ; i++){
		if (sels[i].id == 'user_payment_type_gift'){
			  if (sels[i].selectedIndex == 3){
			  	Effect.Fade('authorize_fields');
			  	document.location.href = '/gift_certificate/payment_through_paypal';
			  }
		}		
	}
}



// Position keyword create box
function copyPosition(src, el) {
	Position.clone(src, el, {offsetLeft: 250, offsetTop: -150, setWidth: false, setHeight: false});
}


  