// JavaScript Document
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>Some details must be corrected before this clip is ready to submit for approval. Please see details  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 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 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
	}

