// JavaScript Document
function checkregister()
{
	var strmsg = "";
	
	/*if(document.getElementById("firstName"))
         {
            if(document.getElementById("firstName").value.length == 0)
            {
                    strmsg = strmsg + 'first name,';
            }
         }
         if(document.getElementById("lastName"))
          {
             if(document.getElementById("lastName").value.length == 0)
             {
                 strmsg = strmsg + 'last name,';
              }
          }*/
        if(document.getElementById("publicUsername"))
            {
                if(document.getElementById("publicUsername").value.length == 0)
                {
                        strmsg = strmsg + 'public name,';
                }
            }
        if(document.getElementById("mailAddress2"))
            {
                if(document.getElementById("mailAddress2").value.length == 0)
                {
		strmsg = strmsg + 'mail address,';
                }
            }
	if(document.getElementById("password2"))
            {
                if(document.getElementById("password2").value.length == 0)
                {
		strmsg = strmsg + 'password,';
                }
            }
	if(document.getElementById("rePassword"))
            {
                if(document.getElementById("rePassword").value.length == 0)
                {
		strmsg = strmsg + 'retyped password,';
                }
            }
	
        if(document.getElementById("country"))
            {
               if(document.getElementById("country").value == "0")
                {
		strmsg = strmsg + 'country,';
                }
            }
	
	if(strmsg == "")
	{
		pass1 = document.getElementById('password2').value;
		pass2 = document.getElementById('rePassword').value;
		if(pass1 != pass2)
		{
			strmsg = 'The re-typed password does not match with the password.';
			document.getElementById("guimessage").innerHTML = strmsg;
			return false;
		}
	}
	if(strmsg == "")
	{
		if(document.frmRegister.terms.checked == false)
		{
			strmsg = 'To register, you must accept the terms and conditions for use.';
			document.getElementById("guimessage").innerHTML = strmsg;
			return false;
		}
	}
	if(strmsg == "")
	{
		if(document.getElementById("publicUsername"))
                    {
                        if(document.getElementById("publicUsername").value.length <=2 )
                        {
                                strmsg = 'Public username should be between 3 to 10 chatacters long.';
                                document.getElementById("guimessage").innerHTML = strmsg;
                                return false;
                        }
                    }
	}
	if(strmsg == "")
	{
		//document.register.action = 'register';
		document.frmRegister.submit();
		
	}
	else
	{
		strmsg = strmsg.substr(0,strmsg.length-1)
		strmsg = "Missing Fields : " + strmsg + '.';
		document.getElementById("guimessage").innerHTML = strmsg;
		return false;
	}
}

function checkedituser(userstatus)
{
	var strmsg ='';
	if(document.getElementById("firstName").value.length == 0)
	{
		strmsg = strmsg + 'first name,';
	}
	if(document.getElementById("lastName").value.length == 0)
	{
		strmsg = strmsg + 'last name,';
	}
	if(userstatus == 'SELLER')
	{
		if(document.getElementById("publicUsername")!= null)
		{
			if(document.getElementById("publicUsername").value.length == 0)
			{
				strmsg = strmsg + 'Public name,';
			}
		}
	}	
	if(document.getElementById("country")!= null)
	{
			if(document.getElementById("country").value.length == 0)
			{
				strmsg = strmsg + 'Country,';
			}
	}	
	
	if(strmsg=='')
	{
		document.getElementById("jenable").value= "1";
		document.edituser.submit();
	}
	else
	{
		strmsg = strmsg.substr(0,strmsg.length-1)
		strmsg = "Missing Fields : " + strmsg + '.';
		document.getElementById("guimessage").innerHTML = '<strong>'+strmsg+'</strong>';
		return false;
	}
}

function sendpassword()
{
	//document.frmlogin.action = "sendpassword";
	document.getElementById("jenable").value= "1";
	document.frmlogin.submit();
}

function changepassword()
{
	var strmsg = '';
	if(document.getElementById("currentPassword").value.length < 5)
	{
		strmsg = 'The password must be at least 5 characters long.';
	}
	
	else if(document.getElementById("newPassword").value.length < 5)
	{
		strmsg = 'The password must be at least 5 characters long.';
	}
	
	else if(document.getElementById("retypePassword").value.length < 5)
	{
		strmsg = 'The password must be at least 5 characters long.';
	}
	
	else if(document.getElementById("newPassword").value != document.getElementById("retypePassword").value )
	{
		strmsg = 'The two passwords are not equal.';
	}
	
	if(strmsg != '')
	{
		document.getElementById('strmsg').innerHTML = strmsg;
		return false;
	}
	else
	{
		document.getElementById("jenable").value= "1";
		document.frmcgepwd.submit();
	}
}

function mailpassword()
{
	var strmsg = '';
	if(document.getElementById("newPassword").value.length < 5)
	{
		strmsg = 'The password must be at least 5 characters long.';
	}
	
	else if(document.getElementById("retypePassword").value.length < 5)
	{
		strmsg = 'The password must be at least 5 characters long.';
	}
	
	else if(document.getElementById("newPassword").value != document.getElementById("retypePassword").value )
	{
		strmsg = 'The two passwords are not equal.';
	}
	
	if(strmsg != '')
	{
		document.getElementById('strmsg').innerHTML = strmsg;
		return false;
	}
	else
	{
		document.getElementById("jenable").value= "1";
		document.frmcgepwd.submit();
	}
}


function checksubmiter()
{
	if(document.frmsubmiter.confirm.checked == false)
	{
		var strmsg = 'You must accept the terms before proceeding.';
		document.getElementById("guimessage").innerHTML = strmsg;
		return false;
	}
}
function changeclass(but)
{
    var checkflag = 0;
    var checkflagrel = 0;
   
   if(but == 'edt')
   {
       document.getElementById("highlight").innerHTML = 'editorial';
   }

   

    if(but == 'com' || but == 'edt')
    {
        for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
        {

            if (document.frmtagclip.confirmationGroup1[i].checked==true)
            {
                checkflag = document.frmtagclip.confirmationGroup1[i].value;
            }
        }
        for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
        {

            if (document.frmtagclip.confirmationGroup2[i].checked==true)
            {
                checkflagrel = document.frmtagclip.confirmationGroup2[i].value;
            }
        }
        if(checkflag == 0 || checkflag == 'N')
        {
                document.getElementById("padclip").className = '';

                for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
                {
                   document.frmtagclip.confirmationGroup1[i].disabled=false;
                }

                document.getElementById("padsecure").className = 'disable';

                for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
                {

                   document.frmtagclip.confirmationGroup2[i].disabled=true;
                }
        }
        if( checkflag == 'Y')
        {
                document.getElementById("padclip").className = '';

                for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
                {

                   document.frmtagclip.confirmationGroup1[i].disabled=false;
                }
                document.getElementById("padsecure").className = '';

                for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
                {

                   document.frmtagclip.confirmationGroup2[i].disabled=false;
                }
        }
    }

    if(but == 'com')
    {
        if(checkflag == 'Y' && checkflagrel == 'Y')
        {
            document.getElementById("highlight").innerHTML = 'commercial';
        }

         else if(checkflag == 'Y' && checkflagrel == 'N')
        {
            document.getElementById("highlight").innerHTML = 'editorial';
        }
        
        else if(checkflag == 'N')
        {
            document.getElementById("highlight").innerHTML = 'commercial';
        }
        else if(checkflag == 'Y')
        {
            document.getElementById("highlight").innerHTML = 'commercial';
        }
        
    }
    if(but == 'dont')
    {
        for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
        {

            if (document.frmtagclip.confirmationGroup1[i].checked==true)
            {
                 document.frmtagclip.confirmationGroup1[i].checked =false;
            }
        }

        for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
        {

            if (document.frmtagclip.confirmationGroup2[i].checked==true)
            {
                 document.frmtagclip.confirmationGroup2[i].checked =false;
            }
        }
      
        document.getElementById("padclip").className = 'disable';

        for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
        {

           document.frmtagclip.confirmationGroup1[i].disabled=true;
        }

        document.getElementById("padsecure").className = 'disable';

        for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
        {

           document.frmtagclip.confirmationGroup2[i].disabled=true;
        }
        document.getElementById("highlight").innerHTML = 'editorial';
    
    }
    if(but == "clpyes")
    {
         document.getElementById("padsecure").className = '';

        for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
        {

           document.frmtagclip.confirmationGroup2[i].disabled=false;
        }
         document.getElementById("highlight").innerHTML = 'editorial';
    }
     if(but == "clpno")
    {
         document.getElementById("padsecure").className = 'disable';

        for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
        {

           document.frmtagclip.confirmationGroup2[i].disabled=true;
        }
         for (i=0;i<document.frmtagclip.useGroup.length;i++)
        {
            if (document.frmtagclip.useGroup[i].checked==true)
            {
                selval = document.frmtagclip.useGroup[i].value;
            }
        }
           if(selval == 'C')
           {
                document.getElementById("highlight").innerHTML = 'commercial';
           }
           else
           {
                document.getElementById("highlight").innerHTML = 'editorial';
           }

    }
    if(but =='secyes')
    {
         for (i=0;i<document.frmtagclip.useGroup.length;i++)
        {
            if (document.frmtagclip.useGroup[i].checked==true)
            {
                selval = document.frmtagclip.useGroup[i].value;
            }
        }
       if(selval == 'C')
       {
            document.getElementById("highlight").innerHTML = 'commercial';
       }
       else
       {
            document.getElementById("highlight").innerHTML = 'editorial';
       }
    }
     if(but =='secno')
    {
            document.getElementById("highlight").innerHTML = 'editorial';
    }
}

function savemyclip(val)
{
    var catContent = "";
    var catContentrem = "";
    var checkcat = document.frmtagclip.checkcat;
    for(var i=0; i<checkcat.length; i++){
            if(checkcat[i].checked)
                    catContent += checkcat[i].value + ",";
    }
    document.getElementById('catContent').value = catContent;

    var checkcatrem = document.frmtagclip.checkcatrem;
    for(var i=0; i<checkcatrem.length; i++){
            if(checkcatrem[i].checked)
                    catContentrem += checkcatrem[i].value + ",";
    }
    document.getElementById('catRem').value = catContentrem;
	
    if(val == 'save')
    {
        document.getElementById('actionval').value = 'save';
        document.frmtagclip.submit();

    }
    if(val == 'submit')
    {
        correctmsg="";

        correctmsg= "<div id='classify_save_info' align='left'><strong>Clip "+document.getElementById('clipid').value +" is not ready to be submitted for approval:</strong><ul>";

        catflag =0;

        keyword="";

        keyword = document.getElementById('tags').value;

        temp = keyword.split(',');

        if(temp.length < 5)
        {
            correctmsg=correctmsg+"<li><strong>Tags</strong> must be checked. You must specify at least 5 keywords, each keyword must be between 1 and 50 characters.</li>";
        }
        else
        {
            tagflag = 0;

            for(i=0;i<temp.length;i++)
            {
                if(temp[i].length > 50 || temp[i].length < 1)
                {
                    tagflag = 1;
                    break;
                }
            }

            if(tagflag == 1)
            {
                correctmsg=correctmsg+"<li><strong>Tags</strong> must be checked. You must specify at least 5 keywords, each keyword must be between 1 and 50 characters.</li>";
            }
        }
        checkcat = document.frmtagclip.checkcat;
        for(i=0;i<checkcat.length;i++)
        {
            if(checkcat[i].checked)
            {
                catflag =1;
                break;
            }
        }
        if(catflag == 0)
        {
            correctmsg=correctmsg+"<li><strong>Category</strong> is missing.</li>";
        }

        if(document.getElementById('cameraHandling').value == "0")
        {
            correctmsg=correctmsg+"<li><strong>Camera handling</strong> is missing.</li>";
        }
        
        if(document.getElementById('framing').value == "0")
        {
            correctmsg=correctmsg+"<li><strong>Framing</strong> is missing.</li>";
        }

        if(document.getElementById('price').value == "0")
        {
            correctmsg=correctmsg+"<li><strong>Price</strong> is missing.</li>";
        }

        if(document.getElementById('dynamics').value == "0")
        {
            correctmsg=correctmsg+"<li><strong>Dynamics</strong> is missing.</li>";
        }
        
        if(document.getElementById('lighting').value == "0")
        {
            correctmsg=correctmsg+"<li><strong>Lighting</strong> is missing.</li>";
        }
        selval = "N";
        for (i=0;i<document.frmtagclip.useGroup.length;i++)
        {
            if (document.frmtagclip.useGroup[i].checked==true)
            {
                selval = document.frmtagclip.useGroup[i].value;
            }
        }
        if(selval == "N")
        {
            correctmsg=correctmsg+"<li><strong>Use info</strong> is invalid or incomplete.</li>";
        }
        if(selval != 'D' && selval != 'N' )
        {
             relreq='U';
             for (i=0;i<document.frmtagclip.confirmationGroup1.length;i++)
             {

                if (document.frmtagclip.confirmationGroup1[i].checked==true)
                {
                    relreq = document.frmtagclip.confirmationGroup1[i].value;
                }
             }
             if(relreq == 'U')
             {
                correctmsg=correctmsg+"<li><strong>Use info</strong> is invalid or incomplete.</li>";
             }
             if(relreq == 'Y')
             {
                relcon = 'U';
                for (i=0;i<document.frmtagclip.confirmationGroup2.length;i++)
                {

                    if (document.frmtagclip.confirmationGroup2[i].checked==true)
                    {
                        relcon = document.frmtagclip.confirmationGroup2[i].value;
                    }
                }
                if(relcon == 'U')
                {
                    correctmsg=correctmsg+"<li><strong>Use info</strong> is invalid or incomplete.</li>";
                }
             }
        }

        correctmsg = correctmsg+" </ul></div>";
        if(correctmsg != "<div id='classify_save_info' align='left'><strong>Clip "+document.getElementById('clipid').value +" is not ready to be submitted for approval:</strong><ul> </ul></div>")
        {
            document.getElementById("approvemsg").innerHTML = '<span style="color:#ff0000"><strong>The clip is not able to submit for approval due to the reasons given below the submit button.</strong></span>';
            document.getElementById("controlmessage").innerHTML = correctmsg;
            document.getElementById("controlmessage_block").style.display = 'block';
            document.getElementById('navigation').focus();
            return false;
        }
        else
        {
            if(selval == "D")
            {
                if(confirm('You dont know how this clip can be used, so we must sell this clip for editorial use only. Is that ok?'))
                {
                    document.getElementById('actionval').value = 'submit';
                    document.frmtagclip.submit();
                }
                else
                {
                    return false;
                }
            }
            else
            {
                document.getElementById('actionval').value = 'submit';
                document.frmtagclip.submit();
            }
        }

    }
}

function checkpastregister(option)
{
	var strmsg = "";
	
	if(document.getElementById("firstName").value.length == 0)
	{
		strmsg = strmsg + 'first name,';
	}
	if(document.getElementById("lastName").value.length == 0)
	{
		strmsg = strmsg + 'last name,';
	}
	if(document.getElementById("country").value.length == 0)
	{
		strmsg = strmsg + 'country,';
	}

	
	if(strmsg == "")
	{
		document.frmdetails.submit();
		
	}
	else
	{
		strmsg = strmsg.substr(0,strmsg.length-1)
		strmsg = "Missing Fields : " + strmsg + '.';
		document.getElementById("guimessage").innerHTML = strmsg;
		return false;
	}
}
function checkdefault()
{
    	var catContent = "";
	var checkcat = document.frmdefault.checkcat;
	for(var i=0; i<checkcat.length; i++){
		if(checkcat[i].checked)
			catContent += checkcat[i].value + ",";
	}
	document.getElementById('catContent').value = catContent;
}

function checkAll(theElement) {

     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox'){
	  theForm[z].checked = true;
	  }
     }
}

function uncheckAll(theElement) {

     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox'){
	  theForm[z].checked = false;
	  }
     }
}

function changemyaddress(baseaddress)
{
    document.edituser.action = baseaddress+'/changeemail';
}

function checkchangeemail()
{
    if(echeck(document.getElementById('newEmailAddress').value))
    {
        if(confirm("Are you sure you want to change your email address?"))
        {
            return true;
        }
        else
        {
            return false
        }
    }
    else
    {
        document.getElementById('msgdiv').innerHTML = document.getElementById('newEmailAddress').value+' is not a valid mail address.';
        return false;
    }
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str)
{

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
                {

                   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
                {
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
                {
		   return false
		}

		 if (str.indexOf(at,(lat+1))!=-1)
                 {
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
                 {
		   return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
                 {
		    return false
		 }

		 if (str.indexOf(" ")!=-1)
                 {
		    return false
		 }

 		 return true
	}
