/***************************************************************************
 *                            Dolphin Web Community Software
 *                              -------------------
 *     begin                : Mon Mar 23 2006
 *     copyright            : (C) 2006  Group
 *     website              : http://www..com
 *
 *     
 *
 ****************************************************************************/

/***************************************************************************
 *
 *   This is a free software; you can modify it under the terms of  
 *   Product License Agreement published on  site at http://www..com/downloads/license.pdf
 *   You may not however distribute it for free or/and a fee. 
 *   This notice may not be removed from the source code. You may not also remove any other visible 
 *   reference and links to  Group as provided in source code.
 *
 ***************************************************************************/

/**
 * Checks/unchecks all tables
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 *
 * @return  boolean  always true
 */
function setCheckboxes(the_form, do_check)
{

	var elts  = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    var i = 0;
	
    for ( i; i < elts_cnt; i++)
    {
        elts[i].checked = do_check;
		if (the_form + "_submit" == elts[i].name)
		{
			elts[i].disabled = !do_check;
		}
    } // end for
	return true;
} // end of the 'setCheckboxes()' function

function setCheckbox(the_form)
{
    var elts      = document.forms[the_form].getElementsByTagName('input');
    var elts_cnt  = elts.length;
    
    var allUnchecked = true;
	
    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].checked) allUnchecked = false;
    }
    
    for (var i = 0; i < elts_cnt; i++)
    {
        if(elts[i].name == (the_form + "_submit")) elts[i].disabled = allUnchecked;
    }

    return true;
}


var win = "width=500,height=600,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
function get_gallery(id_prof)
{
   window.open("photos_gallery.php?ID="+id_prof,'gallery',win);
}

function launchTellFriend ()
{   
    var win = "width=300,height=400,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php",'tellfriend',win);
    return false;
}
function userfee()
{   
    var win = "width=600,height=250,left=50,top=50,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("userfee.php",'userfee',win);
    return false;
}


function launchTellFriendProfile ( sID )
{
    var win = "width=300,height=400,left=200,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=no";
    window.open("tellfriend.php?ID="+sID,'tellfriendprofile',win);
    return false;
}

function ShowShowHide ( show_name, show_name2, hide_name )
{
    if (hide_name) hide_name.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
    if (show_name2) show_name2.style.display = 'inline';
}

function ShowHideHide ( show_name, hide_name, hide_name2 )
{
    if (hide_name) hide_name.style.display = 'none';
    if (hide_name2) hide_name2.style.display = 'none';
    if (show_name) show_name.style.display = 'inline';
}

function charCounter(field,maxLength,countTarget)
{

	field = document.getElementById(field);
	countTarget = document.getElementById(countTarget);
	var inputLength=field.value.length;

	if(inputLength >= maxLength)
	{
		field.value=field.value.substring(0,maxLength);

	}
	countTarget.innerHTML=maxLength-field.value.length;
	
	
}



/**
 * change images onHover mouse action
 */
function show(FileName,jpg1Name)
{
	document.images[FileName].src = jpg1Name;
}

/**
 * set status of the browser window to 's'
 */
function ss(s) 
{
	window.status = s;
	return true;
}

/**
 * set status of the browser window to empty
 */
function ce()
{
	window.status='';
}


/**
 * insert emotion item
 */
function emoticon( txtarea, text ) {

	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function launchAddToIM (id)
{
    var win = "width=600,height=160,left=100,top=100,copyhistory=no,directories=no,menubar=no,location=no,resizable=no,scrollbars=yes";
    window.open("explanation.php?explain=imadd&ID="+id,'add_to_im',win);
    return false;
}

function docOpen(text)
{
	newWindow=window.open('','','toolbar=no,resizable=yes,scrollbars=yes,width=400,height=300');
	newWindow.document.open("text/html");
	newWindow.document.write(unescape(text));
	newWindow.document.close();
}

function get_data( container, url, siteUrl )
    {

        if ( container )
        {
	    var container = document.getElementById( container );
	    container.innerHTML = "loading ... ";
        }

        var XMLHttpRequestObject = false;

        if ( window.XMLHttpRequest )
        {
                XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if ( window.ActiveXObject )
        {
                XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }

        
	if( XMLHttpRequestObject )
        {
    	    var data_source = siteUrl + 'menu_xml.php' + url;
    	    XMLHttpRequestObject.open( "GET", data_source );
    	    XMLHttpRequestObject.onreadystatechange = function()
    	    {
        	if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 )
        	{

        	var xmlDocument = XMLHttpRequestObject.responseXML;
            delete XMLHttpRequestObject;
            XMLHttpRequestObject = null;
		    
		   	names = xmlDocument.getElementsByTagName("name");
		    links = xmlDocument.getElementsByTagName("link");
		    
		    list_sublinks(names, links);

        	}
    	    }
    
            XMLHttpRequestObject.send( null );

	}
	
	//container.innerHTML = '';
	
	
	
	
	function list_sublinks(names, links)
	{	    
    	var loopIndex, name, link, maxIndex = names.length;
    
	    container.innerHTML = '';
	    for ( loopIndex = 0; loopIndex < maxIndex; loopIndex++ )
   	    {
	    
		    //if ( values[loopIndex].firstChild.nodeName=="name")
			name = names[loopIndex].firstChild.nodeValue;
		    
		    //if ( values[loopIndex].childNodes[1].nodeName=="link")
			link = links[loopIndex].firstChild.nodeValue;
					    
		    container.innerHTML += '<a href="' + link + '">' + name + '</a><br />';
	    }
	
	}
}


function createNamedElement( type, name )
{
	
    var element;
		
    try
    {
        element = document.createElement('<'+type+' name="'+name+'">');
    } catch (e) { }

    if (!element || !element.name) // Cool, this is not IE !!
    {
        element = document.createElement(type)
        element.name = name;
    }
								
    return element;
}
									
function display_node(node, siteUrl)
{

    var nn = document.getElementById( node );
    
	var sub_name = node.split('_')[1];
    if ( 'none' == nn.style.display )
    {
	nn.style.display='block';
	if ( '' == nn.innerHTML )    
	    get_data( node, '?action=menu&ID=' + sub_name, siteUrl);
    }
    else
    {
		nn.style.display='none';
    }
    
}
/*This funhction checks the credit card number.*/
var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "Enter Credit Card Number";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

//for join page
function testCreditCard ()
{
	myCardNo = document.jform.cardnum.value;
	mycard = document.jform.cardtype.value;
	var  secno = document.jform.cardcode.value;
	var seclen = secno.length;
	/*alert(mycard);
	alert(myCardNo);
	alert(secno);
	alert(seclen);*/
	if(seclen<3)
	{
		alert("Please enter 3 digit card code");	
		return false;	
	}
	else
	{
		if (checkCreditCard (myCardNo,mycard)) 
		{
			return true;
		} 
		else
		{
			alert (ccErrors[ccErrorNo])
			return false;
		}
	}
}
//ends here

//for profile edit page
function testCreditCard1 ()
{
	var q = document.jform.membership.value;
	var p = document.jform.orig_value.value;
	if(p==q)
	{
		return true;
	}
	else
	{
		myCardNo = document.jform.cardnum.value;
		mycard = document.jform.cardtype.value;
		var  secno = document.jform.cardcode.value;
		var seclen = secno.length;
		/*alert(mycard);
		alert(myCardNo);
		alert(secno);
		alert(seclen);*/
		if(seclen<3)
		{
			alert("Please enter 3 digit card code");
			document.forms['jform'].elements['cardcode'].focus();
			return false;	
		}
		else
		{
			if (checkCreditCard (myCardNo,mycard)) 
			{
				return true;
			} 
			else
			{
				alert (ccErrors[ccErrorNo])
				return false;
			}
		}
	}
}
//ends here
function checkCreditCard (cardnumber,cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "Master Card", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "American Express", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011,650",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "enRoute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
  cards [8] = {name: "Solo", 
               length: "16,18,19", 
               prefixes: "6334, 6767",
               checkdigit: true};
  cards [9] = {name: "Switch", 
               length: "16,18,19", 
               prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
               checkdigit: true};
  cards [10] = {name: "Maestro", 
               length: "16", 
               prefixes: "5020,6",
               checkdigit: true};
  cards [11] = {name: "VisaElectron", 
               length: "16", 
               prefixes: "417500,4917,4913",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++)
  {
    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}
function validateJoinForm()
    {  
		var emailstr = document.forms['jform'].elements['Email1'].value; 
        if ( document.forms['jform'].elements['NickName'].value=="")
		{
			alert('Please fill Username');
			document.forms['jform'].elements['NickName'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['Password1'].value=="")
		{
			alert('Please fill Password');
			document.forms['jform'].elements['Password1'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['Password2'].value=="")
		{
			alert('Please fill Confirm Password');
			document.forms['jform'].elements['Password2'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['Password2'].value!=document.forms['jform'].elements['Password1'].value)
		{
			alert('Password and Confirm password does not match!!!');
			document.forms['jform'].elements['Password2'].select();
			document.forms['jform'].elements['Password2'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['Email1'].value=="")
		{
			alert('Please fill your correct email id');
			document.forms['jform'].elements['Email1'].focus();
			return false;
		}
		else if(!(emailstr.indexOf(".") > 2) && !(emailstr.indexOf("@") > 0))
		{
			alert('Email Id is Invalid!!!');
			document.forms['jform'].elements['Email1'].select();
			document.forms['jform'].elements['Email1'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['Headline'].value=="")
		{
			alert('Please fill your Headline');
			document.forms['jform'].elements['Headline'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['DescriptionMe'].value=="")
		{
			alert('Please fill your Description');
			document.forms['jform'].elements['DescriptionMe'].focus();
			return false;
		}
		else if(document.forms['jform'].elements['City'].value=="")
		{
			alert('Please fill your City');
			document.forms['jform'].elements['City'].focus();
			return false;
		}
		else if(!(document.forms['jform'].elements['i_agree'].checked))
		{
			alert('Please check mark the Terms of use');
			return false;
		}
		else
		{
			return true;
		}
		/*if ( document.forms['jform'].elements['i_agree'].checked ) return true;
        alert('<?php //echo _t("_CLICK_AGREE"); ?>');*/
       
    }
	
function showdiv(i,j)
{
	var q = document.jform.membership.value;
	var p = document.jform.orig_value.value;
	if(p==q)
	{
		j.style.display = "none";
		document.jform.cardtype.disabled = true;
		document.jform.cardnum.disabled = true;
		document.jform.cardcode.disabled = true;
		document.jform.expdate.disabled = true;
	}
	else
	{
		j.style.display = "inline";
		document.jform.cardtype.disabled = false;
		document.jform.cardnum.disabled = false;
		document.jform.cardcode.disabled = false;
		document.jform.expdate.disabled = false;
	}
}
/*============================================================================*/
//######################################################################
/*
	var NicknameInput_ID = 'Login_NickName';
	var NicknameInput_isEmpty = true;
	var NicknameInput_emptyBackground;
	var NicknameInput_nonEmptyBackground;
*/
	/*
	var NicknameInput_emptyColor = 'rgb(170, 170, 170)';
	var NicknameInput_nonEmptyColor = 'rgb(0, 0, 0)';
	var NicknameInput_emptyText = 'Nickname';
	*/
/*
	var PasswordInput_ID = 'Login_Password';
	var PasswordInput_isEmpty = true;
	var PasswordInput_emptyBackground;
	var PasswordInput_nonEmptyBackground;
*/
	/*
	var PasswordInput_emptyColor = 'rgb(170, 170, 170)';
	var PasswordInput_nonEmptyColor = 'rgb(0, 0, 0)';
	var PasswordInput_emptyText = 'Password';
	var PasswordInput_emptyType = 'text';
	var PasswordInput_nonEmptyType = 'password';
	*/
/*
	function NicknameInput_init(sEmptyBackground, sNonEmptyBackground)
	{
	    var elt = document.getElementById(NicknameInput_ID);
	    
	    NicknameInput_emptyBackground = 'url('+sEmptyBackground+')';
	    NicknameInput_nonEmptyBackground = 'url('+sNonEmptyBackground+')';
	
	    elt.style.backgroundImage = NicknameInput_emptyBackground;
	}
	
	function PasswordInput_init(sEmptyBackground, sNonEmptyBackground)
	{
	    var elt = document.getElementById(PasswordInput_ID);
	    
	    PasswordInput_emptyBackground = 'url('+sEmptyBackground+')';
	    PasswordInput_nonEmptyBackground = 'url('+sNonEmptyBackground+')';

	    elt.style.backgroundImage = PasswordInput_emptyBackground;
	}
	
	function NicknameInput_onfocus()
	{
	    var elt = document.getElementById(NicknameInput_ID);
	
	    if (NicknameInput_isEmpty)
	    {
	        elt.style.backgroundImage = NicknameInput_nonEmptyBackground;
	    }
	
	    return true;
	}
	
	function PasswordInput_onfocus()
	{
	    var elt = document.getElementById(PasswordInput_ID);
	
	    if (PasswordInput_isEmpty)
	    {
	        elt.style.backgroundImage = PasswordInput_nonEmptyBackground;
	    }
	
	    return true;
	}
	
	function NicknameInput_onblur()
	{
	    var elt = document.getElementById(NicknameInput_ID);
	
	    if (elt.value == '')
	    {
	        elt.style.backgroundImage = NicknameInput_emptyBackground;
	        NicknameInput_isEmpty = true;
	    } else {
	        NicknameInput_isEmpty = false;
	    }
	
	    return true;
	}
	
	function PasswordInput_onblur()
	{
	    var elt = document.getElementById(PasswordInput_ID);
	
	    if (elt.value == '')
	    {
	        elt.style.backgroundImage = PasswordInput_emptyBackground;
	        PasswordInput_isEmpty = true;
	    } else {
	        PasswordInput_isEmpty = false;
	    }
	
	    return true;
	}
*/